commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r7228 - trunk/gnue-common/src/datasources/drivers/Base


From: reinhard
Subject: [gnue] r7228 - trunk/gnue-common/src/datasources/drivers/Base
Date: Sat, 19 Mar 2005 17:09:36 -0600 (CST)

Author: reinhard
Date: 2005-03-19 17:09:35 -0600 (Sat, 19 Mar 2005)
New Revision: 7228

Modified:
   trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py
   trunk/gnue-common/src/datasources/drivers/Base/ResultSet.py
Log:
Do the requery after the commit, so changes done in the backend through the
commit (e.g. in appserver's OnValidate) become visible.


Modified: trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py 2005-03-19 
18:49:47 UTC (rev 7227)
+++ trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py 2005-03-19 
23:09:35 UTC (rev 7228)
@@ -96,7 +96,7 @@
       # 4. Query current data from the backend.  The requery function only does
       #    something if the primary key was initialized above.  This is used
       #    for appserver to retrieve the result of OnInit.
-      self.__requery ()
+      self.requery ()
 
       # 5. Get default values from DataSource.  This has to be done at the very
       #    end, as these changes remain local until the first post.
@@ -259,7 +259,14 @@
 
     Records with this status will be updated in the database on post.
     """
-    return self._updateFlag and not self._insertFlag and not self._deleteFlag
+    if self._insertFlag or self._deleteFlag:
+      return False
+    if self._updateFlag:
+      return True
+    for child in self._cachedDetailResultSets.values ():
+      if child.isPending ():
+        return True
+    return False
 
   # ---------------------------------------------------------------------------
 
@@ -303,33 +310,6 @@
 
 
   # ---------------------------------------------------------------------------
-  # Requery the record data from the backend
-  # ---------------------------------------------------------------------------
-
-  def __requery (self):
-    """
-    Requery this record to reflect changes done by the backend.
-
-    This method may not be called if the record has unsaved changes; they would
-    get lost!
-
-    This method does nothing if no primary key is available.
-    """
-
-    do = self._parent._dataObject
-
-    if self._initialData.has_key (do._primaryIdField) and \
-       self._initialData [do._primaryIdField] is not None:
-
-      fields = [field for field in self._fields.keys ()
-                if self._parent.isFieldBound (field)]
-      newfields = do._connection.requery (do.table, self.__wherefields (),
-                                          fields)
-      self._initialData.update (newfields)
-      self._fields.update (newfields)
-
-
-  # ---------------------------------------------------------------------------
   # Post changes to database
   # ---------------------------------------------------------------------------
 
@@ -404,12 +384,39 @@
 
       child.post (foreign_keys = fk)
 
-    # Now, requery, as the posting of the record and/or of the details could
-    # have changed something
-    if not deleting:
-      self.__requery ()
 
+  # ---------------------------------------------------------------------------
+  # Requery the record data from the backend
+  # ---------------------------------------------------------------------------
 
+  def requery (self):
+    """
+    Requery this record to reflect changes done by the backend.
+
+    This method may not be called if the record has unsaved changes; they would
+    get lost!
+
+    This method does nothing if no primary key is available.
+    """
+
+    do = self._parent._dataObject
+
+    # Requery detail resultsets
+    for child in (self._cachedDetailResultSets.values ()):
+      child.requery ()
+
+    # Now requery ourselves
+    if self._initialData.has_key (do._primaryIdField) and \
+       self._initialData [do._primaryIdField] is not None:
+
+      fields = [field for field in self._fields.keys ()
+                if self._parent.isFieldBound (field)]
+      newfields = do._connection.requery (do.table, self.__wherefields (),
+                                          fields)
+      self._initialData.update (newfields)
+      self._fields.update (newfields)
+
+
   # ---------------------------------------------------------------------------
   # Post and requery the top level master record
   # ---------------------------------------------------------------------------
@@ -428,7 +435,7 @@
     if self._parent._masterRecordSet:
       self._parent._masterRecordSet.__requery_master ()
     else:
-      self.__requery ()
+      self.requery ()
 
 
   # ---------------------------------------------------------------------------
@@ -526,7 +533,7 @@
     if hasattr (do, 'table'):
       return "<RecordSet for %s>" % do.table
     else:
-      return "<NIL-Table RecordSet>"
+      return "<Unbound/Static RecordSet>"
 
   # ---------------------------------------------------------------------------
   # Virtual methods to be overwritten by the drivers

Modified: trunk/gnue-common/src/datasources/drivers/Base/ResultSet.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/Base/ResultSet.py 2005-03-19 
18:49:47 UTC (rev 7227)
+++ trunk/gnue-common/src/datasources/drivers/Base/ResultSet.py 2005-03-19 
23:09:35 UTC (rev 7228)
@@ -58,6 +58,8 @@
 
      self.__listeners = []
 
+     self.__recordsToRequery = []
+
      self.current = None
 
      if masterRecordSet:
@@ -366,8 +368,21 @@
     global postingRecordset
     return postingRecordset
 
-  # Post changes to the database
-  def post(self, foreign_keys={}):
+
+  # ---------------------------------------------------------------------------
+  # Post changes to the backend
+  # ---------------------------------------------------------------------------
+
+  def post (self, foreign_keys = {}):
+
+    """
+    Post all local changes to the backend.
+
+    This method leaves the ResultSet in an incomplete state.  After every call
+    to post, L{requery} must be called.  If the operation should be committed,
+    the L{Connection.commit} method can be called between post and requery.
+    """
+
     global postingRecordset
     # post our changes
     recordPosition = 0
@@ -397,6 +412,9 @@
       else:
         recordPosition += 1
 
+      if self._postingRecord.isInserted () or self._postingRecord.isModified 
():
+        self.__recordsToRequery.append (self._postingRecord)
+
       if self._postingRecord.isPending ():
         self._postingRecord.post (recordPosition)
 
@@ -408,9 +426,26 @@
       else:
         self._currentRecord = -1
 
-    # Now bring everything else up to date again
+  # ---------------------------------------------------------------------------
+  # Sync resultset with backend, and sync listeners with resultset
+  # ---------------------------------------------------------------------------
+
+  def requery (self):
+
+    """
+    Synchronize everything after a call to L{post}.
+
+    This method must be called after each call to the L{post} method. If the
+    operation should be committed, the L{Connection.commit} method can be
+    called between post and requery.
+    """
+
+    for record in self.__recordsToRequery:
+      record.requery ()
+    self.__recordsToRequery = []
     self.__sync ()
 
+
   def notifyDetailObjects(self):
     gDebug (8,'Master record changed; Notifying Detail Objects')
     for detail in self._dataObject._detailObjects:
@@ -468,7 +503,7 @@
     if hasattr (do, 'table'):
       return "<ResultSet for %s>" % do.table
     else:
-      return "<NIL-Table RecordSet>"
+      return "<Unbound/Static ResultSet>"
 
 
   ###





reply via email to

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