commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r7211 - in trunk/gnue-common/src/datasources: . drivers/Base driv


From: reinhard
Subject: [gnue] r7211 - in trunk/gnue-common/src/datasources: . drivers/Base drivers/appserver/appserver
Date: Wed, 16 Mar 2005 18:18:47 -0600 (CST)

Author: reinhard
Date: 2005-03-16 18:18:46 -0600 (Wed, 16 Mar 2005)
New Revision: 7211

Modified:
   trunk/gnue-common/src/datasources/GDataSource.py
   trunk/gnue-common/src/datasources/drivers/Base/Connection.py
   trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py
   trunk/gnue-common/src/datasources/drivers/appserver/appserver/Connection.py
   trunk/gnue-common/src/datasources/drivers/appserver/appserver/RecordSet.py
Log:
Moved sync and call (formerly known as update and callFunc) to connection
object to better fit with the rest of the system.


Modified: trunk/gnue-common/src/datasources/GDataSource.py
===================================================================
--- trunk/gnue-common/src/datasources/GDataSource.py    2005-03-16 22:52:11 UTC 
(rev 7210)
+++ trunk/gnue-common/src/datasources/GDataSource.py    2005-03-17 00:18:46 UTC 
(rev 7211)
@@ -172,38 +172,31 @@
   def deleteCurrentRecordsetEntry(self):
     self._currentResultSet.getPostingRecordset().delete()
 
-  def callFuncOfCurrentRecordsetEntry(self,name,params):
-    n=self._currentResultSet.getRecordNumber()
-    rset=self._currentResultSet.getRecord(n)
-    if hasattr(rset,'callFunc'):
-      return rset.callFunc(name,params)
-    else:
-      tmsg = u_("Backend doesn't support the trigger 'call' function")
-      raise StandardError, tmsg
-
-
   # ---------------------------------------------------------------------------
-  # Update the current record set
+  # Sync the current record with the backend
   # ---------------------------------------------------------------------------
 
   def updateCurrentRecordSet (self):
     """
-    If a result set is available having a record all fields of this record
-    would be updated. If the backend does not support this operation an
-    ApplicationError will be raised.
+    Send changes to the backend and update local data to reflect changes done
+    by the backend.
     """
 
-    if self._currentResultSet is not None:
-      nr = self._currentResultSet.getRecordNumber ()
-      rs = self._currentResultSet.getRecord (nr)
+    if self._currentResultSet and self._currentResultSet.current:
+      self._currentResultSet.current.sync ()
 
-      if hasattr (rs, 'updateRecordSet'):
-        rs.updateRecordSet ()
+  # ---------------------------------------------------------------------------
+  # Call a backend function for the current record
+  # ---------------------------------------------------------------------------
 
-      else:
-        raise errors.ApplicationError, \
-            u_("Backend does not support the 'update' function")
+  def callFuncOfCurrentRecordsetEntry (self, name, params):
+    """
+    Call function in the backend for the current record.
+    """
 
+    if self._currentResultSet and self._currentResultSet.current:
+      self._currentResultSet.current.call (name, params)
+
   #
   # get/set the static condition assosiated with a datasource
   # the static condition is build out of the <condition> child

Modified: trunk/gnue-common/src/datasources/drivers/Base/Connection.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/Base/Connection.py        
2005-03-16 22:52:11 UTC (rev 7210)
+++ trunk/gnue-common/src/datasources/drivers/Base/Connection.py        
2005-03-17 00:18:46 UTC (rev 7211)
@@ -196,6 +196,25 @@
     return gLeave (8, self._requery (table, oldfields, fields))
 
   # ---------------------------------------------------------------------------
+  # Call a backend function
+  # ---------------------------------------------------------------------------
+
+  def call (self, table, oldfields, methodname, parameters):
+    """
+    Call a function of the backend.
+
+    @param table: Table name.
+    @param oldfields: Fieldname/Value dictionary of fields to find the existing
+      record (aka where-clause).
+    @param methodname: Name of the function to call.
+    @param parameters: parametername/value dictionary.
+    @param recno: Record number to be used in error messages.
+    @return: Result of the function that was called.
+    """
+    gEnter (8)
+    return gLeave (8, self._call (table, oldfields, methodname, parameters))
+
+  # ---------------------------------------------------------------------------
   # Commit pending changes in the backend
   # ---------------------------------------------------------------------------
 
@@ -511,6 +530,25 @@
 
   # ---------------------------------------------------------------------------
 
+  def _call (self, table, oldfields, methodname, parameters):
+    """
+    Call a function of the backend (to be implemented by descendants).
+
+    This method can be overwritten by the database drivers to call a function
+    that runs in the backend for a specific record.
+
+    @param table: Table name.
+    @param oldfields: Fieldname/Value dictionary of fields to find the existing
+      record (aka where-clause).
+    @param methodname: Name of the function to call.
+    @param parameters: parametername/value dictionary.
+    @param recno: Record number to be used in error messages.
+    @return: Result of the function that was called.
+    """
+    pass
+
+  # ---------------------------------------------------------------------------
+
   def _commit (self):
     """
     Commit pending changes in the backend (to be implemented by descendants).

Modified: trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py 2005-03-16 
22:52:11 UTC (rev 7210)
+++ trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py 2005-03-17 
00:18:46 UTC (rev 7211)
@@ -23,6 +23,7 @@
 
 import string
 
+from gnue.common.apps import errors
 from gnue.common.datasources import Exceptions
 
 
@@ -370,6 +371,73 @@
 
 
   # ---------------------------------------------------------------------------
+  # Post and requery the top level master record
+  # ---------------------------------------------------------------------------
+
+  def __post_master (self):
+
+    if self._parent._masterRecordSet:
+      self._parent._masterRecordSet.__post_master ()
+    else:
+      self.post ()
+
+  # ---------------------------------------------------------------------------
+
+  def __requery_master (self):
+
+    if self._parent._masterRecordSet:
+      self._parent._masterRecordSet.__requery_master ()
+    else:
+      self.__requery ()
+
+
+  # ---------------------------------------------------------------------------
+  # Sync backend with frontend
+  # ---------------------------------------------------------------------------
+
+  def sync (self):
+    """
+    Write all local changes of the top level master of this record and all of
+    that's details to the backend, and upate the local cache with changes done
+    by the backend.
+
+    This method can be called to make sure that the backend is up to date with
+    the current state of the data. This makes sense for example before calling
+    some code running in the backend that would need that data (appserver
+    procedures or stored procedures for SQL databases) or when the backend is
+    expected to do some magic on receiving data (like running triggers and
+    recalculating calculated fields).
+    """
+
+    self.__post_master ()
+    self.__requery_master ()
+
+
+  # ---------------------------------------------------------------------------
+  # Call backend code
+  # ---------------------------------------------------------------------------
+
+  def call (self, methodname, parameters):
+    """
+    Call a function of the backend.
+
+    @param methodname: Name of the function to call.
+    @param parameters: Dictionary with parametername/value pairs.
+    @return: Return value of the function that was called.
+    """
+
+    if self.isEmpty ():
+      raise errors.ApplicationError, u_("Function call on empty record")
+
+    self.__post_master ()
+    do = self._parent._dataObject
+    result = do._connection.call (do.table, self.__wherefields (), methodname,
+                                  parameters)
+    self.__requery_master ()
+    return result
+
+
+  # ---------------------------------------------------------------------------
   # Sets the ResultSet associated with this master record
   # ---------------------------------------------------------------------------
 

Modified: 
trunk/gnue-common/src/datasources/drivers/appserver/appserver/Connection.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/appserver/appserver/Connection.py 
2005-03-16 22:52:11 UTC (rev 7210)
+++ trunk/gnue-common/src/datasources/drivers/appserver/appserver/Connection.py 
2005-03-17 00:18:46 UTC (rev 7211)
@@ -188,6 +188,13 @@
 
   # ---------------------------------------------------------------------------
 
+  def _call (self, table, oldfields, methodname, parameters):
+    id = oldfields ['gnue_id']
+    return self._sm.call (self._sess_id, table, [id], methodname,
+                          parameters) [0]
+
+  # ---------------------------------------------------------------------------
+
   def _commit (self):
     self._sm.commit (self._sess_id)
 

Modified: 
trunk/gnue-common/src/datasources/drivers/appserver/appserver/RecordSet.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/appserver/appserver/RecordSet.py  
2005-03-16 22:52:11 UTC (rev 7210)
+++ trunk/gnue-common/src/datasources/drivers/appserver/appserver/RecordSet.py  
2005-03-17 00:18:46 UTC (rev 7211)
@@ -51,63 +51,6 @@
 
 
   # ---------------------------------------------------------------------------
-  # Call a server-side function
-  # ---------------------------------------------------------------------------
-
-  def callFunc (self, methodname, parameters):
-    """
-    This function calls a procedure of the current record (object). All pending
-    changes of the record will be posted first.
-
-    @param methodname: name of the procedure to be called
-    @param parameters: dictionary with parameters for the procedure
-
-    @return: return value of the procedure
-    """
-
-    # Find out the top level record set regarding to master-/detail and call
-    # this recordset's post (). This will do implicit post's on the details
-    current = self._parent
-
-    while current._masterRecordSet is not None:
-      current = current._masterRecordSet._parent
-
-    current.post ()
-
-    result = self.__sm.call (self.__session_id,
-                             self.__classname,
-                             [self._fields ['gnue_id']],
-                             methodname,
-                             parameters) [0]
-
-    self.__updateFields ()
-
-    return result
-
-
-  # ---------------------------------------------------------------------------
-  # Update the current record set
-  # ---------------------------------------------------------------------------
-
-  def updateRecordSet (self):
-    """
-    This function searches for the top level master record and post's it to the
-    backend. Doing this it makes sure all calculated fields have an up to date
-    value. As a side effect this will fire all 'OnChange' triggers bound to the
-    record's class definition.
-    """
-
-    # Find out the top level record set regarding to master-/detail and call
-    # this recordset's post (). This will do implicit post's on the details
-    current = self._parent
-
-    while current._masterRecordSet is not None:
-      current = current._masterRecordSet._parent
-
-    current.post ()
-
-
-  # ---------------------------------------------------------------------------
   # Initialize a record 
   # ---------------------------------------------------------------------------
 
@@ -126,8 +69,12 @@
       if not self._fields.has_key (field.lower ()):
         self._fields [field.lower ()] = None
 
+    # Now get default values from the backend
     self.__updateFields ()
 
+    # They are our initial data, too
+    self._initialData = self._fields.copy ()
+
     # Make sure that the gnue_id is included in the following insert operation.
     # This flag does *not* mark the record itself as dirty, so it won't be
     # included in the next post unless there are further modifications.





reply via email to

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