commit-gnue
[Top][All Lists]
Advanced

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

CVSROOT: /cvsroot/gnue


From: Jason Cater
Subject: CVSROOT: /cvsroot/gnue
Date: Fri, 07 Nov 2003 11:14:22 -0500

Module name:    gnue-common
Branch:         datasource-cleanup
Changes by:     Jason Cater <address@hidden>    03/11/07 11:14:22
Reply-to: address@hidden

CVSROOT:        /cvsroot/gnue
Module name:    gnue-common
Branch:         datasource-cleanup
Changes by:     Jason Cater <address@hidden>    03/11/07 11:14:22

Modified files:
        src/datasources/drivers/appserver/Schema/Discovery: 
                                                            Introspection.py 
        src/datasources/drivers/appserver/appserver: Connection.py 
                                                     RecordSet.py 

Log message:
        merged any changes made to cvs head for appserver

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/src/datasources/drivers/appserver/Schema/Discovery/Introspection.py.diff?only_with_tag=datasource-cleanup&tr1=1.1.2.1&tr2=1.1.2.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/src/datasources/drivers/appserver/appserver/Connection.py.diff?only_with_tag=datasource-cleanup&tr1=1.1.2.2&tr2=1.1.2.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/src/datasources/drivers/appserver/appserver/RecordSet.py.diff?only_with_tag=datasource-cleanup&tr1=1.1.2.1&tr2=1.1.2.2&r1=text&r2=text

Patches:
Index: 
gnue-common/src/datasources/drivers/appserver/Schema/Discovery/Introspection.py
diff -c 
gnue-common/src/datasources/drivers/appserver/Schema/Discovery/Introspection.py:1.1.2.1
 
gnue-common/src/datasources/drivers/appserver/Schema/Discovery/Introspection.py:1.1.2.2
*** 
gnue-common/src/datasources/drivers/appserver/Schema/Discovery/Introspection.py:1.1.2.1
     Thu Oct  9 21:21:12 2003
--- 
gnue-common/src/datasources/drivers/appserver/Schema/Discovery/Introspection.py 
    Fri Nov  7 11:14:20 2003
***************
*** 68,74 ****
          return []
  
        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)
--- 68,74 ----
          return []
  
        try:
!         listcursor = 
self._dataConnection.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)
***************
*** 89,113 ****
  
  
        listcursor.close()
! 
        return list
  
    #############
    #
    #  get schema for one single business class
    #
!   # TODO: Merge into find()
!   #
!   def getSchemaByName(self, name, type=None):
        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 = listcursor.fetch()
        if len(data):
          classdef = data[0]
          print classdef
--- 89,112 ----
  
  
        listcursor.close()
!       
        return list
  
    #############
    #
    #  get schema for one single business class
    #
!   
!   def getSchemaByName(self, name, type=None): 
        try:
!         listcursor = self._dataConnection.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 = listcursor.fetch()                         
        if len(data):
          classdef = data[0]
          print classdef
***************
*** 117,141 ****
                                              'gnue_id':classdef['gnue_id']},
                                       getChildSchema=self.__getChildSchema)
        listcursor.close()
! 
        return schema
! 
! 
    #############
    #
    #  get schema for one single business class
    #
! 
    def __getChildSchema(self, parent):
        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))
--- 116,139 ----
                                              'gnue_id':classdef['gnue_id']},
                                       getChildSchema=self.__getChildSchema)
        listcursor.close()
!       
        return schema
!     
    #############
    #
    #  get schema for one single business class
    #
!   
    def __getChildSchema(self, parent):
        try:
          # fetch all properties used by class "parent"
!         listcursor = self._dataConnection.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))
***************
*** 144,150 ****
        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'])),
--- 142,148 ----
        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'])),
***************
*** 166,168 ****
--- 164,167 ----
        listcursor.close()
  
        return list
+ 
Index: gnue-common/src/datasources/drivers/appserver/appserver/Connection.py
diff -c 
gnue-common/src/datasources/drivers/appserver/appserver/Connection.py:1.1.2.2 
gnue-common/src/datasources/drivers/appserver/appserver/Connection.py:1.1.2.3
*** 
gnue-common/src/datasources/drivers/appserver/appserver/Connection.py:1.1.2.2   
    Fri Oct 10 08:18:50 2003
--- gnue-common/src/datasources/drivers/appserver/appserver/Connection.py       
Fri Nov  7 11:14:22 2003
***************
*** 43,48 ****
--- 43,49 ----
  import types
  import md5
  import sys
+ import mx.DateTime, mx.DateTime.ISO
  
  from DataObject import DataObject
  from gnue.common.datasources.drivers.appserver.Schema.Discovery.Introspection 
import Introspection
***************
*** 67,82 ****
      params = { 'host': connectData['host'],
                 'port': connectData['port'],
                 'transport': connectData['transport']}
-     
-     if connectData.has_key('encoding'):
-       GDebug.printMesg(1,"Appserver's dbdriver doesn't support 'encoding' 
parameter, as the transport"+\
-                        " encoding has to be 'utf-8'.")
  
      self._server = GComm.attach(connectData['rpctype'],params)
  
      GDebug.printMesg(3,"Setup the link to the session manager")
      self._sm = self._server.request("Session")
  
      #GDebug.printMesg(3,"Get the status of the session manager")
      #GDebug.printMesg(3,"Status: "+sessionManager.Status())
  
--- 68,83 ----
      params = { 'host': connectData['host'],
                 'port': connectData['port'],
                 'transport': connectData['transport']}
  
      self._server = GComm.attach(connectData['rpctype'],params)
  
      GDebug.printMesg(3,"Setup the link to the session manager")
      self._sm = self._server.request("Session")
  
+     if connectData.has_key('encoding'):
+       GDebug.printMesg(1,"Appserver's dbdriver doesn't 'encoding' parameter, 
as the transport"+\
+                        " encoding has to be 'utf-8'.")
+ 
      #GDebug.printMesg(3,"Get the status of the session manager")
      #GDebug.printMesg(3,"Status: "+sessionManager.Status())
  
***************
*** 99,105 ****
  
    def request(self,table,filter,sort,fieldlist,unicodeMode=0):
      listid = self._sm.request(self._sess_id,table,filter,sort,fieldlist)
!     return Appserver_ListCursor(self,listid,fieldlist,unicodeMode)
  
    def call(self,classname,obj_id_list,methodname,parameters):
      self._sm.call(self._sess_id,classname,obj_id_list,methodname,parameters)
--- 100,106 ----
  
    def request(self,table,filter,sort,fieldlist,unicodeMode=0):
      listid = self._sm.request(self._sess_id,table,filter,sort,fieldlist)
!     return Appserver_ListCursor(self,listid,table,fieldlist,unicodeMode)
  
    def call(self,classname,obj_id_list,methodname,parameters):
      self._sm.call(self._sess_id,classname,obj_id_list,methodname,parameters)
***************
*** 134,182 ****
  
  
  class Appserver_ListCursor:
!   def __init__(self,dataCon,listid,fieldlist,unicodeMode=0):
      self._dataCon=dataCon
      self._listid=listid
      self._fieldlist=fieldlist
      self._stackpos=0
      self._unicodeMode=unicodeMode
  
    def fetch(self,count=5):
      if self._stackpos == -1:
        return []
! 
      result = self._dataCon._sm.fetch(self._dataCon._sess_id,
                                       self._listid,self._stackpos,count)
      if len(result)<count:
        self._stackpos=-1
! 
      else:
        self._stackpos=self._stackpos+len(result)
  
      list = []
      for i in result:
-       # xmlrpc GNURPC driver changes None into 1
-       # so we have to check for None or 1
-       # while (Instance!=None) and (Instance!=1):
        dict = {}
!       j = 1
        for fieldName in self._fieldlist:
!         value = i[j]
          
-         # convert Strings to unicode
-         if type(value) == types.StringType:
-           value = unicode(value,'utf-8')
- 
-         # recode unicode strings to standart encoding
-         if (type(value) == types.UnicodeType) and \
-                (not self._unicodeMode):
-           value = value.encode(gConfig('textEncoding'))
-             
-         dict[fieldName] = value
-         j=j+1
- 
        dict["gnue_id"]=i[0]
!       list.append(dict)
      return list
  
    def count(self):
--- 135,203 ----
  
  
  class Appserver_ListCursor:
!   def __init__(self,dataCon,listid,classname,fieldlist,unicodeMode=0):
      self._dataCon=dataCon
      self._listid=listid
      self._fieldlist=fieldlist
      self._stackpos=0
      self._unicodeMode=unicodeMode
+     self._fieldtypes = self._dataCon._sm.load (self._dataCon._sess_id,
+                                                classname, [''], 
self._fieldlist)
+     self._fieldtypes = self._fieldtypes [0]
+ 
+   # convert a value retrieved from RPC to the correct native Python type
+   def __rpc_to_native (self, value, type):
+ 
+     # Empty strings indicate None
+     if value == '':
+       return None
+ 
+     # String: convert to unicode or local encoding
+     elif type [:7] == 'string(':
+       value = unicode (value, 'utf-8')
+       if self._unicodeMode:
+         return value
+       else:
+         return value.encode (gConfig ('textEncoding'))
+ 
+     # Date: convert to mx.DateTime object
+     elif type == 'date':
+       return mx.DateTime.ISO.ParseDate (value)
+ 
+     # Time: convert to mx.DateTime object
+     elif type == 'time':
+       return mx.DateTime.ISO.ParseTime (value)
+ 
+     # DateTime: convert to mx.DateTime object
+     elif type == 'datetime':
+       return mx.DateTime.ISO.ParseDateTime (value)
+ 
+     # All others (id, number, boolean, reference): no need to convert
+     else:
+       return value
  
    def fetch(self,count=5):
      if self._stackpos == -1:
        return []
!     
      result = self._dataCon._sm.fetch(self._dataCon._sess_id,
                                       self._listid,self._stackpos,count)
      if len(result)<count:
        self._stackpos=-1
!       
      else:
        self._stackpos=self._stackpos+len(result)
  
      list = []
      for i in result:
        dict = {}
!       j = 0
        for fieldName in self._fieldlist:
!         dict [fieldName] = self.__rpc_to_native (i [j+1], self._fieldtypes 
[j])
!         j += 1
          
        dict["gnue_id"]=i[0]
!       list.append(dict)      
      return list
  
    def count(self):
***************
*** 189,195 ****
      pass
      # TODO: Implement List Close command
  
- 
  class Appserver_UpdateCursor:
    def __init__(self,dataCon,unicodeMode=0):
      self._dataCon=dataCon
--- 210,215 ----
***************
*** 201,207 ****
    def delete(self,classname,id):
      if not self._deleteList.has_key(classname):
         self._deleteList[classname]=[]
! 
      self._deleteList[classname].append(id)
  
    def update(self, classname, id, fieldDict):
--- 221,227 ----
    def delete(self,classname,id):
      if not self._deleteList.has_key(classname):
         self._deleteList[classname]=[]
!        
      self._deleteList[classname].append(id)
  
    def update(self, classname, id, fieldDict):
***************
*** 209,262 ****
         self._updateList[classname]=[]
         self._updateKeyList[classname]=[]
  
-     # convert data to transfer encoding (utf-8)
-     for key in fieldDict.keys():
-       value=fieldDict[key]
-       
-       # convert Strings from local encoding to 'utf-8'
-       if type(value) == types.StringType:
-         fieldDict[key] = 
unicode(value,gConfig('textEncoding')).encode('utf-8')
- 
-         # raise Warning if running in unicode mode
-         if self._unicodeMode:
-           GDebug.printMesg(0,'WARNING: non-unicode passed to the dbdriver 
(%s)' % value)
-           
-       # recode unicode strings to 'utf-8'
-       if type(value) == types.UnicodeType:
-         fieldDict[key] = value.encode('utf-8')
-               
      self._updateList[classname].append(fieldDict)
      self._updateKeyList[classname].append(id)
  
!   def execute(self,classname):
!     #try:
!       if self._deleteList.has_key(classname): 
!         result = self._dataCon._sm.delete(self._dataCon._sess_id,classname,
!                                         self._deleteList[classname])
!       
!         self._deleteList[classname]=[]
  
!     #except:
!     #  return
! 
!    # try:
!       while len(self._updateList[classname]):
          id = self._updateKeyList[classname].pop()
          dict = self._updateList[classname].pop()
          # TODO: merge calls with similar updated fields (=dict.values())
!         result = 
self._dataCon._sm.store(self._dataCon._sess_id,classname,[id],
!                                          dict.keys(),[dict.values()])
! 
!       self._updateList[classname]=[]
!       self._updateKeyList[classname]=[]
! 
!     #except:
!     #  return
!     
!   def revert(self,classname):
!     if self._deleteList.has_key(classname):
!       self._deleteList[classname]=[]
!     if self._updateList.has_key(classname):
!       self._updateList[classname]=[]
!       self._updateKeyList[classname]=[] 
! 
--- 229,273 ----
         self._updateList[classname]=[]
         self._updateKeyList[classname]=[]
  
      self._updateList[classname].append(fieldDict)
      self._updateKeyList[classname].append(id)
  
!   # convert a native Python type into something transportable by RPC
!   def __native_to_rpc (self, s):
!     if type (s) == types.StringType:
!       if self._unicodeMode:
!         msg = 'WARNING: non-unicode passed to the dbdriver (%s)' % value
!         GDebug.printMesg (0, msg)
!       s = unicode (s, gConfig ('textEncoding'))
!     if type (s) == types.UnicodeType:
!       s = s.encode ('utf-8')
!     elif type (s) == mx.DateTime.DateTimeType:
!       s = s.date + ' ' + s.time
!     elif s is None:
!       s = ''
!     return s
! 
!   def execute (self, classname):
!     if self._deleteList.has_key (classname): 
!       self._dataCon._sm.delete (self._dataCon._sess_id, classname,
!                                 self._deleteList [classname])
!       del self._deleteList [classname]
  
!     if self._updateList.has_key (classname):
!       while len (self._updateList [classname]):
          id = self._updateKeyList[classname].pop()
          dict = self._updateList[classname].pop()
          # TODO: merge calls with similar updated fields (=dict.values())
!         data = [self.__native_to_rpc (x) for x in dict.values ()]
!         new_ids = self._dataCon._sm.store (self._dataCon._sess_id, classname,
!                                            [id], dict.keys(), [data])
!         dict ["gnue_id"] = new_ids [0]
!       del self._updateList [classname]
!       del self._updateKeyList [classname]
! 
!   def revert (self, classname):
!     if self._deleteList.has_key (classname):
!       del self._deleteList [classname]
!     if self._updateList.has_key (classname):
!       del self._updateList [classname]
!       del self._updateKeyList [classname]
Index: gnue-common/src/datasources/drivers/appserver/appserver/RecordSet.py
diff -c 
gnue-common/src/datasources/drivers/appserver/appserver/RecordSet.py:1.1.2.1 
gnue-common/src/datasources/drivers/appserver/appserver/RecordSet.py:1.1.2.2
*** 
gnue-common/src/datasources/drivers/appserver/appserver/RecordSet.py:1.1.2.1    
    Thu Oct  9 21:21:12 2003
--- gnue-common/src/datasources/drivers/appserver/appserver/RecordSet.py        
Fri Nov  7 11:14:22 2003
***************
*** 40,45 ****
--- 40,46 ----
  
  class RecordSet(GDataObjects.RecordSet):
    def _postChanges(self):
+   def _postChanges(self):
      if self._deleteFlag:
        GDebug.printMesg(5, 'AppServer database driver: Instance deleted')
        self._parent._update_cursor.delete(self._parent._dataObject.table,




reply via email to

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