commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r8662 - in trunk/gnue-forms/src: . GFObjects


From: reinhard
Subject: [gnue] r8662 - in trunk/gnue-forms/src: . GFObjects
Date: Mon, 11 Sep 2006 08:57:32 -0500 (CDT)

Author: reinhard
Date: 2006-09-11 08:57:31 -0500 (Mon, 11 Sep 2006)
New Revision: 8662

Modified:
   trunk/gnue-forms/src/GFForm.py
   trunk/gnue-forms/src/GFInstance.py
   trunk/gnue-forms/src/GFObjects/GFBlock.py
Log:
Slight restructuring of commit/rollback methods.


Modified: trunk/gnue-forms/src/GFForm.py
===================================================================
--- trunk/gnue-forms/src/GFForm.py      2006-09-11 12:42:57 UTC (rev 8661)
+++ trunk/gnue-forms/src/GFForm.py      2006-09-11 13:57:31 UTC (rev 8662)
@@ -169,12 +169,10 @@
             'cancel_query': {'function': self.cancel_query},
             'execute_query': {'function': self.execute_query},
 
-            'commit': {
-                'function': self.__trigger_commit,
-                'global': True},
-            'rollback': {
-                'function': self.__trigger_rollback,
-                'global': True},
+            # Transactions
+            'commit': {'function': self.commit, 'global': True},
+            'rollback': {'function': self.rollback, 'global': True},
+
             'printout': {
                 'function': self.__trigger_printout},
             'activateDialog': {
@@ -469,22 +467,6 @@
 
     # -------------------------------------------------------------------------
 
-    def __trigger_commit(self):
-        """
-        Save all changes.
-        """  
-        self.commit()
-      
-    # -------------------------------------------------------------------------
-
-    def __trigger_rollback(self):
-        """
-        Roll back all unsaved changes.
-        """
-        self.rollback()
-
-    # -------------------------------------------------------------------------
-
     def __trigger_printout(self):
         """
         Print the form.
@@ -1131,7 +1113,7 @@
 
         if self._currentBlock is not None:
             if self._currentBlock.autoCommit:
-                self.commit()
+                self.execute_commit()
 
         if not self.__must_save():
             # Notify the UI to not show the query button pressed in
@@ -1163,7 +1145,7 @@
 
         if self._currentBlock is not None:
             if self._currentBlock.autoCommit:
-                self.commit()
+                self.execute_commit()
 
         if not self.__must_save():
             # Notify the UI to not show the query button pressed in
@@ -1228,7 +1210,7 @@
 
             except DBError:
                 self.__rollback_all_connections()
-                # TODO: self.__clear_all_blocks()
+                self.__clear_all_blocks()
                 raise
 
         finally:
@@ -1246,37 +1228,6 @@
 
 
     # -------------------------------------------------------------------------
-    # Check all blocks in the form whether they are saved (committed) or not.
-    # -------------------------------------------------------------------------
-
-    def isSaved(self):
-        """
-        Checks all block in the form whether they are saved (committed) or not.
-        @return: boolean, True if all the blocks are committed.
-        """
-
-        # Is the current entry changed?
-        if (self._currentEntry is not None and \
-            self._currentEntry._type != 'GFButton' and \
-            self._currentEntry._field._bound and \
-            self._currentEntry._displayHandler.isPending()):
-          return False
-
-        # Are there any not yet posted changes in any of the blocks?
-        for block in self._logic._blockList:
-            if block.is_pending():
-                return False
-
-        # Does a connection have any pending (already posted but not yet
-        # committed) changes?
-        for connection in (self.__get_connections ()).values ():
-          if connection.isPending ():
-            return False
-
-        return True
-
-
-    # -------------------------------------------------------------------------
     # Commit all pending changes
     # -------------------------------------------------------------------------
 
@@ -1288,84 +1239,74 @@
         if not self.endEditing():
             return
 
-        # It is not possible to make any record dirty in any way if the form is
-        # read only, so the menu item and the toolbar button for committing are
-        # never active for a read only form. Still, any other trigger could
-        # call commit() manually, in which case this exception would occur.
-        if self.readonly:
-            raise ReadOnlyError
-        
-        newBlock = None                     # block to jump to after commit
-
         try:
-            # Save all current records, since they get lost in the Pre-Commit
-            # trigger code
-            for block in self._logic._blockList:
-                block._precommitRecord = block._currentRecord
+            # Do the actual work
+            self.execute_commit()
+        finally:
+            self.refreshDisplay(self)
+            self.update_record_counter()
+            self.update_record_status()
+            self.dispatchEvent('gotoENTRY', object=self._currentEntry,
+                    _form=self)
+            self.beginEditing()
 
-            # Form level pre-commit triggers
-            self.processTrigger('Pre-Commit', ignoreAbort=False)
+    # -------------------------------------------------------------------------
 
-            # Process the commit on all blocks
-            for block in self._logic._blockList:
-                assert gDebug(5, "Saving %s" % block.name)
-                try:
-                    block.processCommit()
-                except Exception:
-                    # jump to offending block
-                    newBlock = block
-                    raise
+    def execute_commit(self):
 
-            try:
-                # Now do the real commit() on the backend connections (only
-                # once per connection, if multiple blocks are sharing the same
-                # connection)
-                for connection in self.__get_connections().values():
-                    connection.commit()
+        # Save all current records, since they get lost in the Pre-Commit
+        # trigger code
+        for block in self._logic._blockList:
+            block._precommitRecord = block._currentRecord
 
-            except:
-                # Make sure the block is in consistent state again; this has to
-                # be done in any case if the processCommit was successful, even
-                # if the connection commit failed!
-                for block in self._logic._blockList:            
-                    block.finalizeCommit(False)
+        # Form level pre-commit triggers
+        self.processTrigger('Pre-Commit', ignoreAbort=False)
+
+        # Process the commit on all blocks
+        for block in self._logic._blockList:
+            assert gDebug(5, "Saving %s" % block.name)
+            try:
+                block.post()
+            except Exception:
+                # jump to offending block
+                if block != self._currentBlock:
+                    self.findAndChangeFocus(block)
                 raise
 
+        try:
+            # Now do the real commit() on the backend connections (only
+            # once per connection, if multiple blocks are sharing the same
+            # connection)
+            for connection in self.__get_connections().values():
+                connection.commit()
+        except:
+            # Make sure the block is in consistent state again; this has to
+            # be done in any case if the processCommit was successful, even
+            # if the connection commit failed!
             for block in self._logic._blockList:            
-                block.finalizeCommit(True)
+                block.requery(False)
+            raise
 
-            # Execute Post-Commit-Trigger for each block
-            for block in self._logic._blockList:
-                block.processTrigger('Post-Commit')
+        for block in self._logic._blockList:            
+            block.requery(True)
 
-            for block in self._logic._blockList:
-                if block.autoClear:
-                    block.processClear()
+        # Execute Post-Commit-Trigger for each block
+        for block in self._logic._blockList:
+            block.processTrigger('Post-Commit')
 
-            self.dispatchEvent('cannotCOMMIT')
-            self.dispatchEvent('cannotROLLBACK')
+        for block in self._logic._blockList:
+            if block.autoClear:
+                block.clear()
 
-            # Execute Post-Commit-Trigger for the form
-            self.processTrigger('Post-Commit')
+        # Execute Post-Commit-Trigger for the form
+        self.processTrigger('Post-Commit')
 
-        finally:
-            # In case the commit failed for a different block than the current
-            # one, jump to that block.
-            if newBlock is not None and newBlock != self._currentBlock:
-                self.findAndChangeFocus(newBlock)
 
-            self.refreshDisplay(self)
-            self.update_record_counter()
-            self.update_record_status()
-            self.dispatchEvent('gotoENTRY', object=self._currentEntry, 
_form=self)
-            self.beginEditing()
-
-
     # -------------------------------------------------------------------------
     # Roll back any uncommitted transaction
     # -------------------------------------------------------------------------
 
-    def rollback(self, recover=False):
+    def rollback(self):
         """
         Roll back any uncommitted transaction.
         """
@@ -1375,20 +1316,14 @@
         # Call rollback only once per connection (if multiple blocks are
         # sharing the same connection)
         self.__rollback_all_connections()
+        self.__clear_all_blocks()
 
-        for block in self._logic._blockList:
-            block.processRollback(recover, backendRollback=False)
-
-        self.dispatchEvent('cannotCOMMIT')
-        self.dispatchEvent('cannotROLLBACK')
-
         self.refreshDisplay(self)
         self.update_record_counter()
         self.update_record_status()
         self.dispatchEvent ('gotoENTRY', object=self._currentEntry, _form=self)
         self.beginEditing()
 
-
     # -------------------------------------------------------------------------
 
     def __rollback_all_connections(self):
@@ -1397,6 +1332,45 @@
             connection.rollback()
 
     # -------------------------------------------------------------------------
+
+    def __clear_all_blocks(self):
+
+        for block in self._logic._blockList:
+            block.clear()
+
+
+    # -------------------------------------------------------------------------
+    # Check all blocks in the form whether they are saved (committed) or not.
+    # -------------------------------------------------------------------------
+
+    def isSaved(self):
+        """
+        Checks all block in the form whether they are saved (committed) or not.
+        @return: boolean, True if all the blocks are committed.
+        """
+
+        # Is the current entry changed?
+        if (self._currentEntry is not None and \
+            self._currentEntry._type != 'GFButton' and \
+            self._currentEntry._field._bound and \
+            self._currentEntry._displayHandler.isPending()):
+          return False
+
+        # Are there any not yet posted changes in any of the blocks?
+        for block in self._logic._blockList:
+            if block.is_pending():
+                return False
+
+        # Does a connection have any pending (already posted but not yet
+        # committed) changes?
+        for connection in (self.__get_connections ()).values ():
+          if connection.isPending ():
+            return False
+
+        return True
+
+
+    # -------------------------------------------------------------------------
     # Print form
     # -------------------------------------------------------------------------
 
@@ -1782,7 +1756,7 @@
 
         if self._currentBlock is not None:
             if self._currentBlock.autoCommit and not self.isSaved():
-                self.commit()
+                self.execute_commit()
 
         if not self.__must_save():
             return
@@ -1814,6 +1788,6 @@
             return False
 
         if answer:
-            self.commit()
+            self.execute_commit()
 
         return True

Modified: trunk/gnue-forms/src/GFInstance.py
===================================================================
--- trunk/gnue-forms/src/GFInstance.py  2006-09-11 12:42:57 UTC (rev 8661)
+++ trunk/gnue-forms/src/GFInstance.py  2006-09-11 13:57:31 UTC (rev 8662)
@@ -119,13 +119,13 @@
                 'requestEXECQUERY'    : self.__execute_execQuery,
 
                 # Transactions
-                'requestCOMMIT'       : self.executeCommit,
-                'requestPRINTOUT'     : self.executePrintout,
-                'requestROLLBACK'     : self.executeRollback,
+                'requestCOMMIT'       : self.__execute_commit,
+                'requestROLLBACK'     : self.__execute_rollback,
 
                 # Miscellaneous stuff
                 'requestMODETOGGLE'   : self.toggleInsertMode,
                 'requestABOUT'        : self.executeAbout,
+                'requestPRINTOUT'     : self.executePrintout,
                 'requestUSERCOMMAND'  : self.executeUserCommand,
                 'requestEXIT'         : self.executeExit})
 
@@ -701,6 +701,21 @@
 
 
   # ---------------------------------------------------------------------------
+  # Transactions
+  # ---------------------------------------------------------------------------
+
+  def __execute_commit(self, event):
+
+    event._form.commit()
+
+  # ---------------------------------------------------------------------------
+
+  def __execute_rollback(self, event):
+
+    event._form.rollback()
+
+
+  # ---------------------------------------------------------------------------
   # Verify state of data and exit form
   # ---------------------------------------------------------------------------
 
@@ -801,26 +816,6 @@
 
 
   # ---------------------------------------------------------------------------
-  # Perform a commit
-  # ---------------------------------------------------------------------------
-
-  def executeCommit (self, event):
-
-    event._form.commit ()
-
-
-  # ---------------------------------------------------------------------------
-  # Perform a rollback
-  # ---------------------------------------------------------------------------
-
-  def executeRollback (self, event):
-    """
-    Tells the form to rollback everything it contains
-    """
-    event._form.rollback ()
-
-
-  # ---------------------------------------------------------------------------
   # Execute user command
   # ---------------------------------------------------------------------------
 

Modified: trunk/gnue-forms/src/GFObjects/GFBlock.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFBlock.py   2006-09-11 12:42:57 UTC (rev 
8661)
+++ trunk/gnue-forms/src/GFObjects/GFBlock.py   2006-09-11 13:57:31 UTC (rev 
8662)
@@ -135,11 +135,6 @@
             'deleteRecord': {'function': self.delete_record},
             'undeleteRecord': {'function': self.undelete_record},
 
-            # Transactions
-            'commit': {'function': self.commit},
-            'rollback': {'function': self.processRollback},
-            'clear': {'function': self.processClear},
-
             # Other stuff
             'call': {'function': self.callFunction},
             'update': {'function': self.updateCurrentRecordSet},
@@ -939,6 +934,58 @@
 
 
   # ---------------------------------------------------------------------------
+  # Saving and Discarding
+  # ---------------------------------------------------------------------------
+
+  def post(self):
+        """
+        Post all pending changes of the block
+        """
+
+        assert gDebug (4, "processing commit on block %s" % self.name, 1)
+
+        self.mode = 'commit'
+
+        self._resultSet.setRecord(self._precommitRecord)
+
+        if self._getMasterBlock() is None:
+            self._dataSourceLink.postAll()
+
+  # ---------------------------------------------------------------------------
+
+  def requery(self, commit):
+        """
+        Called after the commit on the backend is through.
+        """
+
+        # Synchronize backend -> resultset -> UI
+        if self._getMasterBlock() is None:
+            self._dataSourceLink.requeryAll(commit)
+
+        # Our recordCount might have changed if records were deleted
+        self._recordCount = self._resultSet.getRecordCount()
+
+        # If all records were deleted, create an empty new one.
+        if not self._recordCount:
+            self.new_record()
+
+        self.mode = 'normal'
+
+  # ---------------------------------------------------------------------------
+
+  def clear(self):
+        """
+        Clear the result set of this block.
+        """
+
+        # Detail blocks cannot be cleared - they follow their master blindly.
+        if self._getMasterBlock() is not None:
+            return
+
+        self._dataSourceLink.createEmptyResultSet()
+
+
+  # ---------------------------------------------------------------------------
   # Shared code called whenever focus enters or leaves a record
   # ---------------------------------------------------------------------------
 
@@ -960,7 +1007,7 @@
             self.processTrigger('PRE-FOCUSOUT')
 
             if do_auto_commit and self.autoCommit and self._resultSet.current:
-                self._form.commit()
+                self._form.execute_commit()
 
             self.processTrigger('POST-FOCUSOUT')
 
@@ -999,101 +1046,6 @@
 
 
   # ---------------------------------------------------------------------------
-  # Commit and Rollback
-  # ---------------------------------------------------------------------------
-
-  def commit (self):
-    """
-    Commit all pending changes of the form this block is bound to.
-
-    This method is depreciated. Please use form.commit () instead.
-    """
-
-    print "DEPRECIATION WARNING: the use of block.commit () is depreciated.", \
-          "Please use form.commit () instead."
-    self._form.commit ()
-
-  # ---------------------------------------------------------------------------
-
-  def processCommit (self):
-    """
-    Post all pending changes of the block
-    """
-
-    assert gDebug (4, "processing commit on block %s" % self.name, 1)
-
-    self.mode = 'commit'
-
-    self._resultSet.setRecord (self._precommitRecord)
-
-    if self._getMasterBlock () is None:
-      self._dataSourceLink.postAll ()
-
-  # ---------------------------------------------------------------------------
-
-  def finalizeCommit (self, commit):
-    """
-    Called after the commit on the backend is through.
-    """
-
-    # Synchronize backend -> resultset -> UI
-    if self._getMasterBlock () is None:
-      self._dataSourceLink.requeryAll (commit)
-
-    # Our recordCount might have changed if records were deleted
-    self._recordCount = self._resultSet.getRecordCount ()
-
-    # If all records were deleted, create an empty new one.
-    if not self._recordCount:
-      self.new_record()
-
-    self.mode = 'normal'
-
-  # ---------------------------------------------------------------------------
-
-  def processClear (self):
-    """
-    Rollback the blocks pending changes (by calling a rollback of the backend)
-    and finally create a new and empty result set.  This method has no effect
-    for detail-blocks.
-    """
-
-    # Detail blocks cannot be cleared - they follow their master blindly.
-    if self._getMasterBlock () is not None:
-      return
-
-    if self._dataSourceLink._connection is not None:
-      self._dataSourceLink._connection.rollback ()
-
-    self._dataSourceLink.createEmptyResultSet ()
-
-  # ---------------------------------------------------------------------------
-
-  def processRollback (self, recovering = False, backendRollback = True):
-    """
-    Perform a rollback of all pending changes of the block.
-    @param recovering: If False, the user requested a rollback and a new, empty
-      result set will be created. If True, then a commit or such failed and we
-      need to clean up (but not lose state information).
-    @param backendRollback: If True, a rollback is performed on the backend
-      connection, otherwise not.
-    """
-
-    # Detail blocks cannot be rolled back - they follow their master blindly.
-    if self._getMasterBlock () is not None:
-      return
-
-    # If called from GFForm the connection's rollback () has been executed
-    # already.  But if called from a trigger code we do it here
-    if backendRollback:
-      if self._dataSourceLink._connection is not None:
-        self._dataSourceLink._connection.rollback ()
-
-    if not recovering:
-      self._dataSourceLink.createEmptyResultSet ()
-
-
-  # ---------------------------------------------------------------------------
   # Raw data access
   # ---------------------------------------------------------------------------
 





reply via email to

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