commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r8120 - in trunk: gnue-appserver/src gnue-appserver/src/language


From: johannes
Subject: [gnue] r8120 - in trunk: gnue-appserver/src gnue-appserver/src/language gnue-common/src/datasources/drivers/other
Date: Thu, 5 Jan 2006 03:41:13 -0600 (CST)

Author: johannes
Date: 2006-01-05 03:41:11 -0600 (Thu, 05 Jan 2006)
New Revision: 8120

Modified:
   trunk/gnue-appserver/src/data.py
   trunk/gnue-appserver/src/geasGsdGen.py
   trunk/gnue-appserver/src/geasInstance.py
   trunk/gnue-appserver/src/geasList.py
   trunk/gnue-appserver/src/geasSession.py
   trunk/gnue-appserver/src/geasSessionManager.py
   trunk/gnue-appserver/src/language/Object.py
   trunk/gnue-appserver/src/language/ObjectList.py
   trunk/gnue-appserver/src/language/Procedure.py
   trunk/gnue-appserver/src/language/Session.py
   trunk/gnue-appserver/src/repository.py
   trunk/gnue-appserver/src/test.py
   trunk/gnue-appserver/src/testRPC.py
   trunk/gnue-common/src/datasources/drivers/other/appserver.py
Log:
Appserver now uses the object oriented RPC interface -- the flat one is 
removed. Appserver uses python's datetime library for date, time and 
datetime types now.



Modified: trunk/gnue-appserver/src/data.py
===================================================================
--- trunk/gnue-appserver/src/data.py    2006-01-04 00:01:11 UTC (rev 8119)
+++ trunk/gnue-appserver/src/data.py    2006-01-05 09:41:11 UTC (rev 8120)
@@ -21,16 +21,10 @@
 #
 # $Id$
 
-import copy
-import weakref
-import time
-
 from gnue.common.apps import errors
 from gnue.common.datasources import GDataSource, GConditions, GConnections
 from gnue.common.utils.uuid import UUID
 
-bestone = None
-
 class StateChangeError (errors.SystemError):
   def __init__ (self, table, row, oldState):
     msg = u_("Changing state from '%(oldstate)s' to 'initialized' not allowed "

Modified: trunk/gnue-appserver/src/geasGsdGen.py
===================================================================
--- trunk/gnue-appserver/src/geasGsdGen.py      2006-01-04 00:01:11 UTC (rev 
8119)
+++ trunk/gnue-appserver/src/geasGsdGen.py      2006-01-05 09:41:11 UTC (rev 
8120)
@@ -785,7 +785,7 @@
 
     result = GDataSource.DataSourceWrapper (connections = self.connections,
         attributes = {'name'      : "dts_%s" % table,
-                      'database'  : self.sm._internalSession.database,
+                      'database'  : repository._database,
                       'table'     : table,
                       'primarykey': 'gnue_id'},
         fields = fieldList)

Modified: trunk/gnue-appserver/src/geasInstance.py
===================================================================
--- trunk/gnue-appserver/src/geasInstance.py    2006-01-04 00:01:11 UTC (rev 
8119)
+++ trunk/gnue-appserver/src/geasInstance.py    2006-01-05 09:41:11 UTC (rev 
8120)
@@ -246,20 +246,8 @@
     else:
       value = record.getField (propertydef.column)
 
-    value = self.__convert (value, propertydef, DbValueError)
+    return self.__convert (value, propertydef, DbValueError)
 
-    # FIXME: For compatibility, return mx.DateTime instead of datetime objects.
-    # Remove this for 0.5
-    if isinstance (value, datetime.datetime):
-      return mx.DateTime.DateTime (value.year, value.month, value.day,
-          value.hour, value.minute, value.second + value.microsecond / 1000000)
-    elif isinstance (value, datetime.date):
-      return mx.DateTime.DateTime (value.year, value.month, value.day, 0, 0, 0)
-    elif isinstance (value, datetime.time):
-      return mx.DateTime.DateTimeDelta (0, value.hour, value.minute,
-          value.second + value.microsecond / 1000000)
-    else:
-      return value
 
   # ---------------------------------------------------------------------------
   # Get the values of a list of properties
@@ -319,11 +307,10 @@
     checktype (namespace, [None, dict])
 
     # Create a session object which with the actual session id
-    sess = Session.Session (self.__session.sm, id (self.__session),
-                            self.__session.parameters)
+    sess = Session.Session (self.__session, self.__session.parameters)
 
     # Create an object representing the current business object
-    obj = Object.Object (sess, self.__classdef.fullName,
+    obj = Object.Object (sess, self.__session, self.__classdef.fullName,
                          self.__getValue (u'gnue_id'))
 
     # check and convert the parameters
@@ -357,13 +344,6 @@
       cx.bindFunction ('new',        sess.new)
       cx.bindBuiltin ('message',    sess.message)
 
-      # direct access to RPC API func.
-      cx.bindFunction ('direct_request', self.__session.request)
-      cx.bindFunction ('direct_fetch',   self.__session.fetch)
-      cx.bindFunction ('direct_load',    self.__session.load)
-      cx.bindFunction ('direct_store',   self.__session.store)
-      cx.bindFunction ('direct_call',    self.__session.call)
-
       # set context for the procedure
       sess.setcontext (proceduredef.gnue_module.gnue_name)
 

Modified: trunk/gnue-appserver/src/geasList.py
===================================================================
--- trunk/gnue-appserver/src/geasList.py        2006-01-04 00:01:11 UTC (rev 
8119)
+++ trunk/gnue-appserver/src/geasList.py        2006-01-05 09:41:11 UTC (rev 
8120)
@@ -26,6 +26,7 @@
 import copy
 
 from gnue.common.datasources import GConditions
+from gnue.common.apps import errors, i18n
 
 # =============================================================================
 # List class
@@ -233,8 +234,14 @@
 
   def count (self):
     """
-    This function returns the number of instances available in this list.
+    Get the number of instances available in this list.
+
+    @return: number of instances available in this list
     """
+
+    if self.__session.locale:
+      i18n.setcurrentlocale (self.__session.locale)
+
     if self.__condition is not None:
       self.__fillupFunc (0)
       return len (self.__instances)
@@ -255,6 +262,9 @@
     If @start is negative, the starting point is from the end of the list.
     """
 
+    if self.__session.locale:
+      i18n.setcurrentlocale (self.__session.locale)
+
     if start < 0:
       self.__fillupFunc (0)
     else:

Modified: trunk/gnue-appserver/src/geasSession.py
===================================================================
--- trunk/gnue-appserver/src/geasSession.py     2006-01-04 00:01:11 UTC (rev 
8119)
+++ trunk/gnue-appserver/src/geasSession.py     2006-01-05 09:41:11 UTC (rev 
8120)
@@ -275,6 +275,33 @@
 
 
   # ---------------------------------------------------------------------------
+  # Close a session
+  # ---------------------------------------------------------------------------
+
+  def close (self, commit):
+    """
+    Close the session and optionally commit pending changes. The session will
+    be logged out from the application server and removed from the session
+    manager's session-dictionary.
+
+    @param commit: if True, pending changes will be commited before closing
+    """
+
+    assert gEnter (4)
+
+    if commit:
+      self.commit ()
+
+    # FIXME: is a session-id-dictionary really needed by the session manager ?
+    if self.sm is not None:
+      del self.sm._sessions [id (self)]
+
+    self.logout ()
+
+    assert gLeave (4)
+
+
+  # ---------------------------------------------------------------------------
   # Commit the active transaction
   # ---------------------------------------------------------------------------
 
@@ -284,6 +311,8 @@
     backend will be requested to do so, all dirty instances are validated.
     """
 
+    assert gEnter (4)
+
     if self.locale:
       i18n.setcurrentlocale (self.locale)
 
@@ -314,25 +343,63 @@
     # successfully we can send a commit to the backend now.
     self.__connection.commit ()
 
+    assert gLeave (4)
 
+
   # ---------------------------------------------------------------------------
   # Rollback the active transaction
   # ---------------------------------------------------------------------------
 
   def rollback (self):
+    """
+    Rollback the active transaction.
+    """
 
+    assert gEnter (4)
+
     if self.locale:
       i18n.setcurrentlocale (self.locale)
 
     self.__connection.rollback ()
     self.__dirtyInstances = {}
 
+    assert gLeave (4)
+
+
   # ---------------------------------------------------------------------------
   # Create a new list of business objects of a given class
   # ---------------------------------------------------------------------------
 
   def request (self, classname, conditions, sortorder, propertylist):
+    """
+    Create a new list instance containing all items of a given class matching
+    the requested conditions. The elements are sorted according to the given
+    sortorder and preloaded with the given properties.
 
+    @param classname: name of the class to fetch items from
+    @param conditions: a condition (list, dictionary, GConditionTree, ...)
+      acceptable to GCondition.buildCondition to filter items
+    @param sortorder: list of sort-instructions to build the resulting list.
+      Such a sort-instruction could be a string, a tuple, a list or a
+      dictionary. A sort item consists of three parts: propertyname,
+      sort-direction and case-sensitiveness. 
+
+      string     : propertyname
+      tuple, list: (propertyname, descending, ignorecase)
+      dictionary : {'name': ..., 'descending': ..., 'ignorecase': ...}
+
+      A sort item must not be completeley defined. If an element is omitted,
+      the following defaults apply: descending = False, ignorecase = False
+
+    @param propertylist: sequence of properties to fetch for each item in the
+      resulting list. Such propertynames could also be reference properties
+      like 'x_foo.y_bar'. In this case the needed join would be added
+      automatically.
+    @returns: L{geasList.geasList} instance
+    """
+
+    assert gEnter (4)
+
     if self.locale:
       i18n.setcurrentlocale (self.locale)
 
@@ -378,18 +445,19 @@
 
     recordset = self.__connection.query (content, dsCond, sortlist)
 
-    list = geasList.geasList (self, classdef, self.__connection, recordset,
+    result = geasList.geasList (self, classdef, self.__connection, recordset,
                            [u'gnue_id'] + propertylist, asCond, dsSort, asSort)
 
     # We use the address of the geasList object in memory as the list id.  This
     # way, every list gets a really unique list id, and this is even thread
     # safe.
-    list_id = id (list)
-    self.__lists [list_id] = list
+    self.__lists [id (result)] = result
 
-    return list_id
+    assert gLeave (4, result)
 
+    return result
 
+
   # ---------------------------------------------------------------------------
   # Transform a given item to a proper sort-element dictionary
   # ---------------------------------------------------------------------------
@@ -420,46 +488,6 @@
 
 
   # ---------------------------------------------------------------------------
-  # Check list id and raise exception if invalid, return list otherwise
-  # ---------------------------------------------------------------------------
-
-  def __getList (self, list_id):
-
-    if self.__lists.has_key (list_id):
-      return self.__lists [list_id]
-    else:
-      raise ListNotFoundError, (list_id)
-
-  # ---------------------------------------------------------------------------
-  # Count the number of objects in the list
-  # ---------------------------------------------------------------------------
-
-  def count (self, list_id):
-
-    if self.locale:
-      i18n.setcurrentlocale (self.locale)
-
-    list = self.__getList (list_id)
-    result = list.count ()
-
-    return result
-
-  # ---------------------------------------------------------------------------
-  # Fetch data from the database backend
-  # ---------------------------------------------------------------------------
-
-  def fetch (self, list_id, start, count):
-
-    if self.locale:
-      i18n.setcurrentlocale (self.locale)
-
-    list = self.__getList (list_id)
-    result = list.fetch (start, count)
-
-    return result
-
-
-  # ---------------------------------------------------------------------------
   # Create a single geasInstance object from an existing record
   # ---------------------------------------------------------------------------
 
@@ -514,7 +542,21 @@
   # ---------------------------------------------------------------------------
 
   def load (self, classname, obj_id_list, propertylist):
+    """
+    Load data or datatypes of a given class from the database backend.
 
+    @param classname: name of the class to retrieve data for
+    @param obj_id_list: sequence of gnue_id's to fetch data for. If such a
+      gnue_id is None the datatypes of the properties will be fetched instead 
of
+      the data values.
+    @param propertylist: sequence of propertynames to fetch data or datatypes
+      for.
+
+    @returns: sequence of sequences holding the result-values (one per gnue_id)
+    """
+
+    assert gEnter (4)
+
     if self.locale:
       i18n.setcurrentlocale (self.locale)
 
@@ -540,14 +582,33 @@
 
         result.append (typelist)
 
+    assert gLeave (4, result)
+
     return result
 
+
   # ---------------------------------------------------------------------------
   # Store data in the database backend
   # ---------------------------------------------------------------------------
 
   def store (self, classname, obj_id_list, propertylist, data):
+    """
+    Store data for a given class in the backend database. All changes within a
+    single call of this function are treated as an atomic operation. The update
+    stamps (gnue_create*, gnue_modify*) will be updated automatically if 
needed.
+    
+    @param classname: name of the class to store data for
+    @param obj_id_list: sequence of gnue_id's representing the objects to store
+      data for. A gnue_id of None represents a new object. In this case a new
+      gnue_id will be generated.
+    @param propertylist: sequence of the properties to store data for
+    @param data: sequence of sequences with the actual data values, one
+      sequence per object-id. Order of propertylist and data-sequence must
+      match.
+    """
 
+    assert gEnter (4)
+
     if self.locale:
       i18n.setcurrentlocale (self.locale)
 
@@ -586,6 +647,8 @@
       if opControl:
         self.__confirmOperation ()
 
+    assert gLeave (4, result)
+
     return result
 
 
@@ -594,7 +657,18 @@
   # ---------------------------------------------------------------------------
 
   def delete (self, classname, obj_id_list):
+    """
+    Delete objects of a given class. A single call of this function is treated
+    as an atomic operation. If on delete fails, all previous deletes will be
+    revoked.
 
+    @param classname: name of the class to delete objects from
+    @param obj_id_list: sequence of gnue_id's representing the objects to
+      delete
+    """
+
+    assert gEnter (4)
+
     if self.locale:
       i18n.setcurrentlocale (self.locale)
 
@@ -623,13 +697,27 @@
       if opControl:
         self.__confirmOperation ()
 
+    assert gLeave (4)
 
+
   # ---------------------------------------------------------------------------
   # Call a procedure of business objects
   # ---------------------------------------------------------------------------
 
   def call (self, classname, obj_id_list, procedurename, parameters):
+    """
+    Call a procedure of a given class on a sequence of gnue_id's.
 
+    @param classname: name of the class
+    @param obj_id_list: sequence of gnue_id's representing the objects to call
+      the procedure for
+    @param procedurename: name of the procedure to call
+    @param parameters: dictionary of parameters to pass to each call
+    @returns: sequence of sequences with the procedure-results one per gnue_id
+    """
+
+    assert gEnter (4)
+
     if self.locale:
       i18n.setcurrentlocale (self.locale)
 
@@ -653,6 +741,8 @@
       if opControl:
         self.__confirmOperation ()
 
+    assert gLeave (4, result)
+
     return result
 
 
@@ -755,7 +845,7 @@
 
       cond   = {'gnue_id': filterValue}
       fList  = self.request (filterName, cond, [], ['gnue_id'])
-      idList = self.fetch (fList, 0, 5)
+      idList = fList.fetch (0, 5)
 
       if not len (idList):
         raise InvalidFilterValueError, (filterName, filterValue)

Modified: trunk/gnue-appserver/src/geasSessionManager.py
===================================================================
--- trunk/gnue-appserver/src/geasSessionManager.py      2006-01-04 00:01:11 UTC 
(rev 8119)
+++ trunk/gnue-appserver/src/geasSessionManager.py      2006-01-05 09:41:11 UTC 
(rev 8120)
@@ -212,178 +212,42 @@
   # Open the connection
   # ---------------------------------------------------------------------------
 
-  def open (self, authentication):
+  def open (self, parameters):
+    """
+    Create a new connection to the application server and return a session
+    object.
 
+    @param parameters: dictionary of parameters passed to the newly created
+      session. This might contain information for authentication (like
+      '_username' and '_password') as well as locale information.
+    @returns: L{geasSession.geasSession} instance
+    """
+
     assert gEnter (4)
 
     loginHandler = self._connections._loginHandler
     loginOptions = self._connections._loginOptions
     location     = self._connections._location
     
-    conn = GConnections.GConnections(location, loginHandler, loginOptions)
+    conn = GConnections.GConnections (location, loginHandler, loginOptions)
    
     sess = geasSession.geasSession (conn, self._authAdapter, self,
-                                    authentication)
+                                    parameters)
 
-    sess.login (authentication.get ('_username'),
-                authentication.get ('_password'))
+    sess.login (parameters.get ('_username'),
+                parameters.get ('_password'))
 
     # We use the memory address of the geasSession object as session id.  This
     # is always unique and even thread safe.
     session_id = id (sess)
     self._sessions [session_id] = sess
 
-    result = session_id
-    assert gLeave (4, result)
+    assert gLeave (4, sess)
 
-    return result
+    return sess
 
-  # ---------------------------------------------------------------------------
-  # Close the connection
-  # ---------------------------------------------------------------------------
 
-  def close (self, session_id, commit):
-
-    assert gEnter (4)
-
-    s = self._getSession (session_id)
-    if commit:
-      s.commit ()
-    s.logout ()
-    del self._sessions [session_id]
-
-    assert gLeave (4)
-
   # ---------------------------------------------------------------------------
-  # Commit current transaction
-  # ---------------------------------------------------------------------------
-
-  def commit (self, session_id):
-
-    assert gEnter (4)
-
-    s = self._getSession (session_id)
-    s.commit ()
-
-    assert gLeave (4)
-
-  # ---------------------------------------------------------------------------
-  # Rollback current transaction
-  # ---------------------------------------------------------------------------
-
-  def rollback (self, session_id):
-
-    assert gEnter (4)
-
-    s = self._getSession (session_id)
-    s.rollback ()
-
-    assert gLeave (4)
-
-
-  # ---------------------------------------------------------------------------
-  # Build list from query
-  # ---------------------------------------------------------------------------
-
-  def request (self, session_id, classname, conditions, sortorder,
-               propertylist):
-
-    assert gEnter (4)
-
-    s = self._getSession (session_id)
-    result = s.request (classname, conditions, sortorder, propertylist)
-
-    assert gLeave (4, result)
-    return result
-
-
-  # ---------------------------------------------------------------------------
-  # Count number of objects in list
-  # ---------------------------------------------------------------------------
-
-  def count (self, session_id, list_id):
-
-    assert gEnter (4)
-
-    s = self._getSession (session_id)
-    result = s.count (list_id)
-
-    assert gLeave (4, result)
-    return result
-
-  # ---------------------------------------------------------------------------
-  # Fetch objects from list
-  # ---------------------------------------------------------------------------
-
-  def fetch (self, session_id, list_id, start, count, close = False):
-
-    assert gEnter (4)
-    s = self._getSession (session_id)
-    result = s.fetch (list_id, start, count)
-
-    assert gLeave (4, result)
-    return result
-
-
-  # ---------------------------------------------------------------------------
-  # Load objects from ids
-  # ---------------------------------------------------------------------------
-
-  def load (self, session_id, classname, obj_id_list, propertylist):
-
-    assert gEnter (4)
-
-    s = self._getSession (session_id)
-    result = s.load (classname, obj_id_list, propertylist)
-
-    assert gLeave (4, result)
-    return result
-
-  # ---------------------------------------------------------------------------
-  # Store objects
-  # ---------------------------------------------------------------------------
-
-  def store (self, session_id, classname, obj_id_list, propertylist, data):
-
-    assert gEnter (4)
-
-    s = self._getSession (session_id)
-    result = s.store (classname, obj_id_list, propertylist, data)
-
-    assert gLeave (4, result)
-    return result
-
-  # ---------------------------------------------------------------------------
-  # Delete objects
-  # ---------------------------------------------------------------------------
-
-  def delete (self, session_id, classname, obj_id_list):
-
-    assert gEnter (4)
-
-    s = self._getSession (session_id)
-    s.delete (classname, obj_id_list)
-
-    assert gLeave (4)
-
-
-  # ---------------------------------------------------------------------------
-  # Call procedure
-  # ---------------------------------------------------------------------------
-
-  def call (self, session_id, classname, obj_id_list, procedurename,
-            parameters):
-
-    assert gEnter (4)
-
-    s = self._getSession (session_id)
-    result = s.call (classname, obj_id_list, procedurename, parameters)
-
-    assert gLeave (4, result)
-    return result
-
-
-  # ---------------------------------------------------------------------------
   # Get a structure describing all available filters
   # ---------------------------------------------------------------------------
 

Modified: trunk/gnue-appserver/src/language/Object.py
===================================================================
--- trunk/gnue-appserver/src/language/Object.py 2006-01-04 00:01:11 UTC (rev 
8119)
+++ trunk/gnue-appserver/src/language/Object.py 2006-01-05 09:41:11 UTC (rev 
8120)
@@ -47,18 +47,19 @@
   # Constructor
   # -------------------------------------------------------------------------
 
-  def __init__ (self, session, classname, objectId = None, definition = None):
+  def __init__ (self, session, proxy, classname, objectId = None,
+      definition = {}):
+
     # we won't trigger __setattr__ here ...
     self.__dict__ ['objectId']            = objectId
     self.__dict__ ['_Object__session']    = session
+    self.__dict__ ['_Object__proxy']      = proxy
     self.__dict__ ['_Object__class']      = classname
-    self.__dict__ ['_Object__sid']        = session.getSessionId ()
-    self.__dict__ ['_Object__definition'] = definition or {}
+    self.__dict__ ['_Object__definition'] = definition
 
     if self.objectId is None:
       # Create new object
-      sm  = session.getSessionManager ()
-      res = sm.store (self.__sid, self.__class, [None], [], [[]])
+      res = session._store (self.__class, [None], [], [[]])
       self.objectId = res [0]
 
     self.__dict__ ['gnue_id'] = self.objectId
@@ -80,11 +81,9 @@
       assert gLeave (6, result)
       return result
 
-    sm = self.__session.getSessionManager ()
-
     try:
       if not self.__definition.has_key (key):
-        self.__definition [key] = sm.load (self.__sid, self.__class, [''],
+        self.__definition [key] = self.__proxy.load (self.__class, [''],
                                            [name]) [0][0]
       datatype = self.__definition [key]
 
@@ -92,21 +91,22 @@
       raise MemberNotFoundError, (self.__class, name)
 
     if datatype == 'procedure':
-      result = Procedure (self.__session, self.objectId, self.__class, name)
+      result = Procedure (self.__session, self.__proxy, self.objectId,
+                          self.__class, name)
 
     else:
-      res = sm.load (self.__sid, self.__class, [self.objectId], [name])
+      res = self.__proxy.load (self.__class, [self.objectId], [name])
       value = res [0][0]
 
       # Convert reference fields to object references
       if '_' in datatype and value is not None:
         cDef   = self.__session.getClassDefinition (datatype)
-        result = Object (self.__session, datatype, value, cDef)
+        result = Object (self.__session, self.__proxy, datatype, value, cDef)
 
       elif value is None:
         if '_' in datatype:
           cDef   = self.__session.getClassDefinition (datatype)
-          result = NullObject (self.__session, datatype, cDef)
+          result = NullObject (self.__session, self.__proxy, datatype, cDef)
         else:
           result = None
 
@@ -136,11 +136,10 @@
     if not self.__dict__.has_key (attr) or attr.lower () == 'gnue_id':
       name = self.__session.qualify (attr)
       key  = name.lower ()
-      sm   = self.__session.getSessionManager ()
 
       try:
         if not self.__definition.has_key (key):
-          self.__definition [key] = sm.load (self.__sid, self.__class,
+          self.__definition [key] = self.__proxy.load (self.__class,
                                                    [''], [name]) [0][0]
         datatype = self.__definition [key]
 
@@ -156,7 +155,7 @@
       else:
         __value = value
 
-      sm.store (self.__sid, self.__class, [self.objectId], [name], [[__value]])
+      self.__proxy.store (self.__class, [self.objectId], [name], [[__value]])
 
     assert gLeave (6)
 
@@ -185,14 +184,16 @@
       return '<deleted %s instance>' % self.__class
 
 
-  # -------------------------------------------------------------------------
-  # Make object['property'] possible
-  # -------------------------------------------------------------------------
+  # ---------------------------------------------------------------------------
+  # Make object ['property'] possible
+  # ---------------------------------------------------------------------------
 
   def __getitem__ (self, item):
 
     return self.__getattr__ (item)
 
+  # ---------------------------------------------------------------------------
+
   def __setitem__ (self, item, value):
 
     self.__setattr__ (item, value)
@@ -207,16 +208,15 @@
     return True
 
 
-  # -------------------------------------------------------------------------
+  # ---------------------------------------------------------------------------
   # Delete instance and clear object-id
-  # -------------------------------------------------------------------------
+  # ---------------------------------------------------------------------------
 
   def delete (self):
 
     assert gEnter (6)
 
-    sm = self.__session.getSessionManager ()
-    sm.delete (self.__sid, self.__class, [self.objectId])
+    self.__proxy.delete (self.__class, [self.objectId])
     self.objectId = None
 
     assert gLeave (6)
@@ -233,11 +233,11 @@
   # Constructor
   # ---------------------------------------------------------------------------
 
-  def __init__ (self, session, classname, definition):
+  def __init__ (self, session, proxy, classname, definition):
 
     self.__session    = session
+    self.__proxy      = proxy
     self.__class      = classname
-    self.__sid        = session.getSessionId ()
     self.__definition = definition
 
 
@@ -260,9 +260,8 @@
     name = self.__session.qualify (attr)
     key  = name.lower ()
     if not self.__definition.has_key (key):
-      sm = self.__session.getSessionManager ()
-      self.__definition [key] = sm.load (self.__sid, self.__class,
-                                               [''], [name]) [0][0]
+      self.__definition [key] = self.__proxy.load (self.__class, [''],
+                                                      [name]) [0][0]
     if '_' in self.__definition [key]:
       self.__class      = self.__definition [key]
       self.__definition = self.__session.getClassDefinition (self.__class)

Modified: trunk/gnue-appserver/src/language/ObjectList.py
===================================================================
--- trunk/gnue-appserver/src/language/ObjectList.py     2006-01-04 00:01:11 UTC 
(rev 8119)
+++ trunk/gnue-appserver/src/language/ObjectList.py     2006-01-05 09:41:11 UTC 
(rev 8120)
@@ -29,18 +29,20 @@
 # ===========================================================================
 # Class: ObjectList
 # ===========================================================================
+
 class ObjectList:
 
   # -------------------------------------------------------------------------
   # Constructor
   # -------------------------------------------------------------------------
 
-  def __init__ (self, session, classname, cond, sort, properties, definition):
+  def __init__ (self, session, proxy, classname, cond, sort, properties,
+      definition):
 
     self.__session   = session
+    self.__proxy     = proxy
     self.__list      = []
-    self.__list_id   = None
-    self.__sid       = session.getSessionId ()
+    self.__geasList  = None
 
     self.classname   = classname
     self.conditions  = self.__normalizeCondition (cond)
@@ -58,8 +60,7 @@
 
   def __len__ (self):
 
-    sm  = self.__session.getSessionManager ()
-    return sm.count (self.__sid, self.__list_id)
+    return self.__geasList.count ()
 
 
   # ---------------------------------------------------------------------------
@@ -74,7 +75,9 @@
   # -------------------------------------------------------------------------
   # Return a slice or a specific element of this sequence
   # -------------------------------------------------------------------------
+
   def __getitem__ (self, index):
+
     try:
       if isinstance (index, slice):
         if index.start < 0:
@@ -101,11 +104,11 @@
   # -------------------------------------------------------------------------
   # Create an initial sequence
   # -------------------------------------------------------------------------
+
   def __buildList (self):
-    sm  = self.__session.getSessionManager ()
 
-    self.__list_id = sm.request (self.__sid, self.classname, self.conditions,
-                                 self.sortOrder, self.properties)
+    self.__geasList = self.__proxy.request (self.classname, self.conditions,
+                                            self.sortOrder, self.properties)
     self.__list = []
     self.__populateList ()
 
@@ -113,13 +116,13 @@
   # -------------------------------------------------------------------------
   # Populate Cache
   # -------------------------------------------------------------------------
+
   def __populateList (self):
-    sm  = self.__session.getSessionManager ()
 
-    rset = sm.fetch (self.__sid, self.__list_id, len (self.__list),
-                     self.__cacheStep, 0)
+    rset = self.__geasList.fetch (len (self.__list), self.__cacheStep)
     for row in rset:
-      obj = Object (self.__session, self.classname, row [0], self.definition)
+      obj = Object (self.__session, self.__proxy, self.classname, row [0],
+                    self.definition)
       self.__list.append (obj)
 
     # We double the cache-size for the next call to fetch (). This boosts
@@ -130,6 +133,10 @@
     return len (rset)
     
 
+  # ---------------------------------------------------------------------------
+  # Fetch all records from the list
+  # ---------------------------------------------------------------------------
+
   def __fillup (self):
 
     if len (self.__list) < len (self):

Modified: trunk/gnue-appserver/src/language/Procedure.py
===================================================================
--- trunk/gnue-appserver/src/language/Procedure.py      2006-01-04 00:01:11 UTC 
(rev 8119)
+++ trunk/gnue-appserver/src/language/Procedure.py      2006-01-05 09:41:11 UTC 
(rev 8120)
@@ -24,28 +24,31 @@
 # =============================================================================
 # Implement a callable environment for the language interface 
 # =============================================================================
+
 class Procedure:
 
   # ---------------------------------------------------------------------------
   # Constructor
   # ---------------------------------------------------------------------------
-  def __init__ (self, session, objectId, className, procedureName):
+
+  def __init__ (self, session, proxy, objectId, className, procedureName):
+
     self.method     = session.qualify (procedureName)
-
     self.__session  = session
+    self.__proxy    = proxy
     self.__objectId = objectId
     self.__class    = className
 
+
   # ---------------------------------------------------------------------------
   # Delegate calls of this object to the session manager
   # ---------------------------------------------------------------------------
+
   def __call__ (self, **params):
+
     assert gEnter (6)
 
-    sm  = self.__session.getSessionManager ()
-    sid = self.__session.getSessionId ()
-
-    result = sm.call (sid, self.__class, [self.__objectId], self.method,
+    result = self.__proxy.call (self.__class, [self.__objectId], self.method,
                     params) [0]
     assert gLeave (6, result)
     return result

Modified: trunk/gnue-appserver/src/language/Session.py
===================================================================
--- trunk/gnue-appserver/src/language/Session.py        2006-01-04 00:01:11 UTC 
(rev 8119)
+++ trunk/gnue-appserver/src/language/Session.py        2006-01-05 09:41:11 UTC 
(rev 8120)
@@ -51,51 +51,23 @@
   # Constructor
   # -------------------------------------------------------------------------
 
-  def __init__ (self, sessionManager, sessionId, params = {}):
+  def __init__ (self, proxy, params = {}):
     """
     Create an instance of a language interface session
 
-    @param sessionManager: the session manager to be used
-    @param sessionId: id of the session encapsulated by the instance
+    @param proxy: session proxy object
     @param params: dictionary of session parameters
     """
 
-    self.__sm         = sessionManager
-    self.__session_id = sessionId
-    self.__context    = None
-    self.parameters   = params
-    self.classdefs    = {}
+    self.__proxy    = proxy
+    self.__context  = None
+    self.parameters = params
+    self.classdefs  = {}
 
-    assert gDebug (6, "Built session %s with params %s" % (sessionId, params))
+    assert gDebug (6, "Built session %s with params %s" % (proxy, params))
 
 
   # -------------------------------------------------------------------------
-  # Get the session's sessionManager
-  # -------------------------------------------------------------------------
-
-  def getSessionManager (self):
-    """
-    This function returns the session manager this session is bound to
-    @return: session manager instance
-    """
-
-    return self.__sm
-
-
-  # -------------------------------------------------------------------------
-  # Get the session's id
-  # -------------------------------------------------------------------------
-
-  def getSessionId (self):
-    """
-    This function returns the id of this session in the session manager.
-    @return: id of the session
-    """
-
-    return self.__session_id
-
-
-  # -------------------------------------------------------------------------
   # Get or created the class definition dictionary for a given class
   # -------------------------------------------------------------------------
 
@@ -106,18 +78,12 @@
     contains the datatype per class-element (property/procedure).
 
     @param classname: name of the class to return a definition dictionary for
-    @return: class definition dictionary for the requested class
+    @return: empty dictionary
     """
 
     return {}
 
-    key = classname.lower ()
-    if not self.classdefs.has_key (key):
-      self.classdefs [key] = {}
 
-    return self.classdefs [key]
-
-
   # -------------------------------------------------------------------------
   # Set the default context
   # -------------------------------------------------------------------------
@@ -189,9 +155,9 @@
 
     assert gEnter (6)
 
-    if self.__sm is not None:
-      self.__sm.close (self.__session_id, None)
-      self.__sm = self.__session_id = None
+    if self.__proxy is not None:
+      self.__proxy.close (False)
+      self.__proxy = None
 
     assert gLeave (6)
 
@@ -207,8 +173,8 @@
 
     assert gEnter (6)
 
-    if self.__session_id is not None:
-      self.__sm.commit (self.__session_id)
+    if self.__proxy is not None:
+      self.__proxy.commit ()
 
     assert gLeave (6)
 
@@ -224,8 +190,8 @@
 
     assert gEnter (6)
 
-    if self.__session_id is not None:
-      self.__sm.rollback (self.__session_id)
+    if self.__proxy is not None:
+      self.__proxy.rollback ()
 
     assert gLeave (6)
 
@@ -258,7 +224,8 @@
     name = self.qualify (classname)
     cdef = self.getClassDefinition (name)
 
-    result = ObjectList (self, name, conditions, sortorder, properties, cdef)
+    result = ObjectList (self, self.__proxy, name, conditions, sortorder,
+        properties, cdef)
 
     assert gLeave (6, result)
     return result
@@ -304,7 +271,7 @@
 
     name   = self.qualify (classname)
     cDef   = self.getClassDefinition (name)
-    result = Object (self, name, objectId, cDef)
+    result = Object (self, self.__proxy, name, objectId, cDef)
 
     assert gLeave (6, result)
     return result
@@ -330,10 +297,10 @@
     assert gEnter (6)
 
     name = self.qualify (classname)
-    self.__sm.load (self.__session_id, name, [objectId], [u'gnue_id'])
+    self.__proxy.load (name, [objectId], [u'gnue_id'])
 
     cDef   = self.getClassDefinition (name)
-    result = Object (self, name, objectId, cDef)
+    result = Object (self, self.__proxy, name, objectId, cDef)
 
     assert gLeave (6, result)
     return result
@@ -395,7 +362,7 @@
 
 
 # =============================================================================
-# Login-Session creates a new Session-Id using 'user' and 'password'
+# Login-Session creates a new Session using 'user' and 'password'
 # =============================================================================
 
 class LoginSession (Session):
@@ -409,22 +376,4 @@
     parameters = {'_username': user, '_password': password}
     parameters.update (params)
 
-    Session.__init__ (self, sessionManager, sessionManager.open (parameters),
-        params)
-
-
-
-# =============================================================================
-# InternalSession uses 0 as Session-Id
-# =============================================================================
-
-class InternalSession (Session):
-
-  # -------------------------------------------------------------------------
-  # Constructor
-  # -------------------------------------------------------------------------
-
-  def __init__ (self, sessionManager, params = {}):
-
-    Session.__init__ (self, sessionManager, 0, params)
-
+    Session.__init__ (self, sessionManager.open (parameters), params)

Modified: trunk/gnue-appserver/src/repository.py
===================================================================
--- trunk/gnue-appserver/src/repository.py      2006-01-04 00:01:11 UTC (rev 
8119)
+++ trunk/gnue-appserver/src/repository.py      2006-01-05 09:41:11 UTC (rev 
8120)
@@ -25,7 +25,6 @@
 from gnue.common.utils.CaselessDict import CaselessDict
 
 from gnue.appserver import data
-from gnue.appserver.language import Session
 
 # =============================================================================
 # Exceptions

Modified: trunk/gnue-appserver/src/test.py
===================================================================
--- trunk/gnue-appserver/src/test.py    2006-01-04 00:01:11 UTC (rev 8119)
+++ trunk/gnue-appserver/src/test.py    2006-01-05 09:41:11 UTC (rev 8120)
@@ -69,14 +69,14 @@
     self._ok ()
 
     print "Creating and populating list object ...",
-    list = sm.request (session, "address_person", [], ["address_zip"],
+    list = session.request ("address_person", [], ["address_zip"],
                        ["address_name", "address_street", "address_city",
                         "address_country.address_code",
                         "address_country.address_name"])
     self._ok ()
 
     print "Retrieving first instance ...",
-    rset = sm.fetch (session,list,0,1)
+    rset = list.fetch (0, 1)
     first_id = rset[0][0]
     self._ok ()
 
@@ -87,7 +87,7 @@
     print "  Country:", rset[0][4] + '/' + rset[0][5]
 
     print "Retrieving second instance ...",
-    rset = sm.fetch (session,list,1,1)
+    rset = list.fetch (1, 1)
     self._ok ()
 
     print "These are the values of the second instance:"
@@ -97,11 +97,11 @@
     print "  Country:", rset[0][4] + '/' + rset[0][5]
 
     print "Executing rollback to clear cache ...",
-    sm.rollback (session)
+    session.rollback ()
     self._ok ()
 
     print "Loading the first instance with load () ...",
-    rset = sm.load (session, "address_person", [first_id],
+    rset = session.load ("address_person", [first_id],
                     ["address_name", "address_street", "address_city",
                      "address_country.address_code",
                      "address_country.address_name"])
@@ -114,13 +114,20 @@
     print "  Country:", rset[0][3] + '/' + rset[0][4]
 
     print "Now I call the procedure 'show' for the first instance:"
-    sm.call (session, "address_person", [first_id], "address_show", {})
+    try:
+      res = session.call ("address_person", [first_id], "address_show", {})
+    except Exception, msg:
+      print " Exception:", msg
 
     print "Now I call the procedure 'test' for the first instance:"
-    sm.call (session, "address_person", [first_id], "address_test", {})
+    try:
+      res = session.call ("address_person", [first_id], "address_test", {})
+      print "Result:", res
+    except:
+      pass
 
     print "Committing and closing session ...",
-    sm.close (session, 1)
+    session.close (True)
     self._ok ()
 
 

Modified: trunk/gnue-appserver/src/testRPC.py
===================================================================
--- trunk/gnue-appserver/src/testRPC.py 2006-01-04 00:01:11 UTC (rev 8119)
+++ trunk/gnue-appserver/src/testRPC.py 2006-01-05 09:41:11 UTC (rev 8120)
@@ -30,7 +30,7 @@
 # =============================================================================
 
 class testRpcApp (test.testApp):
-  # standart settings
+  # standard settings
   type   = "xmlrpc"
   params = {"host": "localhost",
             "port": 4711,

Modified: trunk/gnue-common/src/datasources/drivers/other/appserver.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/other/appserver.py        
2006-01-04 00:01:11 UTC (rev 8119)
+++ trunk/gnue-common/src/datasources/drivers/other/appserver.py        
2006-01-05 09:41:11 UTC (rev 8120)
@@ -142,13 +142,12 @@
 
   def __readTables (self, parent):
 
-    sm  = self.__connection._sm
-    sid = self.__connection._sess_id
-    lid = sm.request (sid, u"gnue_class", [], [u"gnue_module.gnue_name",
-                  u"gnue_name"], [u"gnue_module.gnue_name", u"gnue_name"])
+    _list = self.__connection._session.request (u"gnue_class", [],
+        [u"gnue_module.gnue_name", u"gnue_name"], [u"gnue_module.gnue_name",
+        u"gnue_name"])
 
     result = {}
-    for (gid, module, name) in sm.fetch (sid, lid, 0, sm.count (sid, lid)):
+    for (gid, module, name) in _list.fetch (0, _list.count ()):
       fullname = "%s_%s" % (module, name)
       master = parent.findChildOfType ('GSTables') or \
           GSchema.GSTables (parent, **self.__RELTYPE)
@@ -163,16 +162,14 @@
 
   def __readFields (self, tables):
     
-    sm  = self.__connection._sm
-    sid = self.__connection._sess_id
-
+    sess  = self.__connection._session
     sort  = [u"gnue_module", u"gnue_name"]
     props = [u"gnue_module.gnue_name", u"gnue_class", u"gnue_name",
              u"gnue_length", u"gnue_nullable", u"gnue_scale", u"gnue_type"]
-    lid = sm.request (sid, u"gnue_property", [], sort, props)
+    _list = sess.request (u"gnue_property", [], sort, props)
 
     result = {}
-    for record in sm.fetch (sid, lid, 0, sm.count (sid, lid)):
+    for record in _list.fetch (0, _list.count ()):
       (gid, module, cid, name, length, nullable, scale, ftype) = record
 
       result [gid] = self.__createField (tables, gid, module, cid, name,
@@ -210,18 +207,16 @@
 
   def __readCalculatedFields (self, tables):
     
-    sm  = self.__connection._sm
-    sid = self.__connection._sess_id
-
+    sess  = self.__connection._session
     sort  = [u"gnue_module", u"gnue_class", u"gnue_name"]
     props = [u"gnue_module.gnue_name", u"gnue_class", u"gnue_name",
              u"gnue_length", u"gnue_nullable", u"gnue_scale", u"gnue_type"]
     cond  = ['and', ['like',    ['field', u'gnue_name'], ['const', u'get%']],
                     ['notnull', ['field', u'gnue_type']]]
-    lid = sm.request (sid, u"gnue_procedure", cond, sort, props)
+    _list = sess.request (u"gnue_procedure", cond, sort, props)
 
     result = {}
-    for record in sm.fetch (sid, lid, 0, sm.count (sid, lid)):
+    for record in _list.fetch (0, _list.count ()):
       (gid, module, cid, name, length, nullable, scale, ftype) = record
 
       result [gid] = self.__createField (tables, gid, module, cid, name [3:],
@@ -272,29 +267,28 @@
 
   def _query_object_ (self, connection, table, fieldnames, condition, 
sortorder,
                      distinct):
-    self.__sm = connection._sm
-    self.__session_id = connection._sess_id
-    self.__list_id = self.__sm.request (self.__session_id, table,
-                                        condition.prefixNotation (), sortorder,
-                                        fieldnames)
+
+    self.__list = connection._session.request (table,
+                            condition.prefixNotation (), sortorder, fieldnames)
     self.__fieldnames = fieldnames
     self.__distinct   = distinct        # currently not honored
 
   # ---------------------------------------------------------------------------
 
   def _count_ (self):
-    return self.__sm.count (self.__session_id, self.__list_id)
+    return self.__list.count ()
 
   # ---------------------------------------------------------------------------
 
   def _fetch_ (self, cachesize):
     position = 0
     while True:
-      rows = self.__sm.fetch (self.__session_id, self.__list_id, position,
-                              cachesize)
+      rows = self.__list.fetch (position, cachesize)
+
       for row in rows:
         # row [0] is the gnue_id that wasn't requested
         yield dict (zip (self.__fieldnames, row[1:]))
+
       # if fetch returned less rows than we requested, we're at the end of data
       if len (rows) < cachesize:
         break
@@ -324,6 +318,7 @@
     Base.Connection.__init__ (self, connections, name, parameters)
     self.__filters = None
     self._sm       = None
+    self._session  = None
 
 
   # ---------------------------------------------------------------------------
@@ -382,10 +377,13 @@
   # ---------------------------------------------------------------------------
 
   def _connect_ (self, connectData):
+
     self.__getSessionManager ()
     self.__updateFilters (connectData)
+
     try:
-      self._sess_id = self._sm.open (connectData)
+      self._session = self._sm.open (connectData)
+
     except errors.RemoteError, e:
       if e.getName () == 'AuthError':
         raise Exceptions.LoginError, e.getMessage ()
@@ -432,7 +430,7 @@
   # ---------------------------------------------------------------------------
 
   def _initialize_ (self, table, fields):
-    id = self._sm.store (self._sess_id, table, [None], [], [[]]) [0]
+    id = self._session.store (table, [None], [], [[]]) [0]
     return self.requery (table, {u'gnue_id': id}, fields)
 
   # ---------------------------------------------------------------------------
@@ -440,26 +438,26 @@
   def _insert_ (self, table, newfields):
     f = newfields.copy ()
     id = f.pop (u'gnue_id')
-    self._sm.store (self._sess_id, table, [id], f.keys (), [f.values ()])
+    self._session.store (table, [id], f.keys (), [f.values ()])
 
   # ---------------------------------------------------------------------------
 
   def _update_ (self, table, oldfields, newfields):
     f = newfields
     id = oldfields [u'gnue_id']
-    self._sm.store (self._sess_id, table, [id], f.keys (), [f.values ()])
+    self._session.store (table, [id], f.keys (), [f.values ()])
 
   # ---------------------------------------------------------------------------
 
   def _delete_ (self, table, oldfields):
     id = oldfields [u'gnue_id']
-    self._sm.delete (self._sess_id, table, [id])
+    self._session.delete (table, [id])
 
   # ---------------------------------------------------------------------------
 
   def _requery_ (self, table, oldfields, fields):
     id = oldfields [u'gnue_id']
-    rows = self._sm.load (self._sess_id, table, [id], fields)
+    rows = self._session.load (table, [id], fields)
     if len (rows):
       row = rows [0]
       result = {}
@@ -473,24 +471,26 @@
 
   def _call_ (self, table, oldfields, methodname, parameters):
     id = oldfields [u'gnue_id']
-    return self._sm.call (self._sess_id, table, [id], methodname,
-                          parameters) [0]
+    return self._session.call (table, [id], methodname, parameters) [0]
 
   # ---------------------------------------------------------------------------
 
   def _commit_ (self):
-    self._sm.commit (self._sess_id)
+    self._session.commit ()
 
   # ---------------------------------------------------------------------------
 
   def _rollback_ (self):
-    self._sm.rollback (self._sess_id)
+    self._session.rollback ()
 
   # ---------------------------------------------------------------------------
 
   def _close_ (self):
+    if self._session is not None:
+      self._session.close (False)
+      self._session = None
+
     if self._sm is not None:
-      self._sm.close (self._sess_id, False)
       self._sm._destroy ()
       self._sm = None
 





reply via email to

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