commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r8458 - trunk/gnue-appserver/src


From: reinhard
Subject: [gnue] r8458 - trunk/gnue-appserver/src
Date: Fri, 12 May 2006 18:55:39 -0500 (CDT)

Author: reinhard
Date: 2006-05-12 18:55:38 -0500 (Fri, 12 May 2006)
New Revision: 8458

Modified:
   trunk/gnue-appserver/src/data.py
Log:
Split up cache.write into cache.write_clean and cache.write_dirty.


Modified: trunk/gnue-appserver/src/data.py
===================================================================
--- trunk/gnue-appserver/src/data.py    2006-05-12 21:34:42 UTC (rev 8457)
+++ trunk/gnue-appserver/src/data.py    2006-05-12 23:55:38 UTC (rev 8458)
@@ -93,20 +93,41 @@
 
 
   # ---------------------------------------------------------------------------
-  # Store data in the cache
+  # Store data in the clean cache
   # ---------------------------------------------------------------------------
 
-  def write (self, table, row, field, value, dirty):
+  def write_clean (self, table, row, data):
     """
-    Write data to the clean or the dirty cache. If data is written to the dirty
-    cache and no atomic operation is started already, this function will start
-    a new atomic operation. 
+    Write data to the clean cache.
 
     A write to the clean cache will be dropped silently if the given field is
     already available in a 'clean version'. This provides transaction integrity
     for backends without transaction support. If a clean write succeeds, the
     state of the given record will be set to 'clean'
 
+    @param table: name of the table
+    @param row: id of the row
+    @param data: (field, value) pairs to write
+    """
+
+    # But be aware not to overwrite an already cached clean value. This is
+    # necessary to keep transaction integrity for backends without
+    # transaction support.
+    r = self.__old.setdefault(table, {}).setdefault(row, {})
+    for (field, value) in data:
+        r.setdefault(field, value)
+    self.__state.setdefault (table + u'-' + row, 'clean')
+
+
+  # ---------------------------------------------------------------------------
+  # Store data in the cache
+  # ---------------------------------------------------------------------------
+
+  def write_dirty (self, table, row, field, value):
+    """
+    Write data to the dirty cache. If no atomic operation is started already,
+    this function will start a new atomic operation. 
+
     A write to the dirty cache will change the record-state to 'commitable', if
     no state information was available before or the state was 'clean'.
     
@@ -114,39 +135,26 @@
     @param row: id of the row
     @param field: name of the field to write data for
     @param value: the value of the field
-    @param dirty: if True, write operation modifies the dirty cache, otherwise
-        it will change the clean cache.
     """
 
     key = table + u'-' + row
 
-    # If we add 'clean' data there is no need to maintain an undo sequence
-    if not dirty:
-      crow = self.__old.setdefault (table, {}).setdefault (row, {})
-      # But be aware not to overwrite an already cached clean value. This is
-      # necessary to keep transaction integrity for backends without
-      # transaction support.
-      if not crow.has_key (field):
-        crow [field] = value
-        self.__state.setdefault (key, 'clean')
+    # If there is no backup of the record right now, we have to create one
+    # before applying any changes.
+    if not self.__backup.has_key (key):
+      rec  = self.__new.get (table) and self.__new [table].get (row)
+      self.__backup [key] = (self.__state.get (key), rec and rec.items ())
 
-    else:
-      # If there is no backup of the record right now, we have to create one
-      # before applying any changes.
-      if not self.__backup.has_key (key):
-        rec  = self.__new.get (table) and self.__new [table].get (row)
-        self.__backup [key] = (self.__state.get (key), rec and rec.items ())
+    self.__new.setdefault (table, {}).setdefault (row, {}) [field] = value
 
-      self.__new.setdefault (table, {}).setdefault (row, {}) [field] = value
+    # After modifying a record update it's state information. If a record is
+    # already initialized or it was a clean record, this modification made it
+    # 'commitable'.
+    state = self.__state.setdefault (key, 'clean')
+    if state in ['initialized', 'clean']:
+      self.__state [key] = 'commitable'
 
-      # After modifying a record update it's state information. If a record is
-      # already initialized or it was a clean record, this modification made it
-      # 'commitable'.
-      state = self.__state.setdefault (key, 'clean')
-      if state in ['initialized', 'clean']:
-        self.__state [key] = 'commitable'
 
-
   # ---------------------------------------------------------------------------
   # Read data from the cache
   # ---------------------------------------------------------------------------
@@ -841,7 +849,7 @@
     # backend.
     if not uncachedFields:
       r = record (self.__cache, self.__connections, self.__database, table, 
row)
-      self.__cache.write (table, row, u'gnue_id', row, dirty = False)
+      self.__cache.write_clean (table, row, [(u'gnue_id', row)])
 
     # otherwise requery the current record for all uncached fields
     else:
@@ -1790,7 +1798,7 @@
     @param value: value of the field
     """
 
-    self.__cache.write (self.__table, self._row, field, value, False)
+    self.__cache.write_clean (self.__table, self._row, [(field, value)])
 
 
   # ---------------------------------------------------------------------------
@@ -1807,12 +1815,13 @@
     @param RecordSet: dictionary like object to retrieve the data from
     """
 
-    for field in fields:
-      f = alias and (alias + '.' + field) or field
+    if alias:
+      self.__cache.write_clean(self.__table, self._row,
+            [(f, RecordSet[alias + u'.' + f]) for f in fields])
+    else:
+      self.__cache.write_clean(self.__table, self._row, RecordSet.iteritems())
 
-      self.__cache.write (self.__table, self._row, field, RecordSet [f], False)
 
-
   # ---------------------------------------------------------------------------
   # Get the value for a field
   # ---------------------------------------------------------------------------
@@ -1857,7 +1866,7 @@
                                      [field])
     if new:
       value = new.get (field)
-      self.__cache.write (self.__table, self._row, field, value, False)
+      self.__cache.write_clean (self.__table, self._row, [(field, value)])
     else:
       value = None
 
@@ -1881,7 +1890,7 @@
 
     checktype (field, unicode)
 
-    self.__cache.write (self.__table, self._row, field, value, True)
+    self.__cache.write_dirty (self.__table, self._row, field, value)
 
 
   # ---------------------------------------------------------------------------





reply via email to

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