commit-gnue
[Top][All Lists]
Advanced

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

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


From: reinhard
Subject: [gnue] r7943 - trunk/gnue-common/src/datasources/drivers/Base
Date: Wed, 28 Sep 2005 12:35:29 -0500 (CDT)

Author: reinhard
Date: 2005-09-21 08:06:48 -0500 (Wed, 21 Sep 2005)
New Revision: 7943

Modified:
   trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py
Log:
Better status handling, going back to 3 variables instead of one status
variable.


Modified: trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py 2005-09-21 
12:05:07 UTC (rev 7942)
+++ trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py 2005-09-21 
13:06:48 UTC (rev 7943)
@@ -137,10 +137,9 @@
     self.__eventController  = eventController
 
     # Record status
-    # New recs:      'empty' -(__setitem__)-> 'inserted' -(delete)-> 'void'
-    # Existing recs: 'clean' -(__setitem__)-> 'modified' -(delete)-> 'deleted'
-    self.__status = 'clean'
-    self.__preDeleteStatus = None
+    self.__inserted = False             # True = new record, False = existing
+    self.__modified = False             # True = dirty, False = clean
+    self.__deleted = False              # True = deleted, False = still alive
 
     # The field values
     self.__fields = {}
@@ -183,7 +182,7 @@
 
       # New record:
       # 1. mark as new
-      self.__status = 'empty'
+      self.__inserted = True
 
       # 2. Get the default values from the backend
       if self.__connection:
@@ -256,11 +255,8 @@
     self.__fields [fieldname] = value
     self.__modifiedFlags [fieldname] = True
     if not self.__initializing and fieldname in self.__boundFields:
-      if self.__status in ['empty', 'clean']:
-        if self.__status == 'empty':
-          self.__status = 'inserted'
-        elif self.__status == 'clean':
-          self.__status = 'modified'
+      if not self.__modified:
+        self.__modified = True
         self.__dispatchEvent ('dsRecordTouched')
 
   # ---------------------------------------------------------------------------
@@ -354,13 +350,9 @@
     if self.__readonly:
       raise Exceptions.ReadOnlyDeleteError
 
-    if self.__status in ['empty', 'inserted']:
-      self.__preDeleteStatus = self.__status
-      self.__status = 'void'
-    elif self.__status in ['clean', 'modified']:
-      self.__preDeleteStatus = self.__status
-      self.__status = 'deleted'
+    self.__deleted = True
 
+
   # ---------------------------------------------------------------------------
   # Remove the delete mark from the record
   # ---------------------------------------------------------------------------
@@ -378,10 +370,10 @@
     if self.__readonly:
       raise Exceptions.ReadOnlyDeleteError
 
-    assert self.__status in ['void','deleted']
-    self.__status = self.__preDeleteStatus
-    self.__preDeleteStatus = None
+    assert self.__deleted
+    self.__deleted = False
   
+
   # ---------------------------------------------------------------------------
   # Call backend code
   # ---------------------------------------------------------------------------
@@ -429,7 +421,8 @@
     been changed nor has a detail for this record been inserted with a status
     other than empty.
     """
-    return self.__status == 'empty' and not self.__hasPendingChildren ()
+    return self.__inserted and not self.__modified and not self.__deleted \
+        and not self.__hasPendingChildren ()
 
   # ---------------------------------------------------------------------------
 
@@ -440,8 +433,9 @@
 
     Records with this status will be inserted into the database on post.
     """
-    return self.__status == 'inserted' or \
-        (self.__status == 'empty' and self.__hasPendingChildren ())
+    return self.__inserted \
+        and (self.__modified or self.__hasPendingChildren ()) \
+        and not self.__deleted
 
   # ---------------------------------------------------------------------------
 
@@ -451,8 +445,9 @@
 
     Records with this status will be updated in the database on post.
     """
-    return self.__status == 'modified' or \
-        (self.__status == 'clean' and self.__hasPendingChildren ())
+    return not self.__inserted \
+        and (self.__modified or self.__hasPendingChildren ()) \
+        and not self.__deleted
 
   # ---------------------------------------------------------------------------
 
@@ -462,7 +457,7 @@
 
     Records with this status will be deleted in the database on post.
     """
-    return self.__status == 'deleted'
+    return not self.__inserted and self.__deleted
 
   # ---------------------------------------------------------------------------
 
@@ -473,10 +468,11 @@
 
     The result is True if either isInserted, isModified, or isDeleted is True.
     """
-    # ... but we check __status instead of isXxxx to not have to evaluate
+    # ... but we check status fields 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 ())
+    return ((self.__modified or self.__hasPendingChildren ()) \
+            and not self.__deleted) \
+        or (not self.__inserted and self.__deleted)
 
   # ---------------------------------------------------------------------------
 
@@ -521,20 +517,17 @@
     if self.__requeryStatus == 'posted':
       # record has been written to the backend - everything is clean now
       self.__fields.update (data)
-      self.__status = 'clean'
+      self.__inserted = False
+      self.__modified = False
       self.__modifiedFlags = {}
       self.__requeryStatus = None
 
-    elif self.__status == 'clean':
-      # record is clean anyway
-      self.__fields.update (data)
-
     else:
-      # record has unsaved changes because the last _post to this record (or a
-      # preceding record) failed - we have to be cautious not to overwrite
-      # changes the user has done
-      for (fieldname, value) in data:
-        if not self.__modifiedFlags [fieldname]:
+      # record may have unsaved changes because the last _post to this record
+      # (or a preceding record) failed - we have to be cautious not to
+      # overwrite changes the user has done
+      for (fieldname, value) in data.items ():
+        if not self.__modifiedFlags.has_key (fieldname):
           self.__fields [fieldname] = value
 
 
@@ -559,9 +552,9 @@
           dataSource._activateResultSet (resultset)
           continue
         
-      # If this record is empty anyway, it can't have any detail records, so
+      # If this record is new, it can't have any detail records yet anyway, so
       # create empty detail result sets.  Query the matching details otherwise.
-      if self.__status == 'empty':
+      if self.__inserted:
         resultset = dataSource.createEmptyResultSet (masterRecord = self)
       else:
         resultset = dataSource.createResultSet (masterRecord = self)
@@ -593,21 +586,18 @@
     if not self.isPending ():
       return
 
-    # Save the initial status so we know if any triggers changed us
-    status = self.__status
-
     # Call the hooks for commit-level hooks
     # A trigger code could change the status from empty/inserted/modified to
     # deleted. In that case, both triggers would be called.
-    if self.__status in ['empty', 'inserted']:
+    if self.__inserted:
       self.__dispatchEvent ('dsCommitInsert')
-    if self.__status == 'modified':
+    elif self.__modified:
       self.__dispatchEvent ('dsCommitUpdate')
-    if self.__status == 'deleted':
+    if self.__deleted:
       self.__dispatchEvent ('dsCommitDelete')
 
     # Check for empty primary key and set with the sequence value if so
-    if self.__status in ['empty', 'inserted']:
+    if self.__inserted:
       if len (self.__primarykeyFields) == 1 and \
           self [self.__primarykeyFields [0]] is None and \
           self.__primarykeySeq is not None and \
@@ -617,15 +607,15 @@
 
     # If we have a connection (i.e. we aren't static or unbound), do the post
     if self.__connection is not None:
-      if self.__status == 'deleted':
+      if self.__deleted:
         self.__connection.delete (self.__tablename, self.__wherefields ())
-      elif self.__status in ['empty', 'inserted', 'modified']:
+      elif self.__inserted or self.__modified:
         modifiedFields = {}
         for field in self.__boundFields:
           if self.__modifiedFlags.has_key (field):
             modifiedFields [field] = self.__fields [field]
 
-        if self.__status in ['empty', 'inserted']:
+        if self.__inserted:
           rowid = self.__connection.insert (self.__tablename, modifiedFields)
           if self.__rowidField:
             self.__fields [self.__rowidField] = rowid
@@ -670,7 +660,8 @@
       return
 
     # The record is now "clean" again
-    self.__status = 'clean'
+    self.__inserted = False
+    self.__modified = False
     self.__modifiedFlags = {}
     self.__initialData = self.__fields.copy ()
     if commit:





reply via email to

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