Commit a3d98800 authored by Tim Peters's avatar Tim Peters

Deprecate a pile of DB.open() arguments.

Start simplifying the code.
parent fa14f638
...@@ -2,6 +2,14 @@ What's new in ZODB3 3.4? ...@@ -2,6 +2,14 @@ What's new in ZODB3 3.4?
======================== ========================
Release date: DD-MMM-2004 Release date: DD-MMM-2004
DB
--
- The following optional arguments to ``DB.open()`` are deprecated:
``transaction``, ``waitflag``, ``force`` and ``temporary``. If one
is specified, its value is ignored, and ``DeprecationWarning`` is
raised. In a future release, these optional arguments will be
removed.
Tools Tools
----- -----
......
...@@ -29,6 +29,9 @@ import transaction ...@@ -29,6 +29,9 @@ import transaction
logger = logging.getLogger('ZODB.DB') logger = logging.getLogger('ZODB.DB')
# A unique marker for detecting use of deprecated arguments.
_deprecated = object()
class DB(object): class DB(object):
"""The Object Database """The Object Database
------------------- -------------------
...@@ -89,10 +92,11 @@ class DB(object): ...@@ -89,10 +92,11 @@ class DB(object):
:Parameters: :Parameters:
- `storage`: the storage used by the database, e.g. FileStorage - `storage`: the storage used by the database, e.g. FileStorage
- `pool_size`: maximum number of open connections - `pool_size`: expected maximum number of open connections
- `cache_size`: target size of Connection object cache - `cache_size`: target size of Connection object cache
- `cache_deactivate_after`: ignored - `cache_deactivate_after`: ignored
- `version_pool_size`: maximum number of connections (per version) - `version_pool_size`: expected maximum number of connections (per
version)
- `version_cache_size`: target size of Connection object cache for - `version_cache_size`: target size of Connection object cache for
version connections version connections
- `version_cache_deactivate_after`: ignored - `version_cache_deactivate_after`: ignored
...@@ -398,8 +402,10 @@ class DB(object): ...@@ -398,8 +402,10 @@ class DB(object):
def objectCount(self): def objectCount(self):
return len(self._storage) return len(self._storage)
def open(self, version='', transaction=None, temporary=0, force=None, def open(self, version='',
waitflag=1, mvcc=True, txn_mgr=None, synch=True): transaction=_deprecated, temporary=_deprecated,
force=_deprecated, waitflag=_deprecated,
mvcc=True, txn_mgr=None, synch=True):
"""Return a database Connection for use by application code. """Return a database Connection for use by application code.
The optional `version` argument can be used to specify that a The optional `version` argument can be used to specify that a
...@@ -417,42 +423,31 @@ class DB(object): ...@@ -417,42 +423,31 @@ class DB(object):
:Parameters: :Parameters:
- `version`: the "version" that all changes will be made - `version`: the "version" that all changes will be made
in, defaults to no version. in, defaults to no version.
- `transaction`: XXX
- `mvcc`: boolean indicating whether MVCC is enabled - `mvcc`: boolean indicating whether MVCC is enabled
- `txn_mgr`: transaction manager to use. None means - `txn_mgr`: transaction manager to use. None means
used the default transaction manager. used the default transaction manager.
- `synch`: boolean indicating whether Connection should - `synch`: boolean indicating whether Connection should
register for afterCompletion() calls. register for afterCompletion() calls.
- `temporary`: XXX
- `force`: XXX
- `waitflag`: XXX
""" """
self._a()
try:
if transaction is not None: if temporary is not _deprecated:
connections = transaction._connections warnings.warn("DB.open() temporary= has no effect",
if connections: DeprecationWarning)
if connections.has_key(version) and not temporary:
return connections[version] if force is not _deprecated:
else: warnings.warn("DB.open() force= has no effect",
transaction._connections = connections = {} DeprecationWarning)
transaction = transaction._connections
if temporary:
# This is a temporary connection.
# We won't bother with the pools. This will be
# a one-use connection.
c = self.klass(version=version,
cache_size=self._version_cache_size,
mvcc=mvcc, txn_mgr=txn_mgr, synch=synch)
c._setDB(self)
self._temps.append(c)
if transaction is not None:
transaction[id(c)] = c
return c
if waitflag is not _deprecated:
warnings.warn("DB.open() waitflag= has no effect",
DeprecationWarning)
if transaction is not _deprecated:
warnings.warn("DB.open() transaction= has no effect",
DeprecationWarning)
self._a()
try:
pools, pooll = self._pools pools, pooll = self._pools
# pools is a mapping object: # pools is a mapping object:
...@@ -492,13 +487,13 @@ class DB(object): ...@@ -492,13 +487,13 @@ class DB(object):
if not pool: if not pool:
c = None c = None
if version: if version:
if self._version_pool_size > len(allocated) or force: if self._version_pool_size > len(allocated):
c = self.klass(version=version, c = self.klass(version=version,
cache_size=self._version_cache_size, cache_size=self._version_cache_size,
mvcc=mvcc, txn_mgr=txn_mgr) mvcc=mvcc, txn_mgr=txn_mgr)
allocated.append(c) allocated.append(c)
pool.append(c) pool.append(c)
elif self._pool_size > len(allocated) or force: elif self._pool_size > len(allocated):
c = self.klass(version=version, c = self.klass(version=version,
cache_size=self._cache_size, cache_size=self._cache_size,
mvcc=mvcc, txn_mgr=txn_mgr, synch=synch) mvcc=mvcc, txn_mgr=txn_mgr, synch=synch)
...@@ -506,16 +501,13 @@ class DB(object): ...@@ -506,16 +501,13 @@ class DB(object):
pool.append(c) pool.append(c)
if c is None: if c is None:
if waitflag: self._r()
self._r() pool_lock.acquire()
pool_lock.acquire() self._a()
self._a() if len(pool) > 1:
if len(pool) > 1: # Note that the pool size will normally be 1 here,
# Note that the pool size will normally be 1 here, # but it could be higher due to a race condition.
# but it could be higher due to a race condition. pool_lock.release()
pool_lock.release()
else:
return
elif len(pool)==1: elif len(pool)==1:
# Taking last one, lock the pool. # Taking last one, lock the pool.
...@@ -552,8 +544,6 @@ class DB(object): ...@@ -552,8 +544,6 @@ class DB(object):
for cc in pool: for cc in pool:
cc.cacheGC() cc.cacheGC()
if transaction is not None:
transaction[version] = c
return c return c
finally: finally:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment