commit-gnue
[Top][All Lists]
Advanced

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

gnue/gnue-common doc/DataObjects.txt src/GDataS...


From: James Thompson
Subject: gnue/gnue-common doc/DataObjects.txt src/GDataS...
Date: Thu, 20 Sep 2001 02:08:36 -0400

CVSROOT:        /cvs
Module name:    gnue
Changes by:     James Thompson <address@hidden> 01/09/20 02:08:36

Modified files:
        gnue-common/doc: DataObjects.txt 
        gnue-common/src: GDataSource.py 
        gnue-common/src/dbdrivers/geas: DBdriver.py 

Log message:
        Updates to GEAS driver (getting closer)

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/doc/DataObjects.txt.diff?cvsroot=OldCVS&tr1=1.4&tr2=1.5&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/src/GDataSource.py.diff?cvsroot=OldCVS&tr1=1.17&tr2=1.18&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/src/dbdrivers/geas/DBdriver.py.diff?cvsroot=OldCVS&tr1=1.13&tr2=1.14&r1=text&r2=text

Patches:
Index: gnue/gnue-common/doc/DataObjects.txt
diff -u gnue/gnue-common/doc/DataObjects.txt:1.4 
gnue/gnue-common/doc/DataObjects.txt:1.5
--- gnue/gnue-common/doc/DataObjects.txt:1.4    Sun Aug 12 15:55:26 2001
+++ gnue/gnue-common/doc/DataObjects.txt        Thu Sep 20 02:08:36 2001
@@ -70,7 +70,11 @@
     has been requeried.  handler is a method that takes two arguments: 
     the master ResultSet and the detail ResultSet 
 
+  getLoginFields()
+  connect()
 
+
+
 ***********
 ResultSet: 
   
@@ -106,5 +110,17 @@
   addDetailResultSet(): Sets the dataSet associated with this master record
 
 
+
+****************
+Typical layout
+
+DataObject contains link to ResultSet 
+ResultSet contains link to RecordSet
+
+On startup the DataSource asks the GConnection manager for a handle to a 
dataObject
+the end result is that the DataSource is bound to a specifc database driver
+
+From then on all access to the DataObject is hidden by wrapper functions in the
+DataSource
 
 
Index: gnue/gnue-common/src/GDataSource.py
diff -u gnue/gnue-common/src/GDataSource.py:1.17 
gnue/gnue-common/src/GDataSource.py:1.18
--- gnue/gnue-common/src/GDataSource.py:1.17    Wed Sep 19 01:27:44 2001
+++ gnue/gnue-common/src/GDataSource.py Thu Sep 20 02:08:36 2001
@@ -81,11 +81,13 @@
       # catch this exception and handle it properly (exit w/message)
       self._dataObject = \
          self._connectionManager.getDataObject(self.database, self.type)
+      GDebug.printMesg (7, "GDataSource.py bound to %s " % self._dataObject)
 
     self._dataObject._fieldReferences = self._fieldReferences
     self._dataObject._unboundFieldReferences = self._unboundFieldReferences
     self._dataObject._defaultValues = self._defaultValues
 
+
     # Copy all attributes from XML to the dataObject
     for attribute in tagAttributes.keys():
       if hasattr(self, attribute):
@@ -130,15 +132,12 @@
     return self._dataObject != None and self._dataObject.hasMaster()
 
   def createResultSet(self, conditions={}, readOnly=0):
-#    if self._dataObject: 
       return self._dataObject.createResultSet(conditions,readOnly)
 
   def addDetailDataObject(self, dataObject, handler=None):
-#    if self._dataObject:
       self._dataObject.addDetailDataObject(dataObject, handler)
 
   def createEmptyResultSet(self, readOnly=0):
-#    if self._dataObject:
       return self._dataObject.createEmptyResultSet(readOnly)
 
 ######
Index: gnue/gnue-common/src/dbdrivers/geas/DBdriver.py
diff -u gnue/gnue-common/src/dbdrivers/geas/DBdriver.py:1.13 
gnue/gnue-common/src/dbdrivers/geas/DBdriver.py:1.14
--- gnue/gnue-common/src/dbdrivers/geas/DBdriver.py:1.13        Wed Sep 19 
00:58:58 2001
+++ gnue/gnue-common/src/dbdrivers/geas/DBdriver.py     Thu Sep 20 02:08:36 2001
@@ -37,6 +37,19 @@
 import md5
 import sys
 
+try:
+    import CORBA
+    idlFiles=GConfig.get('GEASDIR')+"/share/idl/geas.idl"
+    GDebug.printMesg(1,"IDL being loaded from %s" % (idlFiles))
+    CORBA._load_idl(idlFiles)
+    import GEAS
+    
+except ImportError,ex:
+    print "Failed to load CORBA module."
+    print "Please see http://projects.sault.org/orbit-python/ for the required 
python CORBA bindings"
+    sys.exit(0)
+
+
 class GEAS_RecordSet(GDataObjects.RecordSet): 
   def _postChanges(self): 
     values = []
@@ -46,9 +59,14 @@
       fields.append(field + " = %s")
       values.append(self._fields[field])
     
-    statement = 'UPDATE %s SET %s WHERE %s = %s'
-
+    # statement = 'UPDATE %s SET %s WHERE %s = %s'
 
+# GEAS_ResultSet
+#
+# Notes:
+# In the GEAS driver a CURSOR is simply the ObjectList handle returned
+# via the query interface
+#
 class GEAS_ResultSet(GDataObjects.ResultSet): 
   def __init__(self, dataObject, cursor=None, \
         defaultValues={}, masterRecordSet=None): 
@@ -58,33 +76,66 @@
     self._fieldNames = None
     GDebug.printMesg(5, 'ResultSet created')
   
+
   def _loadNextRecord(self): 
     if self._cursor: 
-
-      try: 
-        rs = self._cursor.fetchone()
-      except self._DatabaseError, err:
+      try:
+        print self._cursor
+        #if not self._fieldNames: 
+        #  self._fieldNames = []
+        #  for t in (self._cursor.description): 
+        #    self._fieldNames.append (t[0])
+        #    self._boundFields[string.lower[t[0]]] = ""
+
+
+        for obj in self._cursor.objects:
+            print "Obj ", obj.objectID
+            #self.objlist[obj.objectID] = obj
+            #r = self._buildMask(obj)
+            #print "Mask", r
+            #rs.append(r)
+            
+#        rs = self._cursor.fetchone()
+      except self._dataObject._DatabaseError, err:
         raise GDataObjects.ConnectionError, err
 
-      GDebug.printMesg(5, rs)
-      if not self._fieldNames: 
-        self._fieldNames = []
-        for t in (self._cursor.description): 
-          self._fieldNames.append (t[0])
-          self._boundFields[string.lower[t[0]]] = ""
-      if rs: 
-        i = 0
-        dict = {}
-        for f in (rs): 
-          dict[self._fieldNames[i]] = f
-          i = i + 1
-        self._cachedRecords.append (self._recordSetClass(parent=self, \
-                                            initialData=dict))
-        return 1
-      else:
-        return 0
-    else: 
-      return 0
+#      GDebug.printMesg(5, rs)
+#      if rs: 
+#        i = 0
+#        dict = {}
+#        for f in (rs): 
+#          dict[self._fieldNames[i]] = f
+#          i = i + 1
+#        self._cachedRecords.append (self._recordSetClass(parent=self, \
+#                                            initialData=dict))
+#        return 1
+#      else:
+#        return 0
+#    else: 
+#      return 0
+
+#  def _buildMask(self, obj):
+#        r = {}
+#        # add objectID into field list
+#        r["ID"] = obj.objectID
+#        for f in self._fieldNames.keys():
+#         for f in obj
+#            r[f] = self._get_object_field(obj,f)
+#        return r
+#    
+#  def _get_object_field(self,obj,field):
+#      retval = ""
+#      try:
+#          retval = obj.getField(field)
+#      except (GEAS.UnknownField,GEAS.NotReadable,GEAS.ServerError,
+#              GEAS.Interrupted,GEAS.NotDataField,GEAS.Locked,
+#              GEAS.TransactionNotInProgress),ex:
+#          # pass error message on
+#          raise DBError , ex.detail
+#      except GEAS.NullField,ex:
+#          # allowed, the field defaults to 'empty'
+#          pass
+#      return retval
 
 
 class GEAS_DataObject(GDataObjects.DataObject): 
@@ -112,7 +163,6 @@
     GDataObjects.DataObject.__init__(self)
 
     GDebug.printMesg (1,"GEAS database driver backend initializing")
-
     self._resultSetClass = GEAS_ResultSet
     self._DatabaseError = GEAS.ServerError
 
@@ -144,7 +194,7 @@
         # TODO: (jcater)     allowGuestLogin = [0|1]
         # TODO: (jcater)     guestLogin = guest
         # TODO: (jcater)     allowBlankLogin = [0|1]
-        self._databaseConnection = self._factory.guestLogin()
+        self._dataConnection = self._factory.guestLogin()
       else:
 
         # TODO: (jcater) The GEAS docs say this is not supported and 
@@ -153,12 +203,11 @@
         # TODO: (jcater) this will have to do for now (even though, 
         # TODO: (jcater) IIRC, is does nothing to validate the user/pass
         # TODO: (jcater) supplied to it.)
-        self._databaseConnection = self._factory.unsecureLogin(user,passwd)
+        self._dataConnection = self._factory.unsecureLogin(user,passwd)
 
-      self.triggerExtensions = TriggerExtensions(self._databaseConnection)
+      self.triggerExtensions = TriggerExtensions(self._dataConnection)
 
-    except (GEAS.ServerError,
-            GEAS.AuthenticationError), ex:
+    except (GEAS.ServerError, GEAS.AuthenticationError), ex:
       raise GDataObjects.ConnectionError, ex
 
     #
@@ -167,44 +216,73 @@
     #   TODO: (jcater) I have no idea if this works, if it will change, 
     #   TODO: (jcater) or, well, anything for that matter. Think of it  
     #   TODO: (jcater) as a placeholder.
-    self._transaction = self._databaseConnection.new()
+    self._transaction = self._dataConnection.new()
 
 
   # We only need the basics -- username and password -- to log in
   def getLoginFields(self): 
     return [['_username', 'User Name',0],['_password', 'Password',1]]
 
-  def _buildQuery(self, conditions={}): 
+  def _buildQuery(self, conditions={}):
     GDebug.printMesg(7,'Implicit Fields: %s' % self._fieldReferences)
-    if len(self._fieldReferences): 
-            q = "SELECT %s FROM %s%s" % \
-           (string.join(self._fieldReferences.keys(),","), self.table, 
-            self._conditionToSQL(conditions))
-    else: 
-      q = "SELECT * FROM %s%s" % (self.table, self._conditionToSQL(conditions))
+    query = self._dataConnection.newQuery()
+    query.classname = "%s" % self.table
+    query.orderby = "name"
+    query.reverse = CORBA.FALSE
+    query.logic = GEAS.Query.AND
+    
+    print "Conditions" , conditions, ' classname ', self.table
 
-    GDebug.printMesg(5,q)
+    if len(self._fieldReferences):
+###      for fieldname in self._fieldReferences.keys():
+      for fieldname in conditions.keys():
+        f = GEAS.Query.Field( field=fieldname, 
test=GEAS.Query.equals,invert=CORBA.FALSE,
+                              
casesensitive=CORBA.FALSE,value=str(conditions[fieldname]))
+        query.addField( f )
+        
+#        f1 = GEAS.Query.Field( field="name",test=GEAS.Query.equals,
+#                               
invert=CORBA.FALSE,casesensitive=CORBA.FALSE,value=fieldcontents)
+#        
+#        f2 = GEAS.Query.Field( field="code",test=GEAS.Query.equals,
+#                               
invert=CORBA.FALSE,casesensitive=CORBA.FALSE,value=language)
+#        query.addField(f2)
+#        f3 = GEAS.Query.Field( field="dialect",test=GEAS.Query.equals,
+#                               
invert=CORBA.FALSE,casesensitive=CORBA.FALSE,value=dialect)
+#        query.addField(f3)
+#        obj_list = con.executeQuery(query)
+#        query.release()
+#      
+#            self._conditionToSQL(conditions))
+#    else: 
+#      q = "SELECT * FROM %s%s" % (self.table, 
self._conditionToSQL(conditions))
+#
+#    GDebug.printMesg(5,q)
+#
+    return query
+
 
-    return q
+  def _createEmptyResultSet(self, readOnly=0, masterRecordSet=None):
+    return self.createResultSet(readOnly=readOnly, 
masterRecordSet=masterRecordSet)
 
   def _createResultSet(self, conditions={}, readOnly=0, masterRecordSet=None): 
     try:
-      pass
-      #cursor = self._dataConnection.newQuery()
+      if len(conditions):
+        obj_list = 
self._dataConnection.executeQuery(self._buildQuery(conditions))  
+      else:
+        obj_list = self._dataConnection.loadAll(self.table)
       
-      #cursor.execute(self._buildQuery(conditions))
     except self._DatabaseError, err: 
       raise GDataObjects.ConnectionError, err
-    #rs = self._resultSetClass(self, cursor=cursor, masterRecordSet=None)
-    #if readOnly: 
-    #  rs._readonly = readOnly
-    #return rs
+    rs = self._resultSetClass(self, cursor=obj_list, masterRecordSet=None)
+    if readOnly: 
+      rs._readonly = readOnly
+    return rs
 
   def commit(self): 
     GDebug.printMesg (5,"GEAS database driver: commit()")
  
     try: 
-      connection.rollback()
+      self._dataConnection.commit()
     except self._DatabaseError, value:
       raise GDataObjects.ConnectionError, value
 
@@ -212,15 +290,13 @@
     GDebug.printMesg (5,"GEAS database driver: rollback()")
 
     try: 
-      connection.rollback()
+      self._dataConnection.abort()
     except: 
       pass     # I'm SURE this isn't right (jcater)
                 # But not all db's support transactions
-
-  def _buildQuery(self, conditions={}): 
-    return None
-
-
+                # TODO : (jamest) This is cruft from _dbsig driver
+                # TODO : not sure what to make of it yet for geas
+                
   # Used to convert a condition tree to an sql where clause
   def _conditionToSQL (self, condition): 
     if condition == {} or condition == None: 
@@ -272,11 +348,6 @@
         raise GConditions.ConditionNotSupported, \
           'Condition clause "%s" is not supported by this db driver.' % otype
 
-
-      
-
-
-
 supportedDataObjects = { 
   'object': GEAS_DataObject
 }
@@ -288,23 +359,10 @@
 
 ##############################################################
 #
-# Beginning of runtime initialization code...
-# (load corba bindings, etc)
+# This is old stuff that needs to go away
 #
 ##############################################################
 
-try:
-    import CORBA
-    idlFiles=GConfig.get('GEASDIR')+"/share/idl/geas.idl"
-    GDebug.printMesg(1,"IDL being loaded from %s" % (idlFiles))
-    CORBA._load_idl(idlFiles)
-    import GEAS
-    
-except ImportError,ex:
-    print "Failed to load CORBA module."
-    print "Please see http://projects.sault.org/orbit-python/ for the required 
python CORBA bindings"
-    sys.exit(0)
-
 class DBdriver:
     def __init__ (self):
         GDebug.printMesg(1,"GNU Enterprise Application Server driver 
initializing")
@@ -316,50 +374,11 @@
         self.fieldlist = []
         self.objlist = {}
 
-    def connect(self, host, dbname, user, passwd):
-        GDebug.printMesg(1,"GEAS driver initializing")     
-
-        # find the object server base object
-        self.orb = CORBA.ORB_init(() , CORBA.ORB_ID)
-        try:
-            self.ior = 
open(GConfig.get('GEASDIR')+"/var/run/geas-server.ior").readline()
-        except (IOError), ex:
-            GDebug.printMesg(0,"*** Error: ior file for geas was not found...  
is geas running?")
-            sys.exit(1)
-        self.factory = self.orb.string_to_object(self.ior)
-
-        try:
-            GDebug.printMesg(1,"Logging into geas as %s" % (user))
-            if (user == 'guest') or (user == ''):
-                self.database = self.factory.guestLogin()
-            else:
-               # NOTE: this will change again
-                self.database = self.factory.unsecureLogin(user,passwd)
-
-            print "DBdriver.py", self.database
-
-            self.triggerExtensions = TriggerExtensions(self._dataConnection)
-        except (GEAS.ServerError,GEAS.AuthenticationError),ex:
-            GDebug.printMesg(0,"Failed to connect to database. Exiting.")
-            GDebug.printMesg(0,ex.detail)
-            sys.exit(0)
-
     def disconnect(self):
         print "disconnect"
         self.database.logout();
 
-    def beginTransaction(self):
-        pass
-
-
-    def commit(self):
-        pass
-
 
-    def rollback(self):
-        pass
-
-
     def query(self, table, mask = None, order_by=None):
         GDebug.printMesg(3, "query mask %s " % mask)
         (objectID, mask) = self.filterMask(mask)
@@ -403,26 +422,7 @@
 
         return rs
 
-    def commit(self):
-        pass
 
-    def rollback(self):
-        pass
-
-    def get_object_field(self,obj,field):
-       retval = ""
-       try:
-           retval = obj.getField(field)
-       except (GEAS.UnknownField,GEAS.NotReadable,GEAS.ServerError,
-               GEAS.Interrupted,GEAS.NotDataField,GEAS.Locked,
-               GEAS.TransactionNotInProgress),ex:
-           # pass error message on
-           raise DBError , ex.detail
-       except GEAS.NullField,ex:
-           # allowed, the field defaults to 'empty'
-           pass
-       return retval
-
     def set_object_field(self,obj,field,value):
        try:
            if field != "objectid":
@@ -489,14 +489,6 @@
                     nmask[k] = mask[k]
 
         return (objectID, nmask)
-
-    def buildMask(self, obj):
-        r = {}
-        # add objectID into field list
-        r[self.uniqueKey] = obj.objectID
-        for f in self.fieldlist.keys():
-            r[f] = self.get_object_field(obj,f)
-        return r
 
     def _make_passkey(self, user, passwd, random):
         m = md5.new(user + '-' + passwd + '-' + random)



reply via email to

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