commit-gnue
[Top][All Lists]
Advanced

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

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


From: reinhard
Subject: [gnue] r7354 - trunk/gnue-common/src/datasources/drivers/Base
Date: Tue, 12 Apr 2005 08:05:32 -0500 (CDT)

Author: reinhard
Date: 2005-04-12 08:05:31 -0500 (Tue, 12 Apr 2005)
New Revision: 7354

Modified:
   trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py
Log:
Handle status with a single variable instead of four variables.


Modified: trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py 2005-04-12 
09:41:35 UTC (rev 7353)
+++ trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py 2005-04-12 
13:05:31 UTC (rev 7354)
@@ -47,12 +47,10 @@
     self.__rowidField       = rowidField        # Field name of the rowid
     self.__primarykeyFields = primarykeyFields  # Field names of the primarykey
 
-    # Status information - FIXME: should be private, others should use
-    # isEmpty(), isInserted(), isModified() and isDeleted()
-    self._emptyFlag  = False
-    self._insertFlag = False
-    self._updateFlag = False
-    self._deleteFlag = False
+    # Record status
+    # New records:      'empty' -(setField)-> 'inserted' -(delete)-> 'void'
+    # Existing records: 'clean' -(setField)-> 'modified' -(delete)-> 'deleted'
+    self.__status = 'clean'
 
     # The ResultSet this RecordSet is a part of - FIXME: should be private
     self._parent = parent
@@ -85,8 +83,7 @@
 
       # New record:
       # 1. mark as new
-      self._insertFlag = True
-      self._emptyFlag  = True
+      self.__status = 'empty'
 
       do = self._parent._dataObject
 
@@ -176,10 +173,11 @@
 
     self.__setField (fieldname, value)
     if self._parent.isFieldBound (fieldname):
-      self._emptyFlag = False
-      # On first touch of the record, call _onModification trigger
-      if not self._updateFlag:
-        self._updateFlag = True
+      if self.__status in ['empty', 'clean']:
+        if self.__status == 'empty':
+          self.__status = 'inserted'
+        elif self.__status == 'clean':
+          self.__status = 'modified'
         if hasattr (do, '_dataSource'):
           do._dataSource._onModification (self)
 
@@ -221,10 +219,13 @@
       # Provide better feedback??
       tmsg = _("Attempted to delete from a read only datasource")
       raise Exceptions.ReadOnlyError, tmsg
-    else:
-      self._deleteFlag = True
 
+    if self.__status in ['empty', 'inserted']:
+      self.__status = 'void'
+    elif self.__status in ['clean', 'modified']:
+      self.__status = 'deleted'
 
+
   # ---------------------------------------------------------------------------
   # Status of this record
   # ---------------------------------------------------------------------------
@@ -237,15 +238,7 @@
     been changed nor has a detail for this record been inserted with a status
     other than empty.
     """
-    if self._emptyFlag:
-      result = True
-      for child in self._cachedDetailResultSets.values ():
-        if child.isPending ():
-          result = False
-          break
-    else:
-      result = False
-    return result
+    return self.__status == 'empty' and not self.__hasPendingChildren ()
 
   # ---------------------------------------------------------------------------
 
@@ -256,7 +249,8 @@
     
     Records with this status will be inserted into the database on post.
     """
-    return self._insertFlag and not self._deleteFlag and not self.isEmpty ()
+    return self.__status == 'inserted' or \
+        (self.__status == 'empty' and self.__hasPendingChildren ())
 
   # ---------------------------------------------------------------------------
 
@@ -266,14 +260,8 @@
 
     Records with this status will be updated in the database on post.
     """
-    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
+    return self.__status == 'modified' or \
+        (self.__status == 'clean' and self.__hasPendingChildren ())
 
   # ---------------------------------------------------------------------------
 
@@ -283,7 +271,7 @@
 
     Records with this status will be deleted in the database on post.
     """
-    return self._deleteFlag and not self._insertFlag
+    return self.__status == 'deleted'
 
   # ---------------------------------------------------------------------------
 
@@ -294,9 +282,21 @@
     
     The result is True if either isInserted, isModified, or isDeleted is True.
     """
-    return self.isInserted () or self.isModified () or self.isDeleted ()
+    # ... but we check __status instead of isXxxx to not have to evaluate
+    # __hasPendingChildren several times.
+    return self.__status in ['inserted', 'modified', 'deleted'] or \
+        (self.__status in ['empty', 'clean'] and self.__hasPendingChildren ())
 
+  # ---------------------------------------------------------------------------
 
+  def __hasPendingChildren (self):
+
+    for child in self._cachedDetailResultSets.values ():
+      if child.isPending ():
+        return True
+    return False
+
+
   # ---------------------------------------------------------------------------
   # Fields to be used in WHERE clauses for UPDATE and DELETE.
   # ---------------------------------------------------------------------------
@@ -364,29 +364,29 @@
     self.__setMasterLink ()
 
     # Save the initial status so we know if any triggers changed us
-    status = (self._insertFlag, self._deleteFlag, self._updateFlag)
+    status = self.__status
 
     # Call the hooks for commit-level hooks
     if hasattr(self._parent._dataObject,'_dataSource'):
-      if self._insertFlag and not self._deleteFlag:
+      if self.__status in ['empty', 'inserted']:
         self._parent._dataObject._dataSource._beforeCommitInsert(self)
-      elif self._deleteFlag and not self._insertFlag:
-        self._parent._dataObject._dataSource._beforeCommitDelete(self)
-      elif self._updateFlag:
+      elif self.__status in ['clean', 'modified']:
         self._parent._dataObject._dataSource._beforeCommitUpdate(self)
+      elif self.__status == 'deleted':
+        self._parent._dataObject._dataSource._beforeCommitDelete(self)
 
     #
     # If the record status changed while we were doing the triggers,
     # start from the beginning and run the triggers again.
     #
-    if status != (self._insertFlag, self._deleteFlag, self._updateFlag):
+    if status != self.__status:
       self.post(recordNumber)
       return
 
     #
     # Check for empty primary key and set with the sequence value if so
     #
-    if self.isInserted():
+    if self.__status in ['empty', 'inserted']:
       do = self._parent._dataObject
       if hasattr(do,'primarykey') and hasattr(do,'primarykeyseq'):
         if do.primarykey and do.primarykeyseq and ',' not in do.primarykey and 
\
@@ -399,16 +399,16 @@
       do = self._parent._dataObject
       gDebug (8, 'Posting datasource %s' % do.name)
 
-      if self._deleteFlag:
+      if self.__status == 'deleted':
         do._connection.delete (do.table, self.__wherefields (), recordNumber)
 
-      elif self._insertFlag or self._updateFlag:
+      else:
         modifiedFields = {}
         for field in self.__modifiedFlags.keys ():
           if self._parent.isFieldBound (field):
             modifiedFields [field] = self.__fields [field]
 
-        if self._insertFlag:
+        if self.__status in ['empty', 'inserted']:
           rowid = do._connection.insert (do.table, modifiedFields, 
recordNumber)
           if self.__rowidField:
             self.__fields [self.__rowidField] = rowid
@@ -423,8 +423,7 @@
                                  modifiedFields, recordNumber)
 
         # The record is now "clean" again
-        self._insertFlag    = False
-        self._updateFlag    = False
+        self.__status        = 'clean'
         self.__modifiedFlags = {}
         self.__initialData   = self.__fields.copy ()
 





reply via email to

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