commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r7682 - in trunk: gnue-common/src/datasources gnue-common/src/dat


From: reinhard
Subject: [gnue] r7682 - in trunk: gnue-common/src/datasources gnue-common/src/datasources/drivers/Base gnue-common/src/datasources/drivers/DBSIG2 gnue-common/src/datasources/drivers/file gnue-common/src/datasources/drivers/other gnue-forms/src/GFObjects
Date: Mon, 4 Jul 2005 17:35:14 -0500 (CDT)

Author: reinhard
Date: 2005-07-04 17:35:12 -0500 (Mon, 04 Jul 2005)
New Revision: 7682

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/Base/ResultSet.py
   trunk/gnue-common/src/datasources/drivers/DBSIG2/Connection.py
   trunk/gnue-common/src/datasources/drivers/file/inifile.py
   trunk/gnue-common/src/datasources/drivers/other/appserver.py
   trunk/gnue-forms/src/GFObjects/GFBlock.py
   trunk/gnue-forms/src/GFObjects/GFField.py
Log:
Move the cursor through the records as we post changes to the backend, so that
all commit triggers see the posting record as the current record. Also, after
an exception on writing to the backend, the record pointer remains on the
record that caused the error, helping the user to identify the faulty record.


Modified: trunk/gnue-common/src/datasources/GDataSource.py
===================================================================
--- trunk/gnue-common/src/datasources/GDataSource.py    2005-07-04 22:01:54 UTC 
(rev 7681)
+++ trunk/gnue-common/src/datasources/GDataSource.py    2005-07-04 22:35:12 UTC 
(rev 7682)
@@ -53,16 +53,18 @@
       "requery" option of this datasource is in use.
     - dsCursorMoved (parameters: none) whenever the cursor in the current
       ResultSet is moved, i.e. a different record becomes the current record.
-    - dsRecordLoaded (parameters: record) whenever a record has been loaded
-      from the backend.
-    - dsRecordTouchend (parameters: record) whenever a record is modified for
-      the first time since it was loaded from the backend or last saved.
-    - dsCommitInsert (parameters: record) whenever a record is about to be
-      inserted in the backend due to a commit operation.
-    - dsCommitUpdate (parameters: record) whenever a record is about to be
-      updated in the backend due to a commit operation.
-    - dsCommitDelete (parameters: record) whenever a record is about to be
-      deleted in the backend due to a commit operation.
+    - dsRecordLoaded whenever a record has been loaded from the backend.
+    - dsRecordTouchend whenever a record is modified for the first time since
+      it was loaded from the backend or last saved.
+    - dsCommitInsert whenever a record is about to be inserted in the backend
+      due to a commit operation. The record in question will be the current
+      record of the datasource at the time this trigger is run.
+    - dsCommitUpdate whenever a record is about to be updated in the backend
+      due to a commit operation. The record in question will be the current
+      record of the datasource at the time this trigger is run.
+    - dsCommitDelete whenever a record is about to be deleted in the backend
+      due to a commit operation. The record in question will be the current
+      record of the datasource at the time this trigger is run.
   """
 
   # 
--------------------------------------------------------------------------- 
@@ -164,7 +166,7 @@
   # ---------------------------------------------------------------------------
 
   def __trigger_delete (self):
-    (self._currentResultSet.getPostingRecordset ()).delete ()
+    self._currentResultSet.current.delete ()
 
   # ---------------------------------------------------------------------------
 

Modified: trunk/gnue-common/src/datasources/drivers/Base/Connection.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/Base/Connection.py        
2005-07-04 22:01:54 UTC (rev 7681)
+++ trunk/gnue-common/src/datasources/drivers/Base/Connection.py        
2005-07-04 22:35:12 UTC (rev 7682)
@@ -171,19 +171,18 @@
   # Insert a new record in the backend
   # ---------------------------------------------------------------------------
 
-  def insert (self, table, newfields, recno):
+  def insert (self, table, newfields):
     """
     Insert a new record in the backend.
 
     @param table: Table name.
     @param newfields: Fieldname/Value dictionary of data to insert.
-    @param recno: Record number to be used in error messages.
     @return: The rowid of the newly inserted record, or None if no rowid's are
     supported.
     """
 
     gEnter (8)
-    rowid = self._insert_ (table, newfields, recno)
+    rowid = self._insert_ (table, newfields)
     self.__pending = True
     return gLeave (8, rowid)
 
@@ -192,7 +191,7 @@
   # Update an existing record in the backend
   # ---------------------------------------------------------------------------
 
-  def update (self, table, oldfields, newfields, recno):
+  def update (self, table, oldfields, newfields):
     """
     Update an existing record in the backend.
 
@@ -200,11 +199,10 @@
     @param oldfields: Fieldname/Value dictionary of fields to find the existing
       record (aka where-clause).
     @param newfields: Fieldname/Value dictionary of data to change.
-    @param recno: Record number to be used in error messages.
     """
 
     gEnter (8)
-    self._update_ (table, oldfields, newfields, recno)
+    self._update_ (table, oldfields, newfields)
     self.__pending = True
     gLeave (8)
 
@@ -213,18 +211,17 @@
   # Delete a record from the backend
   # ---------------------------------------------------------------------------
 
-  def delete (self, table, oldfields, recno):
+  def delete (self, table, oldfields):
     """
     Delete a record from the backend.
 
     @param table: Table name.
     @param oldfields: Fieldname/Value dictionary of fields to find the existing
       record (aka where-clause).
-    @param recno: Record number to be used in error messages.
     """
 
     gEnter (8)
-    self._delete_ (table, oldfields, recno)
+    self._delete_ (table, oldfields)
     self.__pending = True
     gLeave (8)
 
@@ -454,7 +451,7 @@
 
   # ---------------------------------------------------------------------------
 
-  def _insert_ (self, table, newfields, recno):
+  def _insert_ (self, table, newfields):
     """
     Insert a new record in the backend (to be implemented by descendants).
 
@@ -464,7 +461,6 @@
 
     @param table: Table name.
     @param newfields: Fieldname/Value dictionary of data to insert.
-    @param recno: Record number to be used in error messages.
     @return: The rowid of the newly inserted record, or None if no rowid's are
     supported.
     """
@@ -472,7 +468,7 @@
 
   # ---------------------------------------------------------------------------
 
-  def _update_ (self, table, oldfields, newfields, recno):
+  def _update_ (self, table, oldfields, newfields):
     """
     Update an existing record in the backend.
 
@@ -483,13 +479,12 @@
     @param oldfields: Fieldname/Value dictionary of fields to find the existing
       record (aka where-clause)
     @param newfields: Fieldname/Value dictionary of data to change.
-    @param recno: Record number to be used in error messages.
     """
     pass
 
   # ---------------------------------------------------------------------------
 
-  def _delete_ (self, table, oldfields, recno):
+  def _delete_ (self, table, oldfields):
     """
     Delete a record from the backend (to be implemented by descendants).
 
@@ -499,7 +494,6 @@
     @param table: Table name.
     @param oldfields: Fieldname/Value dictionary of fields to find the existing
       record (aka where-clause)
-    @param recno: Record number to be used in error messages.
     """
     pass
 

Modified: trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py 2005-07-04 
22:01:54 UTC (rev 7681)
+++ trunk/gnue-common/src/datasources/drivers/Base/RecordSet.py 2005-07-04 
22:35:12 UTC (rev 7682)
@@ -165,7 +165,7 @@
       # Set the current state of all fields as given in the parameter
       self.__fields = self.__initialData.copy ()
       if self.__eventController is not None:
-        self.__eventController.dispatchEvent ('dsRecordLoaded', record = self)
+        self.__eventController.dispatchEvent ('dsRecordLoaded')
 
     else:
 
@@ -243,7 +243,7 @@
         elif self.__status == 'clean':
           self.__status = 'modified'
         if self.__eventController is not None:
-          self.__eventController.dispatchEvent ('dsRecordTouched', record=self)
+          self.__eventController.dispatchEvent ('dsRecordTouched')
 
   # ---------------------------------------------------------------------------
 
@@ -504,14 +504,12 @@
   # Post changes to database
   # ---------------------------------------------------------------------------
 
-  def _post (self, recordNumber = None):
+  def _post (self):
     """
     Write all local changes for this record to the backend, as
     well as for all detail records where this record is the master.
 
     This is called by L{ResultSet.post} for each record with pending changes.
-
-    @param recordNumber: Record number to be used in error messages.
     """
 
     # Just to make sure - you never know who calls us...
@@ -526,11 +524,11 @@
       # 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']:
-        self.__eventController.dispatchEvent ('dsCommitInsert', record = self)
+        self.__eventController.dispatchEvent ('dsCommitInsert')
       if self.__status == 'modified':
-        self.__eventController.dispatchEvent ('dsCommitUpdate', record = self)
+        self.__eventController.dispatchEvent ('dsCommitUpdate')
       if self.__status == 'deleted':
-        self.__eventController.dispatchEvent ('dsCommitDelete', record = self)
+        self.__eventController.dispatchEvent ('dsCommitDelete')
 
     # Check for empty primary key and set with the sequence value if so
     if self.__status in ['empty', 'inserted']:
@@ -544,8 +542,7 @@
     # 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':
-        self.__connection.delete (self.__tablename, self.__wherefields (),
-            recordNumber)
+        self.__connection.delete (self.__tablename, self.__wherefields ())
       elif self.__status in ['empty', 'inserted', 'modified']:
         modifiedFields = {}
         for field in self.__boundFields:
@@ -553,8 +550,7 @@
             modifiedFields [field] = self.__fields [field]
 
         if self.__status in ['empty', 'inserted']:
-          rowid = self.__connection.insert (self.__tablename, modifiedFields,
-              recordNumber)
+          rowid = self.__connection.insert (self.__tablename, modifiedFields)
           if self.__rowidField:
             self.__fields [self.__rowidField] = rowid
             self.__initialData [self.__rowidField] = rowid
@@ -565,7 +561,7 @@
 
         else:
           self.__connection.update (self.__tablename, self.__wherefields (),
-              modifiedFields, recordNumber)
+              modifiedFields)
 
         # The record is now "clean" again
         self.__status        = 'clean'

Modified: trunk/gnue-common/src/datasources/drivers/Base/ResultSet.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/Base/ResultSet.py 2005-07-04 
22:01:54 UTC (rev 7681)
+++ trunk/gnue-common/src/datasources/drivers/Base/ResultSet.py 2005-07-04 
22:35:12 UTC (rev 7682)
@@ -633,20 +633,10 @@
 
 
   # ---------------------------------------------------------------------------
-  # TODO: What's this??
-  # ---------------------------------------------------------------------------
-
-  def getPostingRecordset (self):
-    global postingRecordset
-    return postingRecordset
-
-
-  # ---------------------------------------------------------------------------
   # Post changes to the backend
   # ---------------------------------------------------------------------------
 
   def post (self, fkData = {}):
-
     """
     Post all local changes to the backend.
 
@@ -658,37 +648,56 @@
       internally for detail resultsets in a master/detail relationship.
     """
 
-    global postingRecordset
+    # save current record position
+    currentRecord = self.__currentRecord
 
     # post our changes
-    recordPosition = 0
-    while recordPosition < len (self.__cachedRecords):
-      record = self.__cachedRecords [recordPosition]
-      postingRecordset = record
+    try:
+      # we move the cursor along while we post, so triggers see the posting
+      # record as the current record
+      self.__currentRecord = 0
+      while self.__currentRecord < len (self.__cachedRecords):
+        self.current = self.__cachedRecords [self.__currentRecord]
+        if self.current.isPending ():
+          self.current._activate ()
 
-      if (record.isEmpty () or record.isDeleted ()) \
-          and self.__connection is not None:
-        # Adjust the current record if a preceding record or the current record
-        # is deleted
-        self.__removeRecord (recordPosition)
-      else:
-        recordPosition += 1
+          if self.current.isInserted () or self.current.isModified ():
+            self.__recordsToRequery.append (self.current)
 
-      if record.isInserted () or record.isModified ():
-        self.__recordsToRequery.append (record)
+          # Set the foreign keys for inserted records in case the master 
changed
+          # its primary key in a commit trigger
+          if self.current.isInserted ():
+            for (fieldname, value) in fkData.items ():
+              self.current [fieldname] = value
 
-      # Set the foreign keys for inserted records in case the master changed
-      # its primary key in a commit trigger
-      if record.isInserted ():
-        for (fieldname, value) in fkData.items ():
-          record [fieldname] = value
+          wasDeleted = ((self.current.isEmpty () or self.current.isDeleted ()) 
\
+              and self.__connection is not None)
 
-      if record.isPending ():
-        record._post (recordPosition)
+          self.current._post ()
 
-    # Move to record 0 if all preceding records were deleted
-    # (or set to -1 if all records were deleted)
-    if self.__currentRecord < 0:
+          if wasDeleted:
+            # Adjust the current record if a preceding record or the current
+            # record is deleted
+            self.__removeRecord (self.__currentRecord)
+            if index <= currentRecord:
+              currentRecord -= 1
+          else:
+            self.__currentRecord += 1
+        else:
+          self.__currentRecord += 1
+
+    except:
+      # If any error happened on writing to the backend, move the UI to the
+      # record that caused the error
+      self.__sync ()
+      raise
+
+    # Restore current record position
+    if currentRecord >= 0:
+      self.__currentRecord = currentRecord
+    else:
+      # Move to record 0 if all preceding records were deleted
+      # (or set to -1 if all records were deleted)
       if len(self.__cachedRecords):
         self.__currentRecord = 0
       else:
@@ -700,7 +709,6 @@
   # ---------------------------------------------------------------------------
 
   def requery (self):
-
     """
     Synchronize everything after a call to L{post}.
 
@@ -763,6 +771,8 @@
       else:
         # Not found in newData - delete it
         self.__removeRecord (index)
+        if index <= self.__currentRecord:
+          self.__currentRecord -= 1
 
     # Add the rest of newData - it has been inserted
     # Convert the multi dimensional dictionary into a list
@@ -810,8 +820,6 @@
 
     self.__cachedRecords.pop (index)
     self.__recordCount -= 1
-    if index <= self.__currentRecord:
-      self.__currentRecord -= 1
 
 
   # ---------------------------------------------------------------------------
@@ -863,7 +871,3 @@
     _query_ functions.
     """
     pass
-
-
-# TODO: wtf?
-postingRecordset = None

Modified: trunk/gnue-common/src/datasources/drivers/DBSIG2/Connection.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/DBSIG2/Connection.py      
2005-07-04 22:01:54 UTC (rev 7681)
+++ trunk/gnue-common/src/datasources/drivers/DBSIG2/Connection.py      
2005-07-04 22:35:12 UTC (rev 7682)
@@ -398,17 +398,12 @@
   # Execute an insert, update, or delete statement
   # ---------------------------------------------------------------------------
 
-  def __execute (self, statement, parameters, recno):
+  def __execute (self, statement, parameters):
 
     try:
       return self.sql0 (statement, parameters)
     except self._driver.DatabaseError:
-      if recno:
-        raise Exceptions.ConnectionError, \
-         "\nERROR POSTING RECORD # %s\n\n%s" % (recno,
-                                                errors.getException () [2])
-      else:
-        raise Exceptions.ConnectionError, errors.getException () [2]
+      raise Exceptions.ConnectionError, errors.getException () [2]
 
 
   # ---------------------------------------------------------------------------
@@ -499,7 +494,7 @@
 
   # ---------------------------------------------------------------------------
 
-  def _insert_ (self, table, newfields, recno):
+  def _insert_ (self, table, newfields):
     fields = []
     values = []
     parameters = {}
@@ -510,11 +505,11 @@
       parameters [key] = value
     statement = "INSERT INTO %s (%s) VALUES (%s)" % (table, ', '.join (fields),
         ', '.join (values))
-    return self.__execute (statement, parameters, recno)
+    return self.__execute (statement, parameters)
 
   # ---------------------------------------------------------------------------
 
-  def _update_ (self, table, oldfields, newfields, recno):
+  def _update_ (self, table, oldfields, newfields):
     (where, parameters) = self.__where (oldfields)
     updates = []
     for (field, value) in newfields.items ():
@@ -523,14 +518,14 @@
       parameters [key] = value
     statement = "UPDATE %s SET %s WHERE %s" % (table, ', '.join (updates),
         where)
-    self.__execute (statement, parameters, recno)
+    self.__execute (statement, parameters)
 
   # ---------------------------------------------------------------------------
 
-  def _delete_ (self, table, oldfields, recno):
+  def _delete_ (self, table, oldfields):
     (where, parameters) = self.__where (oldfields)
     statement = 'DELETE FROM %s WHERE %s' % (table, where)
-    self.__execute (statement, parameters, recno)
+    self.__execute (statement, parameters)
 
   # ---------------------------------------------------------------------------
 

Modified: trunk/gnue-common/src/datasources/drivers/file/inifile.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/file/inifile.py   2005-07-04 
22:01:54 UTC (rev 7681)
+++ trunk/gnue-common/src/datasources/drivers/file/inifile.py   2005-07-04 
22:35:12 UTC (rev 7682)
@@ -178,7 +178,7 @@
   # Insert new record
   # ---------------------------------------------------------------------------
 
-  def _insert_ (self, table, newfields, recno):
+  def _insert_ (self, table, newfields):
 
     parser = self.__getParser (self.getFilename (table), table)
 
@@ -201,7 +201,7 @@
   # Update existing record
   # ---------------------------------------------------------------------------
 
-  def _update_ (self, table, oldfields, newfields, recno):
+  def _update_ (self, table, oldfields, newfields):
 
     parser = self.__getParser (self.getFilename (table), table)
 
@@ -236,7 +236,7 @@
   # Delete record
   # ---------------------------------------------------------------------------
 
-  def _delete_ (self, table, oldfields, recno):
+  def _delete_ (self, table, oldfields):
 
     parser = self.__getParser (self.getFilename (table), table)
 

Modified: trunk/gnue-common/src/datasources/drivers/other/appserver.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/other/appserver.py        
2005-07-04 22:01:54 UTC (rev 7681)
+++ trunk/gnue-common/src/datasources/drivers/other/appserver.py        
2005-07-04 22:35:12 UTC (rev 7682)
@@ -464,21 +464,21 @@
 
   # ---------------------------------------------------------------------------
 
-  def _insert_ (self, table, newfields, recno):
+  def _insert_ (self, table, newfields):
     f = newfields.copy ()
     id = f.pop (u'gnue_id')
     self._sm.store (self._sess_id, table, [id], f.keys (), [f.values ()])
 
   # ---------------------------------------------------------------------------
 
-  def _update_ (self, table, oldfields, newfields, recno):
+  def _update_ (self, table, oldfields, newfields):
     f = newfields
     id = oldfields [u'gnue_id']
     self._sm.store (self._sess_id, table, [id], f.keys (), [f.values ()])
 
   # ---------------------------------------------------------------------------
 
-  def _delete_ (self, table, oldfields, recno):
+  def _delete_ (self, table, oldfields):
     id = oldfields [u'gnue_id']
     self._sm.delete (self._sess_id, table, [id])
 

Modified: trunk/gnue-forms/src/GFObjects/GFBlock.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFBlock.py   2005-07-04 22:01:54 UTC (rev 
7681)
+++ trunk/gnue-forms/src/GFObjects/GFBlock.py   2005-07-04 22:35:12 UTC (rev 
7682)
@@ -291,39 +291,33 @@
 
   def __dsRecordTouched (self, event):
     # This already gets called by GFField??
-    # self.__fireRecordTrigger ('PRE-CHANGE', event.record)
+    # self.__fireRecordTrigger ('PRE-CHANGE')
     pass
 
   # ---------------------------------------------------------------------------
 
   def __dsCommitInsert (self, event):
-    self.__fireRecordTrigger ('PRE-INSERT', event.record)
-    self.__fireRecordTrigger ('PRE-COMMIT', event.record)
+    self.__fireRecordTrigger ('PRE-INSERT')
+    self.__fireRecordTrigger ('PRE-COMMIT')
 
   # ---------------------------------------------------------------------------
 
   def __dsCommitUpdate (self, event):
-    self.__fireRecordTrigger ('PRE-UPDATE', event.record)
-    self.__fireRecordTrigger ('PRE-COMMIT', event.record)
+    self.__fireRecordTrigger ('PRE-UPDATE')
+    self.__fireRecordTrigger ('PRE-COMMIT')
 
   # ---------------------------------------------------------------------------
 
   def __dsCommitDelete (self, event):
-    self.__fireRecordTrigger ('PRE-DELETE', event.record)
-    self.__fireRecordTrigger ('PRE-COMMIT', event.record)
+    self.__fireRecordTrigger ('PRE-DELETE')
+    self.__fireRecordTrigger ('PRE-COMMIT')
 
   # ---------------------------------------------------------------------------
 
-  def __fireRecordTrigger (self, trigger, record):
-    # FIXME: remove record parameter, make ResultSet move "current" pointer
-    # through the records?
-    saveMode = self.mode
-    self._preCommitWorkingRecord = record
-    self.mode = 'precommit'
+  def __fireRecordTrigger (self, trigger):
     self.processTrigger (trigger)
     for field in self._fieldList:
       field.processTrigger (trigger)
-    self.mode = saveMode
 
 
   # ---------------------------------------------------------------------------

Modified: trunk/gnue-forms/src/GFObjects/GFField.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFField.py   2005-07-04 22:01:54 UTC (rev 
7681)
+++ trunk/gnue-forms/src/GFObjects/GFField.py   2005-07-04 22:35:12 UTC (rev 
7682)
@@ -274,9 +274,6 @@
             value = self._block._queryValues[self]
           except KeyError:
             value = None
-    elif mode == 'precommit':
-        value = self._block._preCommitWorkingRecord.getField(self.field)
-
     else:
       if self._block._resultSet and self._block._resultSet.current:
         value = self._block._resultSet.current.getField(self.field)
@@ -346,9 +343,6 @@
     if mode == 'query':
       self._block._queryValues[self] = value
 
-    elif mode == 'precommit':
-      self._block._preCommitWorkingRecord.setField(self.field,value)
-
     else:
       self._block.processTrigger('Pre-Change')
       self.processTrigger('Pre-Change')





reply via email to

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