commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

r5040 - trunk/gnue-common/src/datasources/drivers/appserver/Schema/Disco


From: johannes
Subject: r5040 - trunk/gnue-common/src/datasources/drivers/appserver/Schema/Discovery
Date: Mon, 26 Jan 2004 10:59:16 -0600 (CST)

Author: johannes
Date: 2004-01-26 10:59:15 -0600 (Mon, 26 Jan 2004)
New Revision: 5040

Modified:
   
trunk/gnue-common/src/datasources/drivers/appserver/Schema/Discovery/Introspection.py
Log:
All names (classes and properties) are now fully qualified, 
e.g. 'address_person' instead of just 'person'


Modified: 
trunk/gnue-common/src/datasources/drivers/appserver/Schema/Discovery/Introspection.py
===================================================================
--- 
trunk/gnue-common/src/datasources/drivers/appserver/Schema/Discovery/Introspection.py
       2004-01-26 14:51:13 UTC (rev 5039)
+++ 
trunk/gnue-common/src/datasources/drivers/appserver/Schema/Discovery/Introspection.py
       2004-01-26 16:59:15 UTC (rev 5040)
@@ -25,6 +25,7 @@
 #
 # NOTES:
 #
+# $Id$
 
 __all__ = ['Introspection']
 
@@ -35,7 +36,10 @@
 from gnue.common.apps import GDebug, GConfig
 from gnue.common.datasources import GIntrospection
 
-class Introspection(GIntrospection.Introspection):
+# =============================================================================
+# Introspection support for application server
+# =============================================================================
+class Introspection (GIntrospection.Introspection):
 
   # list of the types of Schema objects this driver provides
   types = [('object',_('Business Object Class'),1)]
@@ -47,7 +51,7 @@
   #
   def find(self, name=None, type=None):
     if name is None:
-      return self.getSchemaList(type)
+      return self.getSchemaList (type)
     else:
       rs = self.getSchemaByName(name, type)
       if rs:
@@ -56,111 +60,188 @@
         return None
 
 
-  #############
-  #
-  #  get list of all business classes
-  #
-  # TODO: Merge into find()
-  #
-  def getSchemaList(self, type=None):
-      if not(type in ('object',None)):
-        return []
+  # -------------------------------------------------------------------------
+  # Get a dictionary with all modules available
+  # -------------------------------------------------------------------------
+  def _getModuleDict (self):
+    res = {}
 
+    try:
+      cursor = self._connection.request ('gnue_module', [], ['gnue_id'], 
+                                         ['gnue_id', 'gnue_name'])
       try:
-        listcursor = 
self._connection.request('gnue_class',[],['gnue_module'],['gnue_name','gnue_comment','gnue_module'])
-      except Exception, msg:
-        print "error %s" %msg
-        GDebug.printMesg(1,_("Error creating introspection module list \n\n 
--- %s ---)") % msg)
-        return []
+        data = [1]
+        while len (data):
+          data = cursor.fetch ()
 
-      list = []
-      data = ['1']
-      while len(data):
-        data = listcursor.fetch()
+          for module in data:
+            res [module ['gnue_id']] = module ['gnue_name']
+
+      finally:
+        cursor.close ()
+
+    except Exception, msg:
+      print "Error %s" % msg
+      GDebug.printMesg (1, _("Error creating introspection module list\n\n " +
+                             "--- %s ---") % msg)
+      raise
+
+    return res
+
+  # -------------------------------------------------------------------------
+  # Get a list of all business classes
+  # -------------------------------------------------------------------------
+  def getSchemaList (self, type = None):
+    if not (type in ('object', None)):
+      return []
+
+    self._modules = self._getModuleDict ()
+    self._classes = {}
+
+    # First we build a module dictionary
+    try:
+      cursor = self._connection.request ('gnue_module', [], ['gnue_id'], 
+                                         ['gnue_id', 'gnue_name'])
+      data = [1]
+      while len (data):
+        data = cursor.fetch ()
+
+        for module in data:
+          self._modules [module ['gnue_id']] = module ['gnue_name']
+
+
+      cursor.close ()
+
+    except Exception, msg:
+      print "Error %s" % msg
+      GDebug.printMesg (1, _("Error creating introspection module list\n\n " +
+                             "--- %s ---") % msg)
+      return []
+
+    # Next we build a class dictionary
+    try:
+      cursor = self._connection.request ('gnue_class', [], ['gnue_module'],
+                                         ['gnue_name', 'gnue_module'])
+
+      data = [1]
+
+      while len (data):
+        data = cursor.fetch ()
+
         for classdef in data:
-          print classdef
-          schema = 
GIntrospection.Schema(attrs={'id':string.lower(classdef['gnue_name']),
-                                              'name':classdef['gnue_name'],
-                                              'type':'object',
-                                              'gnue_id':classdef['gnue_id']},
-                                       getChildSchema=self.__getChildSchema)
-          list.append(schema)
+          classid = classdef ['gnue_id']
+          modname = self._modules [classdef ['gnue_module']]
 
+          self._classes [classid] = modname + '_' + classdef ['gnue_name']
 
-      listcursor.close()
+      cursor.close ()
+
+      # Now we build the result
+      res = []
+      classes = self._classes.keys ()
+      classes.sort ()
+
+      for key in classes:
+        name  = self._classes [key]
+        attrs = {'id'     : string.lower (name),
+                 'name'   : name,
+                 'type'   : 'object',
+                 'gnue_id': key}
       
-      return list
+        res.append (GIntrospection.Schema (attrs, 
+                                  getChildSchema = self.__getChildSchema))
 
-  #############
-  #
-  #  get schema for one single business class
-  #
+    except Exception, msg:
+      print "Error %s" % msg
+      GDebug.printMesg (1, _("Error creating introspection class list\n\n " +
+                             "--- %s ---") % msg)
+      return []
+
+    return res
+
   
-  def getSchemaByName(self, name, type=None): 
+  # -------------------------------------------------------------------------
+  # Get a schema for a single business class
+  # FIXME: 'gnue_name' is not a fully qualified identifier in the
+  #        classrepository. There might be more modules introducing the same 
+  #        classname.
+  # -------------------------------------------------------------------------
+  def getSchemaByName (self, name, type = None): 
+    res = None
+    self._modules = self._getModuleDict ()
+
+    try:
+      cursor = self._connection.request ('gnue_class',
+          [["eq", ""], ["field", "gnue_name"], ["const", name]],
+          ['gnue_id'],
+          ['gnue_module', 'gnue_name'])
+
       try:
-        listcursor = self._connection.request('gnue_class', [["eq", ""], 
["field", "gnue_name"], ["const", name]],
-                                                  
['gnue_module'],['gnue_name','gnue_comment','gnue_module'])
-      except Exception, msg:
-        print "error %s" %msg
-        GDebug.printMesg(1,_("Error fetching class %s \n\n --- %s ---)") % 
(name,msg))
-        return []
+        data = cursor.fetch ()
+        if len (data):
+          cdef = data [0]
 
-      data = listcursor.fetch()                         
-      if len(data):
-        classdef = data[0]
-        print classdef
-        schema = 
GIntrospection.Schema(attrs={'id':string.lower(classdef['gnue_name']),
-                                            'name':classdef['gnue_name'],
-                                            'type':'object',
-                                            'gnue_id':classdef['gnue_id']},
-                                     getChildSchema=self.__getChildSchema)
-      listcursor.close()
+          name  = "%s_%s" % (self._modules [cdef ['gnue_module']], 
+                             cdef ['gnue_name'])
+
+          attrs = {'id'     : string.lower (name),
+                   'name'   : name,
+                   'type'   : 'object',
+                   'gnue_id': cdef ['gnue_id']}
       
-      return schema
-    
-  #############
-  #
-  #  get schema for one single business class
-  #
-  
+          res = GIntrospection.Schema (attrs, 
+                                       getChildSchema = self.__getChildSchema)
+      finally:
+        cursor.close ()
+
+    except:
+      raise
+
+    return res
+
+  # -------------------------------------------------------------------------
+  # Get a list of all properties owned by a given class
+  # -------------------------------------------------------------------------
   def __getChildSchema(self, parent):
+    res = []
+    self._modules = self._getModuleDict ()
+
+    try:
+      cursor = self._connection.request ('gnue_property', 
+          [["eq", ""], ["field", "gnue_class"], ["const", parent.gnue_id]],
+          ['gnue_id'], 
+          ['gnue_module', 'gnue_name', 'gnue_type', 'gnue_length',
+          'gnue_scale'])
       try:
-        # fetch all properties used by class "parent"
-        listcursor = self._connection.request('gnue_property',  # class
-                                                  [["eq", ""], ["field", 
"gnue_class"],
-                                                               ["const", 
parent.gnue_id]], # condition
-                                                  ['gnue_module'],  # sort
-                                                  
['gnue_name','gnue_comment','gnue_module','gnue_class','gnue_type',
-                                                   
'gnue_length','gnue_scale'])  
-        
-      except Exception, msg:
-        print "error %s" %msg
-        GDebug.printMesg(1,_("Error while loading class properties for class 
%s \n\n --- %s ---)") % (parent.name,msg))
-        return []
+        data = [1]
+        while len (data):
+          data = cursor.fetch ()
 
-      list = []
-      data = ['1']
-      while len(data):
-        data = listcursor.fetch()                         
-        for propdef in data:
-          print propdef
-          attrs={'id': "%s.%s" % (parent.id, 
string.lower(propdef['gnue_name'])),
-                 'name': propdef['gnue_name'],
-                 'precision': propdef['gnue_scale'],   # TODO: check if scale 
and precision is the same
-                 'datatype':propdef['gnue_type'],
-                 'nativetype': 'unknown',
-                 'required': 0 }                       # TODO: classrep has no 
 'required' field
+          for property in data:
+            name  = "%s_%s" % (self._modules [property ['gnue_module']],
+                               string.lower (property ['gnue_name']))
 
-          # TODO: make classrep types a bit more straigtforward
-          if propdef['gnue_type'] =='id' or propdef['gnue_type'] 
=='gnue_module' \
-                 or propdef['gnue_type'] =='gnue_class':
-            attrs['length'] =  32
-          else:
-            attrs['length'] =  propdef['gnue_length']
+            # TODO: check if scale and precision is the same
+            # TODO: classrepository doesn't define 'required'
+            attrs = { 'id'        : "%s.%s" % (parent.id, name),
+                      'name'      : name,
+                      'datatype'  : property ['gnue_type'],
+                      'precision' : property ['gnue_scale'] ,
+                      'nativetype': 'unknown',
+                      'required'  : 0}
 
-          list.append(GIntrospection.Schema(attrs=attrs))
+            if property ['gnue_type'] in ['boolean', 'date', 'datetime', 
+                                          'number', 'string', 'time']:
+              attrs ['length'] = property ['gnue_length']
+            else:
+              attrs ['length'] = 32
 
-      listcursor.close()
+            res.append (GIntrospection.Schema (attrs))
 
-      return list
+      finally:
+        cursor.close ()
 
+    except:
+      raise
+
+    return res


Property changes on: 
trunk/gnue-common/src/datasources/drivers/appserver/Schema/Discovery/Introspection.py
___________________________________________________________________
Name: svn:keyword
   + Id





reply via email to

[Prev in Thread] Current Thread [Next in Thread]