[ZODB-Dev] Re: ZODB-Dev digest, Vol 1 #493 - 7 msgs

Jeff Sasmor jsasmor@gte.net
Wed, 19 Jun 2002 17:50:18 -0400


I found this difficult to do, but possible. 

I keep the connection open during the app,
but when I do undo I do a few things: 

first I make sure that the ZODB is up to date
by checking the transaction to see if there are any
uncommitted objects in it. 

given a transaction_id:

tid = split(transaction_id)
    if tid:
      t = get_transaction()
      if len(t._objects) > 0:
        dbMgr.dbPost(note=_('Pre-Undo DB commit to close open transaction'),obj=self,mark_non_undoable=1) 
        

Then in order to complete the Undo you have to do a db commit:
      note = "Undo %s" % (join(tid[1:]))
      tid=decode64(tid[0])
      try:
        dbMgr.getDB().undo(tid)
      except Exception,value:
        result = 0
        GenericWarning('Error: %s' % str(value))
      else:
        try:
          dbMgr.dbPost(note=note,obj=self)
        except UndoError,v:
          GenericWarning('Non-undoable transaction:\n%s' % str(v))
          result = 0
        
    else:
      result = 0
    
    return result
     
then I close all data structures in my app that maintain refs to these objects
and do a reconnect:

self.connection.close()
self.connection = self.db.open()
self.root = self.connection.root()


then rebuild all the windows in my app, which of course refreshes all the objects.
Works fine; user sees a quick flicker, but how often do you undo, anyway.  

I found this approach to be necc since the GUI library (wxPython) I use holds all
sorts of internal refs to the objects you pass it and it's almost impossible to ensure
a 'clean' system after an undo if the entire set of windows etc. is not refreshed.

Hope these fragments don't seem like gibberish...

HTH

#--------------------------------
Jeff Sasmor
jeff@sasmor.com

Message: 3
Date: Tue, 18 Jun 2002 18:57:18 -0400
From: "Mike C. Fletcher" <mcfletch@rogers.com>
To: zodb-dev <zodb-dev@python.org>
Subject: [ZODB-Dev] Help: ZODB undo problem

Hopefully third time is a charm :) ...

I'm trying to add undo functionality to a ZODB-3-based single-user GUI 
application.  <snip>