[ZODB-Dev] Transaction undo example
Patrick DECAT
pdecat at gmail.com
Tue Apr 12 09:27:37 EDT 2005
My fault, it's a ZODB list, not a Zope one.
Perhaps you should have a look at the unit tests in TransactionalUndoStorage.py.
This one is rather explicit :
def checkTwoObjectUndo(self):
eq = self.assertEqual
# Convenience
p31, p32, p51, p52 = map(zodb_pickle,
map(MinPO, (31, 32, 51, 52)))
oid1 = self._storage.new_oid()
oid2 = self._storage.new_oid()
revid1 = revid2 = ZERO
# Store two objects in the same transaction
t = Transaction()
self._storage.tpc_begin(t)
self._transaction_begin()
self._transaction_store(oid1, revid1, p31, '', t)
self._transaction_store(oid2, revid2, p51, '', t)
# Finish the transaction
self._transaction_vote(t)
revid1 = self._transaction_newserial(oid1)
revid2 = self._transaction_newserial(oid2)
self._storage.tpc_finish(t)
eq(revid1, revid2)
# Update those same two objects
t = Transaction()
self._storage.tpc_begin(t)
self._transaction_begin()
self._transaction_store(oid1, revid1, p32, '', t)
self._transaction_store(oid2, revid2, p52, '', t)
# Finish the transaction
self._transaction_vote(t)
revid1 = self._transaction_newserial(oid1)
revid2 = self._transaction_newserial(oid2)
self._storage.tpc_finish(t)
eq(revid1, revid2)
# Make sure the objects have the current value
data, revid1 = self._storage.load(oid1, '')
eq(zodb_unpickle(data), MinPO(32))
data, revid2 = self._storage.load(oid2, '')
eq(zodb_unpickle(data), MinPO(52))
# Now attempt to undo the transaction containing two objects
info = self._storage.undoInfo()
tid = info[0]['id']
t = Transaction()
self._storage.tpc_begin(t)
oids = self._storage.transactionalUndo(tid, t)
self._storage.tpc_vote(t)
self._storage.tpc_finish(t)
eq(len(oids), 2)
self.failUnless(oid1 in oids)
self.failUnless(oid2 in oids)
data, revid1 = self._storage.load(oid1, '')
eq(zodb_unpickle(data), MinPO(31))
data, revid2 = self._storage.load(oid2, '')
eq(zodb_unpickle(data), MinPO(51))
self._iterate()
On Apr 12, 2005 2:55 PM, Stefan Milenkovic <smilenko at gmail.com> wrote:
> Maybe I should have precised that I don't use Zope. I just use ZODB as
> a standalone database which is accessed by some Python code...
>
> Thanks,
>
> Stefan
>
>
> On Apr 12, 2005 2:18 PM, Patrick DECAT <pdecat at gmail.com> wrote:
> > I believe you should then use the manage_undo_transactions method as
> > used in the undo.dtml form.
> >
> > Something like:
> > context.manage_undo_transactions(transaction_info=('QTF5TVlhNjdtTXc9'))
> >
> > HTH,
> > Patrick.
> >
> > On Apr 12, 2005 2:09 PM, Stefan Milenkovic <smilenko at gmail.com> wrote:
> > > Hello,
> > >
> > > Thank you for your answer! But my problem is not exactly this one. In
> > > fact I have a committed transaction and I want to undo it. It doesn't
> > > concern the current transaction...
> > >
> > > Maybe my first question was not clear...
> > >
> > > Thanks,
> > >
> > > Stefan
> > >
> > >
> > > On Apr 12, 2005 12:28 PM, Patrick DECAT <pdecat at gmail.com> wrote:
> > > > Hi,
> > > >
> > > > if you want to abort the current transaction, here is a sample
> > > > inspired from Zope's code:
> > > > def some_method(self, REQUEST, RESPONSE):
> > > > """Do stuff"""
> > > > try:
> > > > # Do important stuff
> > > > RESPONSE.setStatus(204)
> > > > except:
> > > > RESPONSE.setStatus(500)
> > > > get_transaction().abort()
> > > >
> > > > return RESPONSE
> > > >
> > > > HTH,
> > > > Patrick.
> > > >
> > > > On Apr 12, 2005 11:24 AM, Stefan Milenkovic <smilenko at gmail.com> wrote:
> > > > > Hello,
> > > > >
> > > > > I am relatively new to ZODB and I have to work for some reasons with
> > > > > the transactions.
> > > > >
> > > > > I am trying to undo a transaction, but until now it has been
> > > > > unsuccessful. Maybe I don't know how to do it exacltly...
> > > > >
> > > > > So is there someone who can give me a small example of a transaction undo?
> > > > >
> > > > > Thanks in advance,
> > > > >
> > > > > Stefan
> > > > > _______________________________________________
> > > > > For more information about ZODB, see the ZODB Wiki:
> > > > > http://www.zope.org/Wikis/ZODB/
> > > > >
> > > > > ZODB-Dev mailing list - ZODB-Dev at zope.org
> > > > > http://mail.zope.org/mailman/listinfo/zodb-dev
> > > > >
> > > >
> > >
> >
>
More information about the ZODB-Dev
mailing list