commit-gnue
[Top][All Lists]
Advanced

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

r5628 - trunk/gnue-common/src/datasources/drivers/appserver/appserver


From: reinhard
Subject: r5628 - trunk/gnue-common/src/datasources/drivers/appserver/appserver
Date: Sat, 3 Apr 2004 17:39:35 -0600 (CST)

Author: reinhard
Date: 2004-04-03 17:39:35 -0600 (Sat, 03 Apr 2004)
New Revision: 5628

Modified:
   trunk/gnue-common/src/datasources/drivers/appserver/appserver/Connection.py
   trunk/gnue-common/src/datasources/drivers/appserver/appserver/DataObject.py
   trunk/gnue-common/src/datasources/drivers/appserver/appserver/Info.py
   trunk/gnue-common/src/datasources/drivers/appserver/appserver/RecordSet.py
   trunk/gnue-common/src/datasources/drivers/appserver/appserver/ResultSet.py
   trunk/gnue-common/src/datasources/drivers/appserver/appserver/__init__.py
Log:
Completely revised GNUe-AppServer dbdriver.


Modified: 
trunk/gnue-common/src/datasources/drivers/appserver/appserver/Connection.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/appserver/appserver/Connection.py 
2004-04-03 23:37:51 UTC (rev 5627)
+++ trunk/gnue-common/src/datasources/drivers/appserver/appserver/Connection.py 
2004-04-03 23:39:35 UTC (rev 5628)
@@ -1,4 +1,7 @@
+# GNU Enterprise Datasource Library - Driver for GNUe-AppServer
 #
+# Copyright 2000-2004 Free Software Foundation
+#
 # This file is part of GNU Enterprise.
 #
 # GNU Enterprise is free software; you can redistribute it
@@ -16,226 +19,87 @@
 # write to the Free Software Foundation, Inc., 59 Temple Place
 # - Suite 330, Boston, MA 02111-1307, USA.
 #
-# Copyright 2000-2004 Free Software Foundation
-#
-# FILE:
-# appserver/Connection.py
-#
-# DESCRIPTION:
-"""
-Implementation of dbdriver for use with GNUe Application Server.
-"""
-# NOTES:
-#
-# HISTORY:
-#
+# $Id$
 
-VERSION="0.0.1"
-
 ####                                   ####
 #### IF YOU MODIFY ANY CONNECTION      ####
 #### ATTRIBUTES, PLEASE UPDATE info.py ####
 ####                                   ####
 
-__all__ = ['Connection']
-
-from gnue.common.datasources import GDataObjects, GConditions
-from gnue.common.datasources.drivers.Base import Connection as BaseConnection
-from gnue.common.apps import GDebug
+from gnue.common.datasources.drivers import Base
 from gnue.common.rpc import client
 
-from DataObject import *
+import DataObject
 
-import string
-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
 
-# TODO: move all non standart Connection functions (request, ...) into a 
subobject native
-#       to prevent namespace conflicts
+# =============================================================================
+# Connection class
+# =============================================================================
 
-class Connection(BaseConnection):
-
-  _DatabaseError = client.Error
+class Connection (Base.Connection):
+  """
+  Handles a connection to the GNUe-AppServer backend.
+  """
   defaultBehavior = Introspection
   supportedDataObjects = {
-    'object': DataObject
+    'object': DataObject.DataObject
   }
 
-  # We only need the basics -- username and password -- to log in
-  def getLoginFields(self):
-    return [['_username', 'User Name',0],['_password', 'Password',1]]
+  # ---------------------------------------------------------------------------
+  # Define the needed information to log in
+  # ---------------------------------------------------------------------------
 
+  def getLoginFields (self):
+    return [['_username', 'User Name', 0], ['_password', 'Password', 1]]
 
-  def connect(self, connectData):
-    user = connectData['_username']
-    passwd = connectData['_password']
+  # ---------------------------------------------------------------------------
+  # Open a connection
+  # ---------------------------------------------------------------------------
 
-    params = { 'host': connectData['host'],
-               'port': connectData['port'],
-               'transport': connectData['transport']}
+  def connect (self, connectData):
 
-    self._server = client.attach(connectData['rpctype'],params)
+    user = connectData ['_username']
+    passwd = connectData ['_password']
 
+    params = {'host': connectData ['host'],
+              'port': connectData ['port'],
+              'transport': connectData ['transport']}
+
+    self._server = client.attach (connectData ['rpctype'], params)
+
     if connectData.has_key ('timeout'):
       self._server.setTimeout (float (connectData ['timeout']))
 
-    GDebug.printMesg(3,"Setup the link to the session manager")
-    self._sm = self._server.request("Session")
+    self._sm = self._server.request ('Session')
+    self._sess_id = self._sm.open ({'user': user, 'password': passwd})
 
-    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())
-
-    try:
-      GDebug.printMesg(3,"Open Session ...")
-      GDebug.printMesg(1,"Logging into appserver as user '%s'" % (user))
-      self._sess_id = self._sm.open({'user':user,'password':passwd})
-
-    except Exception, msg:
-      tmsg = _("Error loging into appserver: %s") % msg
-      raise GDataObjects.ConnectionError, tmsg
-
-    if self._sess_id == 0:
-      tmsg = _("Error loging into appserver")
-      raise GDataObjects.ConnectionError, tmsg
-
-    self._updateCursor = Appserver_UpdateCursor(self)
-
-    # We have no separate native object
+    # Can be removed after the call to _dataConnection.cursor() is removed from
+    # the Base driver
     self.native = self
 
-  def cursor(self):
-    return self._updateCursor
+  # ---------------------------------------------------------------------------
+  # Commit active transaction
+  # ---------------------------------------------------------------------------
 
-  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):
-    return self._sm.call (self._sess_id, classname, obj_id_list, methodname,
-                   parameters) [0]
-
   def commit (self):
-    self._updateCursor.execute ()
     self._sm.commit (self._sess_id)
 
+  # ---------------------------------------------------------------------------
+  # Rollback active transaction
+  # ---------------------------------------------------------------------------
+
   def rollback (self):
-    self._updateCursor.revert ()
     self._sm.rollback (self._sess_id)
 
-  def close(self,commit):
-    self._sm.close(self._sess_id,commit)
+  # ---------------------------------------------------------------------------
+  # Close connection
+  # ---------------------------------------------------------------------------
 
-  # Return a sequence number from sequence 'name'
-  # def getSequence(self, name):
-  # !!! has to be emulated !!!
-  # return self.__singleQuery("select nextval('%s')" % name)
+  def close (self):
+    self._sm.close (self._sess_id, False)
 
-  # Run the SQL statement 'statement'
-  #def sql(self, statement):
-  # !!! has to be emulated !!!
-  #  cursor = self.__connection.cursor()
-  #  try:
-  #    cursor.execute(statement)
-  #    cursor.close()
-  #  except:
-  #    cursor.close()
-  #    raise
-
-
-
-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
-
-  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] = i [j+1]
-        j += 1
-
-      dict["gnue_id"]=i[0]
-      list.append(dict)
-    return list
-
-  def count(self):
-    if not hasattr(self,"_count"):
-      self._count = 
self._dataCon._sm.count(self._dataCon._sess_id,self._listid)
-
-    return self._count
-
-  def close(self):
-    pass
-    # TODO: Implement List Close command
-
-class Appserver_UpdateCursor:
-  def __init__(self,dataCon,unicodeMode=0):
-    self._dataCon=dataCon
-    self._deleteList={}
-    self._updateList={}
-    self._updateKeyList={}
-    self._unicodeMode=unicodeMode
-
-  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):
-    if not self._updateList.has_key(classname):
-       self._updateList[classname]=[]
-       self._updateKeyList[classname]=[]
-
-    self._updateList[classname].append(fieldDict)
-    self._updateKeyList[classname].append(id)
-
-  def execute (self):
-    for classname in self._deleteList.keys ():
-      self._dataCon._sm.delete (self._dataCon._sess_id, classname,
-                                self._deleteList [classname])
-      del self._deleteList [classname]
-
-    for classname in self._updateList.keys ():
-      while len (self._updateList [classname]):
-        id = self._updateKeyList[classname].pop()
-        dict = self._updateList[classname].pop()
-        # TODO: merge calls with similar updated fields (=dict.values())
-        new_ids = self._dataCon._sm.store (self._dataCon._sess_id, classname,
-                                           [id], dict.keys (), [dict.values 
()])
-        dict ["gnue_id"] = new_ids [0]
-      del self._updateList [classname]
-      del self._updateKeyList [classname]
-
-  def revert (self):
-    for classname in self._deleteList.keys ():
-      del self._deleteList [classname]
-    for classname in self._updateList.keys ():
-      del self._updateList [classname]
-      del self._updateKeyList [classname]
+  # Can be removed after the call to _dataConnection.cursor() is removed from
+  # the Base driver
+  def cursor(self):
+    return None


Property changes on: 
trunk/gnue-common/src/datasources/drivers/appserver/appserver/Connection.py
___________________________________________________________________
Name: svn:keywords
   + Id

Modified: 
trunk/gnue-common/src/datasources/drivers/appserver/appserver/DataObject.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/appserver/appserver/DataObject.py 
2004-04-03 23:37:51 UTC (rev 5627)
+++ trunk/gnue-common/src/datasources/drivers/appserver/appserver/DataObject.py 
2004-04-03 23:39:35 UTC (rev 5628)
@@ -1,112 +1,108 @@
+# GNU Enterprise Datasource Library - Driver for GNUe-AppServer
 #
+# Copyright 2000-2004 Free Software Foundation
+#
 # This file is part of GNU Enterprise.
 #
-# GNU Enterprise is free software; you can redistribute it 
-# and/or modify it under the terms of the GNU General Public 
-# License as published by the Free Software Foundation; either 
+# GNU Enterprise is free software; you can redistribute it
+# and/or modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation; either
 # version 2, or (at your option) any later version.
 #
-# GNU Enterprise is distributed in the hope that it will be 
-# useful, but WITHOUT ANY WARRANTY; without even the implied 
-# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+# GNU Enterprise is distributed in the hope that it will be
+# useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 # PURPOSE. See the GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public 
-# License along with program; see the file COPYING. If not, 
-# write to the Free Software Foundation, Inc., 59 Temple Place 
+# You should have received a copy of the GNU General Public
+# License along with program; see the file COPYING. If not,
+# write to the Free Software Foundation, Inc., 59 Temple Place
 # - Suite 330, Boston, MA 02111-1307, USA.
 #
-# Copyright 2000-2004 Free Software Foundation
-#
-# FILE:
-# appserver/DataObject.py
-#
-# DESCRIPTION:
-# Implementation of dbdriver for use with GNUe Application Server.
-#
-# NOTES:
-#
-# HISTORY:
-#
+# $Id$
 
-__all__ = ['DataObject']
+from types import *
 
-from gnue.common.datasources import GConditions, Exceptions
-from gnue.common.datasources.drivers.Base import DataObject as BaseDataObject
-from gnue.common.apps import GDebug
-
 import string
-import types
-import md5
-import sys
 
-from ResultSet import *
+from gnue.common.datasources import GConditions
+from gnue.common.datasources.drivers import Base
 
-class DataObject(BaseDataObject):
+import ResultSet
 
-  _resultSetClass = ResultSet
+# =============================================================================
+# DataObject class
+# =============================================================================
 
+class DataObject (Base.DataObject):
+  """
+  Handles a dataobject in the GNUe-AppServer backend.
+  """
+  # This is actually never used
+  _resultSetClass = ResultSet.ResultSet
 
-  def _buildQuery(self, conditions={},forDetail=None,additionalSQL=""):
-    # Standardize incomming conditions as a GConditions structre
-    if type(conditions) == types.DictType:
-        cond = GConditions.buildConditionFromDict(conditions)
-    else:
-        cond = conditions
+  # ---------------------------------------------------------------------------
+  # Build query in prefix notation
+  # ---------------------------------------------------------------------------
 
-    # Construct query object
-    GDebug.printMesg(7,'Implicit Fields: %s' % self._fieldReferences)
-    query = []
+  def _buildQuery (self, conditions = {}, forDetail = None,
+                   additionalSQL = ''):
 
-    # Add conditionals
-    query = GConditions.buildPrefixFromTree(cond._children[0] )
+    if isinstance (conditions, DictType):
+      cond = GConditions.buildConditionFromDict (conditions)
+    else:
+      cond = conditions
 
-    GDebug.printMesg(7,'Full query in prefix notation: %s' % query)
+    query = GConditions.buildPrefixFromTree (cond._children [0])
 
     return query
 
+  # ---------------------------------------------------------------------------
+  # Create an empty resultset
+  # ---------------------------------------------------------------------------
 
-  def _createEmptyResultSet(self, readOnly=0, masterRecordSet=None):
-    return self.createResultSet(readOnly=readOnly,\
-                                conditions=GConditions.GCimpossible,\
-                                masterRecordSet=masterRecordSet)
+  def _createEmptyResultSet (self, readOnly = 0, masterRecordSet = None):
 
-  def _createResultSet(self, conditions={}, readOnly=0,
-                       masterRecordSet=None, sql=""):
+    fieldlist = self._fieldReferences.keys ()
 
-    GDebug.printMesg (5,"Setting up list object ...");
+    return ResultSet.ResultSet (dataObject      = self,
+                                sm              = self._connection._sm,
+                                session_id      = self._connection._sess_id,
+                                list_id         = None,
+                                classname       = self.table,
+                                fieldlist       = fieldlist,
+                                fetchcount      = self.cache,
+                                readOnly        = readOnly,
+                                masterRecordSet = masterRecordSet)
 
-    sort=[]
-    filter=[]
+  # ---------------------------------------------------------------------------
+  # Create a resultset
+  # ---------------------------------------------------------------------------
 
-    # the fieldnames seem to be stored in _fieldReferences
-    fieldlist=self._fieldReferences.keys()
-    
-    GDebug.printMesg (5,"Using "+str(fieldlist)+" as fieldlist");
-    
-    if hasattr(self,"order_by"):
-      GDebug.printMesg (5,"Sorting list by fields '"+self.order_by+"'");
-      sort=string.splitfields(self.order_by,",")
+  def _createResultSet (self, conditions = {}, readOnly = 0,
+                        masterRecordSet = None, sql = ''):
 
-    try:
-      if conditions:
-        GDebug.printMesg (5,"Setting Conditions ...");
-        filter = self._buildQuery(conditions)
-    except self._connection._DatabaseError, err:
-      raise Exceptions.ConnectionError, err
+    if conditions:
+      filter = self._buildQuery (conditions)
+    else:
+      filter = []
 
-    try:
-      listcursor = self._connection.request (self.table, filter, sort,
-                                             fieldlist, self._unicodeMode)
-    except Exception, msg:
-      tmsg = _("Error during creation of object list:\n\n%s") % msg
-      raise Exceptions.ConnectionError, tmsg
+    if hasattr (self, 'order_by'):
+      sort = string.splitfields (self.order_by, ',')
+    else:
+      sort = []
 
-    rs = self._resultSetClass (self, cursor=listcursor, masterRecordSet=None,
-                               fetchcount = self.cache)
-    
-    if readOnly: 
-      rs._readonly = readOnly
-      
-    return rs
+    fieldlist = self._fieldReferences.keys ()
 
+    list_id = self._connection._sm.request (self._connection._sess_id,
+                                            self.table, filter, sort, 
fieldlist)
+
+    return ResultSet.ResultSet (dataObject      = self,
+                                sm              = self._connection._sm,
+                                session_id      = self._connection._sess_id,
+                                list_id         = list_id,
+                                classname       = self.table,
+                                fieldlist       = fieldlist,
+                                fetchcount      = self.cache,
+                                readOnly        = readOnly,
+                                masterRecordSet = masterRecordSet)


Property changes on: 
trunk/gnue-common/src/datasources/drivers/appserver/appserver/DataObject.py
___________________________________________________________________
Name: svn:keywords
   + Id


Property changes on: 
trunk/gnue-common/src/datasources/drivers/appserver/appserver/Info.py
___________________________________________________________________
Name: svn:keywords
   + Id

Modified: 
trunk/gnue-common/src/datasources/drivers/appserver/appserver/RecordSet.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/appserver/appserver/RecordSet.py  
2004-04-03 23:37:51 UTC (rev 5627)
+++ trunk/gnue-common/src/datasources/drivers/appserver/appserver/RecordSet.py  
2004-04-03 23:39:35 UTC (rev 5628)
@@ -1,79 +1,93 @@
+# GNU Enterprise Datasource Library - Driver for GNUe-AppServer
 #
+# Copyright 2000-2004 Free Software Foundation
+#
 # This file is part of GNU Enterprise.
 #
-# GNU Enterprise is free software; you can redistribute it 
-# and/or modify it under the terms of the GNU General Public 
-# License as published by the Free Software Foundation; either 
+# GNU Enterprise is free software; you can redistribute it
+# and/or modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation; either
 # version 2, or (at your option) any later version.
 #
-# GNU Enterprise is distributed in the hope that it will be 
-# useful, but WITHOUT ANY WARRANTY; without even the implied 
-# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+# GNU Enterprise is distributed in the hope that it will be
+# useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 # PURPOSE. See the GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public 
-# License along with program; see the file COPYING. If not, 
-# write to the Free Software Foundation, Inc., 59 Temple Place 
+# You should have received a copy of the GNU General Public
+# License along with program; see the file COPYING. If not,
+# write to the Free Software Foundation, Inc., 59 Temple Place
 # - Suite 330, Boston, MA 02111-1307, USA.
 #
-# Copyright 2000-2004 Free Software Foundation
-#
-# FILE:
-# appserver/DBdriver.py
-#
-# DESCRIPTION:
-# Implementation of dbdriver for use with GNUe Application Server.
-#
-# NOTES:
-#
-# HISTORY:
-#
+# $Id$
 
-from gnue.common.datasources import GConditions, Exceptions
-from gnue.common.datasources.drivers.Base import RecordSet as BaseRecordSet
-from gnue.common.apps import GDebug
+from gnue.common.datasources.drivers import Base
 
-import string
-import types
-import md5
-import sys
+# =============================================================================
+# RecordSet class
+# =============================================================================
 
-class RecordSet(BaseRecordSet):
-  def _postChanges(self):
-    if self._deleteFlag:
-      GDebug.printMesg(5, 'AppServer database driver: Instance deleted')
-      self._parent._update_cursor.delete(self._parent._dataObject.table,
-                                         self._fields["gnue_id"])
+class RecordSet (Base.RecordSet):
+  """
+  Handles a record (i.e. an instance) in the GNUe-AppServer backend.
+  """
+  # ---------------------------------------------------------------------------
+  # Initialization
+  # ---------------------------------------------------------------------------
 
-    if self._insertFlag:
-      GDebug.printMesg(5, 'AppServer database driver: new Instance '+\
-                       'created and inserted')
-      ## Set __id__ to "0" for new instances
-      self._parent._update_cursor.update(self._parent._dataObject.table,
-                                         0, self._fields)
+  def __init__ (self, parent, sm, session_id, classname, initialData = {}):
 
-    elif self._updateFlag:
-      modifiedFields={}
-      for field in (self._modifiedFlags.keys()):
-        modifiedFields[field]=self._fields[field]
+    Base.RecordSet.__init__ (self, parent, initialData = initialData)
 
-      self._parent._update_cursor.update(self._parent._dataObject.table,
-                                         self._fields["gnue_id"], 
modifiedFields)
+    self.__sm = sm
+    self.__session_id = session_id
+    self.__classname = classname
 
-    self._updateFlag = 0
-    self._insertFlag = 0
-    self._deleteFlag = 0
+  # ---------------------------------------------------------------------------
+  # Delete
+  # ---------------------------------------------------------------------------
 
-  # this function calls a per entry function on server side
-  def callFunc(self,name,params):
-    if self._insertFlag:
-      # store record on server
-      GDebug.printMesg(0, 'FIXME: record has to be stored on appserver '+\
-                       'and its gnue_id should be returned')
-      return
+  def _postDelete (self):
 
-    return self._parent._dataObject._dataConnection.call ( \
-       self._parent._dataObject.table,
-       [self._fields["gnue_id"]],
-       name,params)
+    self.__sm.delete (self.__session_id,
+                      self.__classname,
+                      [self._fields ['gnue_id']])
 
+  # ---------------------------------------------------------------------------
+  # Insert
+  # ---------------------------------------------------------------------------
+
+  def _postInsert (self, fields):
+
+    self._fields ['gnue_id'] = self.__sm.store (self.__session_id,
+                                                self.__classname,
+                                                [None],
+                                                fields.keys (),
+                                                [fields.values ()]) [0]
+
+  # ---------------------------------------------------------------------------
+  # Update
+  # ---------------------------------------------------------------------------
+
+  def _postUpdate (self, fields):
+
+    self.__sm.store (self.__session_id,
+                     self.__classname,
+                     [self._fields ['gnue_id']],
+                     fields.keys (),
+                     [fields.values ()])
+
+  # ---------------------------------------------------------------------------
+  # Call a server-side function
+  # ---------------------------------------------------------------------------
+
+  def callFunc (self, methodname, parameters):
+
+    # Before calling the function, post all pending changes to the server
+    self.post ()
+
+    return self.__sm.call (self.__session_id,
+                           self.__classname,
+                           [self._fields ['gnue_id']],
+                           methodname,
+                           parameters) [0]


Property changes on: 
trunk/gnue-common/src/datasources/drivers/appserver/appserver/RecordSet.py
___________________________________________________________________
Name: svn:keywords
   + Id

Modified: 
trunk/gnue-common/src/datasources/drivers/appserver/appserver/ResultSet.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/appserver/appserver/ResultSet.py  
2004-04-03 23:37:51 UTC (rev 5627)
+++ trunk/gnue-common/src/datasources/drivers/appserver/appserver/ResultSet.py  
2004-04-03 23:39:35 UTC (rev 5628)
@@ -1,4 +1,7 @@
+# GNU Enterprise Datasource Library - Driver for GNUe-AppServer
 #
+# Copyright 2000-2004 Free Software Foundation
+#
 # This file is part of GNU Enterprise.
 #
 # GNU Enterprise is free software; you can redistribute it
@@ -16,65 +19,87 @@
 # write to the Free Software Foundation, Inc., 59 Temple Place
 # - Suite 330, Boston, MA 02111-1307, USA.
 #
-# Copyright 2000-2004 Free Software Foundation
-#
-# FILE:
-# appserver/ResultSet.py
-#
-# DESCRIPTION:
-# Implementation of dbdriver for use with GNUe Application Server.
-#
-# NOTES:
-#
-# HISTORY:
-#
+# $Id$
 
-from gnue.common.datasources import GConditions, Exceptions
-from gnue.common.datasources.drivers.Base import ResultSet as BaseResultSet
-from gnue.common.apps import GDebug
+from gnue.common.datasources.drivers import Base
 
-import string
-import types
-import md5
-import sys
+import RecordSet
 
-from RecordSet import *
+# =============================================================================
+# ResultSet class
+# =============================================================================
 
-#
-# Notes:
-# In the Appserver driver a CURSOR is simply the List handle returned
-# via the query interface
-#
-class ResultSet(BaseResultSet):
+class ResultSet (Base.ResultSet):
+  """
+  Handles a resultset (i.e. a list) in the GNUe-AppServer backend.
+  """
+  # This is actually never used
+  _recordSetClass = RecordSet.RecordSet
 
-  _recordSetClass = RecordSet
+  # ---------------------------------------------------------------------------
+  # Initialization
+  # ---------------------------------------------------------------------------
 
-  def __init__ (self, dataObject, cursor = None, defaultValues = {},
-                masterRecordSet = None, fetchcount = 5):
-    BaseResultSet.__init__ (self, dataObject, cursor, defaultValues,
-                            masterRecordSet)
-    self.fetchcount = fetchcount
+  def __init__ (self, dataObject, sm, session_id, list_id, classname,
+                fieldlist, fetchcount, readOnly, masterRecordSet):
 
+    Base.ResultSet.__init__ (self, dataObject,
+                             masterRecordSet = masterRecordSet)
+    self._readOnly = readOnly
 
-  def _loadNextRecord(self):
+    self.__sm = sm
+    self.__session_id = session_id
+    self.__list_id = list_id
+    self.__classname = classname
+    self.__fieldlist = fieldlist
+    self.__fetchcount = fetchcount
 
-    more = 0
-    if self._cursor:
+    if self.__list_id:
+      self.__position = 0               # current fetch position in resultset
+    else:
+      # Empty result set
+      self.__position = -1
 
-      # load next records into local cache
+  # ---------------------------------------------------------------------------
+  # Fetch next records
+  # ---------------------------------------------------------------------------
 
-      instances = self._cursor.fetch (self.fetchcount)
-      for i in instances:
+  def _loadNextRecord (self):
 
-        more = 1
+    if self.__position == -1:
+      return False
 
-        record=self._recordSetClass(parent=self,initialData=i)
+    records = self.__sm.fetch (self.__session_id,
+                               self.__list_id,
+                               self.__position,
+                               self.__fetchcount)
+    if not records:
+      self.__position = -1
+      return False
 
-        self._cachedRecords.append (record)
+    if len (records) < self.__fetchcount:
+      self.__position = -1
+    else:
+      self.__position += len (records)
 
-        self._recordCount=self._recordCount+1
+    for record in records:
+      dict = {}
+      j = 0
+      for fieldName in ['gnue_id'] + self.__fieldlist:
+        dict [fieldName] = record [j]
+        j += 1
 
-    # if no record returned return a zero
-    return more
+      r = RecordSet.RecordSet (self, self.__sm, self.__session_id,
+                               self.__classname, dict)
+      self._cachedRecords.append (r)
+      self._recordCount += 1
 
+    return True
 
+  # ---------------------------------------------------------------------------
+  # Create an empty record
+  # ---------------------------------------------------------------------------
+
+  def _createEmptyRecord (self):
+    return RecordSet.RecordSet (self, self.__sm, self.__session_id,
+                                self.__classname)


Property changes on: 
trunk/gnue-common/src/datasources/drivers/appserver/appserver/ResultSet.py
___________________________________________________________________
Name: svn:keywords
   + Id

Modified: 
trunk/gnue-common/src/datasources/drivers/appserver/appserver/__init__.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/appserver/appserver/__init__.py   
2004-04-03 23:37:51 UTC (rev 5627)
+++ trunk/gnue-common/src/datasources/drivers/appserver/appserver/__init__.py   
2004-04-03 23:39:35 UTC (rev 5628)
@@ -1,10 +1,13 @@
+# GNU Enterprise Datasource Library - Driver for GNUe-AppServer
 #
+# Copyright 2000-2004 Free Software Foundation
+#
 # This file is part of GNU Enterprise.
 #
 # GNU Enterprise is free software; you can redistribute it
 # and/or modify it under the terms of the GNU General Public
 # License as published by the Free Software Foundation; either
-# version 2, or(at your option) any later version.
+# version 2, or (at your option) any later version.
 #
 # GNU Enterprise is distributed in the hope that it will be
 # useful, but WITHOUT ANY WARRANTY; without even the implied
@@ -16,21 +19,13 @@
 # write to the Free Software Foundation, Inc., 59 Temple Place
 # - Suite 330, Boston, MA 02111-1307, USA.
 #
-# Copyright 2000-2004 Free Software Foundation
-#
+# $Id$
+
 """
-appserver init file
+Implementation of dbdriver for use with GNUe Application Server.
 """
 
-# Test if plugin is functional
-def __initplugin__ ():
-  import Connection
-
-#
-# Stub code to not initialize the Connection until needed.
-# This greatly helps with error messages.
-#
-def Connection(*args, **parms):
-  from Connection import Connection as C
-  return C(*args, **parms)
-
+from Connection import Connection
+from DataObject import DataObject
+from ResultSet import ResultSet
+from RecordSet import RecordSet


Property changes on: 
trunk/gnue-common/src/datasources/drivers/appserver/appserver/__init__.py
___________________________________________________________________
Name: svn:keywords
   + Id





reply via email to

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