[Zodb-checkins] CVS: Zope3/src/ZODB - Connection.py:1.140.2.5
DB.py:1.71.2.4
Jeremy Hylton
jeremy at zope.com
Wed Mar 31 17:08:09 EST 2004
Update of /cvs-repository/Zope3/src/ZODB
In directory cvs.zope.org:/tmp/cvs-serv16924/src/ZODB
Modified Files:
Tag: jeremy-txn-branch
Connection.py DB.py
Log Message:
Add optional txn_mgr argument to DB.open() and Connection().
This feature would be used instead of setLocalTransaction(). Given
the new TM architecture, where a Transaction can't be reused for
multiple commits, this seems like the cleanest alternative.
=== Zope3/src/ZODB/Connection.py 1.140.2.4 => 1.140.2.5 ===
--- Zope3/src/ZODB/Connection.py:1.140.2.4 Tue Mar 30 11:47:52 2004
+++ Zope3/src/ZODB/Connection.py Wed Mar 31 17:08:07 2004
@@ -33,7 +33,6 @@
from ZODB.POSException \
import ConflictError, ReadConflictError, InvalidObjectReference
from ZODB.TmpStore import TmpStore
-from ZODB.Transaction import Transaction, get_transaction
from ZODB.utils import oid_repr, z64
from ZODB.serialize import ObjectWriter, ConnectionObjectReader, myhasattr
@@ -125,10 +124,9 @@
_tmp = None
_code_timestamp = 0
- _transaction = None
def __init__(self, version='', cache_size=400,
- cache_deactivate_after=None, mvcc=True):
+ cache_deactivate_after=None, mvcc=True, txn_mgr=None):
"""Create a new Connection.
A Connection instance should by instantiated by the DB
@@ -157,6 +155,12 @@
self._store_count = 0 # Number of objects stored
self._modified = []
+ # If a transaction manager is passed to the constructor, use
+ # it instead of the global transaction manager. The instance
+ # variable will hold either a TM class or the transaction
+ # module itself, which implements the same interface.
+ self._txn_mgr = txn_mgr or transaction
+
# _invalidated queues invalidate messages delivered from the DB
# _inv_lock prevents one thread from modifying the set while
# another is processing invalidations. All the invalidations
@@ -190,21 +194,18 @@
self._import = None
def getTransaction(self):
- t = self._transaction
- if t is None:
- # Fall back to thread-bound transactions
- t = transaction.get()
- return t
+ # XXX mark this as deprecated?
+ return self._txn_mgr.get()
def setLocalTransaction(self):
"""Use a transaction bound to the connection rather than the thread"""
- # XXX mention that this should only be called when you open
- # a connection or at transaction boundaries (but the lattter are
- # hard to be sure about).
- if self._transaction is None:
- self._transaction = Transaction()
- return self._transaction
+ # XXX mark this method as depcrecated? note that it's
+ # signature changed?
+
+ if self._txn_mgr is transaction:
+ self._txn_mgr = transaction.TransactionManager()
+ return self._txn_mgr
def _cache_items(self):
# find all items on the lru list
@@ -312,7 +313,7 @@
obj._p_jar = self
if self._added_during_commit is not None:
self._added_during_commit.append(obj)
- self.getTransaction().register(obj)
+ self._txn_mgr.get().register(obj)
# Add to _added after calling register(), so that _added
# can be used as a test for whether the object has been
# registered with the transaction.
@@ -658,7 +659,7 @@
elif obj._p_oid in self._added:
# It was registered before it was added to _added.
return
- self.getTransaction().register(obj)
+ self._txn_mgr.get().register(obj)
def root(self):
"""Return the database root object.
@@ -737,7 +738,7 @@
"""Load non-current state for obj or raise ReadConflictError."""
if not (self._mvcc and self._setstate_noncurrent(obj)):
- self.getTransaction().register(obj)
+ self._txn_mgr.get().register(obj)
self._conflicts[obj._p_oid] = True
raise ReadConflictError(object=obj)
@@ -779,7 +780,7 @@
finally:
self._inv_lock.release()
else:
- self.getTransaction().register(obj)
+ self._txn_mgr.get().register(obj)
raise ReadConflictError(object=obj)
def oldstate(self, obj, tid):
@@ -925,7 +926,7 @@
self._flush_invalidations()
def sync(self):
- self.getTransaction().abort()
+ self._txn_mgr.get().abort()
sync = getattr(self._storage, 'sync', 0)
if sync:
sync()
@@ -954,5 +955,5 @@
new._p_oid = oid
new._p_jar = self
new._p_changed = 1
- self.getTransaction().register(new)
+ self._txn_mgr.get().register(new)
self._cache[oid] = new
=== Zope3/src/ZODB/DB.py 1.71.2.3 => 1.71.2.4 ===
--- Zope3/src/ZODB/DB.py:1.71.2.3 Tue Mar 30 14:43:50 2004
+++ Zope3/src/ZODB/DB.py Wed Mar 31 17:08:08 2004
@@ -391,7 +391,7 @@
return len(self._storage)
def open(self, version='', transaction=None, temporary=0, force=None,
- waitflag=1, mvcc=True):
+ waitflag=1, mvcc=True, txn_mgr=None):
"""Return a database Connection for use by application code.
The optional version argument can be used to specify that a
@@ -424,7 +424,7 @@
# a one-use connection.
c = self.klass(version=version,
cache_size=self._version_cache_size,
- mvcc=mvcc)
+ mvcc=mvcc, txn_mgr=txn_mgr)
c._setDB(self)
self._temps.append(c)
if transaction is not None:
@@ -474,13 +474,13 @@
if self._version_pool_size > len(allocated) or force:
c = self.klass(version=version,
cache_size=self._version_cache_size,
- mvcc=mvcc)
+ mvcc=mvcc, txn_mgr=txn_mgr)
allocated.append(c)
pool.append(c)
elif self._pool_size > len(allocated) or force:
c = self.klass(version=version,
cache_size=self._cache_size,
- mvcc=mvcc)
+ mvcc=mvcc, txn_mgr=txn_mgr)
allocated.append(c)
pool.append(c)
More information about the Zodb-checkins
mailing list