[Zodb-checkins] CVS: ZODB/src/ZODB - DemoStorage.py:1.24 DB.py:1.60
BaseStorage.py:1.41
Jeremy Hylton
jeremy at zope.com
Tue Feb 17 20:13:33 EST 2004
Update of /cvs-repository/ZODB/src/ZODB
In directory cvs.zope.org:/tmp/cvs-serv25077/src/ZODB
Modified Files:
DemoStorage.py DB.py BaseStorage.py
Log Message:
Rename transactionalUndo() to undo().
The old undo was not used by Zope and shouldn't have been used by any
other client. The newly named undo() is the preferred version of
undo.
XXX DemoStorage didn't implement transactionalUndo, so now it doesn't
implementation undo() at all. We need to replace it with the demo
storage from ZODB4.
There are a few changes related to ZODB4 removal in this checkin.
=== ZODB/src/ZODB/DemoStorage.py 1.23 => 1.24 ===
--- ZODB/src/ZODB/DemoStorage.py:1.23 Wed Dec 24 11:02:00 2003
+++ ZODB/src/ZODB/DemoStorage.py Tue Feb 17 20:13:00 2004
@@ -277,9 +277,6 @@
finally: self._lock_release()
return self._tid
- def supportsUndo(self):
- return 1
-
def supportsVersions(self):
return 1
@@ -320,57 +317,6 @@
v = self._vindex[version] = {}
v[oid] = r
self._ltid = self._tid
-
- def undo(self, transaction_id):
- self._lock_acquire()
- try:
- transaction_id=base64.decodestring(transaction_id+'\n')
- try: t=self._data[transaction_id][4]
- except KeyError:
- raise UndoError, 'Invalid undo transaction id'
-
- index=self._index
- vindex=self._vindex
- vindex_get=self._vindex.get
- for r in t:
- if index[r[0]] is not r:
- raise POSException.UndoError, 'non-undoable transaction'
-
- oids=[]
- for r in t:
- oid, pre, vdata, p, tid = r
- if pre:
-
- index[oid] = pre
- oids.append(oid)
-
- # Delete old version data
- if vdata:
- version=vdata[0]
- v=vindex.get(version, None)
- if v: del v[oid]
-
- # Add new version data (from pre):
- oid, prepre, vdata, p, tid = pre
- if vdata:
- version=vdata[0]
- v=vindex.get(version, None)
- if v is None: v=vindex[version]={}
- v[oid]=pre
-
- else:
- del index[oid]
- if vdata:
- version=vdata[0]
- v=vindex.get(version, None)
- if v: del v[oid]
- if not v: del vindex[version]
-
- del self._data[transaction_id]
-
- return oids
-
- finally: self._lock_release()
def undoLog(self, first, last, filter=None):
if last < 0:
=== ZODB/src/ZODB/DB.py 1.59 => 1.60 ===
--- ZODB/src/ZODB/DB.py:1.59 Tue Jan 6 16:44:25 2004
+++ ZODB/src/ZODB/DB.py Tue Feb 17 20:13:00 2004
@@ -574,82 +574,70 @@
def cacheStatistics(self): return () # :(
def undo(self, id, transaction=None):
- storage=self._storage
- try: supportsTransactionalUndo = storage.supportsTransactionalUndo
- except AttributeError:
- supportsTransactionalUndo=0
- else:
- supportsTransactionalUndo=supportsTransactionalUndo()
-
- if supportsTransactionalUndo:
- # new style undo
- if transaction is None:
- transaction = get_transaction()
- transaction.register(TransactionalUndo(self, id))
- else:
- # fall back to old undo
- d = {}
- for oid in storage.undo(id):
- d[oid] = 1
- # XXX I think we need to remove old undo to use mvcc
- self.invalidate(None, d)
+ if transaction is None:
+ transaction = get_transaction()
+ transaction.register(TransactionalUndo(self, id))
def versionEmpty(self, version):
return self._storage.versionEmpty(version)
-class CommitVersion:
- """An object that will see to version commit
+class ResourceManager(object):
+ """Transaction participation for a version or undo resource."""
- in cooperation with a transaction manager.
- """
- def __init__(self, db, version, dest=''):
- self._db=db
- s=db._storage
- self._version=version
- self._dest=dest
- self.tpc_abort=s.tpc_abort
- self.tpc_begin=s.tpc_begin
- self.tpc_vote=s.tpc_vote
- self.tpc_finish=s.tpc_finish
- self._sortKey=s.sortKey
+ def __init__(self, db):
+ self._db = db
+ # Delegate the actual 2PC methods to the storage
+ self.tpc_begin = self._db._storage.tpc_begin
+ self.tpc_vote = self._db._storage.tpc_vote
+ self.tpc_finish = self._db._storage.tpc_finish
+ self.tpc_abort = self._db._storage.tpc_abort
def sortKey(self):
- return "%s:%s" % (self._sortKey(), id(self))
+ return "%s:%s" % (self._db._storage.sortKey(), id(self))
+
+ # The object registers itself with the txn manager, so the ob
+ # argument to the methods below is self.
+
+ def abort(self, ob, t):
+ pass
- def abort(self, reallyme, t): pass
+ def commit(self, ob, t):
+ pass
+
+class CommitVersion(ResourceManager):
+
+ def __init__(self, db, version, dest=''):
+ super(CommitVersion, self).__init__(db)
+ self._version = version
+ self._dest = dest
- def commit(self, reallyme, t):
+ def commit(self, ob, t):
dest=self._dest
- tid, oids = self._db._storage.commitVersion(self._version, dest, t)
+ tid, oids = self._db._storage.commitVersion(self._version, self._dest,
+ t)
oids = list2dict(oids)
- self._db.invalidate(tid, oids, version=dest)
- if dest:
+ self._db.invalidate(tid, oids, version=self._dest)
+ if self._dest:
# the code above just invalidated the dest version.
# now we need to invalidate the source!
self._db.invalidate(tid, oids, version=self._version)
-class AbortVersion(CommitVersion):
- """An object that will see to version abortion
-
- in cooperation with a transaction manager.
- """
-
- def commit(self, reallyme, t):
- version = self._version
- tid, oids = self._db._storage.abortVersion(version, t)
- self._db.invalidate(tid, list2dict(oids), version=version)
-
-
-class TransactionalUndo(CommitVersion):
- """An object that will see to transactional undo
-
- in cooperation with a transaction manager.
- """
+class AbortVersion(ResourceManager):
- # I (Jim) am lazy. I'm reusing __init__ and abort and reusing the
- # version attr for the transaction id. There's such a strong
- # similarity of rhythm that I think it's justified.
+ def __init__(self, db, version):
+ super(AbortVersion, self).__init__(db)
+ self._version = version
+
+ def commit(self, ob, t):
+ tid, oids = self._db._storage.abortVersion(self._version, t)
+ self._db.invalidate(tid, list2dict(oids), version=self._version)
+
+class TransactionalUndo(ResourceManager):
+
+ def __init__(self, db, tid):
+ super(TransactionalUndo, self).__init__(db)
+ self._tid = tid
- def commit(self, reallyme, t):
- tid, oids = self._db._storage.transactionalUndo(self._version, t)
+ def commit(self, ob, t):
+ tid, oids = self._db._storage.undo(self._tid, t)
self._db.invalidate(tid, list2dict(oids))
=== ZODB/src/ZODB/BaseStorage.py 1.40 => 1.41 ===
--- ZODB/src/ZODB/BaseStorage.py:1.40 Tue Jan 6 16:43:04 2004
+++ ZODB/src/ZODB/BaseStorage.py Tue Feb 17 20:13:01 2004
@@ -120,9 +120,6 @@
def supportsUndo(self):
return 0
- def supportsTransactionalUndo(self):
- return 0
-
def supportsVersions(self):
return 0
@@ -221,7 +218,7 @@
"""
pass
- def undo(self, transaction_id):
+ def undo(self, transaction_id, txn):
if self._is_read_only:
raise POSException.ReadOnlyError()
raise POSException.UndoError, 'non-undoable transaction'
More information about the Zodb-checkins
mailing list