Commit 37d0cf64 authored by Jeremy Hylton's avatar Jeremy Hylton

Edit docstrings to remove epydoc markup.

parent e7d2b802
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
############################################################################## ##############################################################################
"""Database connection support """Database connection support
$Id: Connection.py,v 1.134 2004/03/04 16:15:55 jeremy Exp $""" $Id: Connection.py,v 1.135 2004/03/04 19:48:03 jeremy Exp $"""
import logging import logging
import sys import sys
...@@ -102,20 +102,30 @@ class Connection(ExportImport, object): ...@@ -102,20 +102,30 @@ class Connection(ExportImport, object):
XXX Mention the database pool. XXX Mention the database pool.
$Id: Connection.py,v 1.134 2004/03/04 16:15:55 jeremy Exp $ The Connection plays several different roles.
@group User Methods: root, get, add, close, db, sync, isReadOnly, It provides a user-visible interface for accessing objects. These
cacheGC, cacheFullSweep, cacheMinimize, getVersion, modifiedInVersion methods are designed for use by application code: root(), get(),
@group Experimental Methods: setLocalTransaction, getTransaction, add(), close(), db(), sync(), isReadOnly(), cacheGC(),
onCloseCallbacks cacheMinimize(), getVersion(), modifiedInVersion().
@group Transaction Data Manager Methods: tpc_begin, tpc_vote,
tpc_finish, tpc_abort, sortKey, abort, commit, commit_sub, The Connection also interacts with the transaction manager to
abort_sub store changes and make changes by other clients visible. These
@group Database Invalidation Methods: invalidate, _setDB methods participate in that collaoration: tpc_begin(), tpc_vote(),
@group IPersistentDataManager Methods: setstate, register, tpc_finish(), tpc_abort(), sortKey(), abort(), commit(),
setklassstate commit_sub(), abort_sub().
@group Other Methods: oldstate, exchange, getDebugInfo, setDebugInfo,
getTransferCounts The Connection normally used the standard get_transaction()
mechanism for finding the current Transaction. The experimental
setLocalTransaction() and getLocationTransaction() methods can be
used to provide a fixed Transaction.
The Connection also implements the IPersistentDataManager
interface, which provides methods for persistent objects to load
their state and register changes. The methods are setstate(),
register(), setklassstate().
$Id: Connection.py,v 1.135 2004/03/04 19:48:03 jeremy Exp $
""" """
_tmp = None _tmp = None
...@@ -221,7 +231,7 @@ class Connection(ExportImport, object): ...@@ -221,7 +231,7 @@ class Connection(ExportImport, object):
return '<Connection at %08x%s>' % (id(self), ver) return '<Connection at %08x%s>' % (id(self), ver)
def get(self, oid): def get(self, oid):
"""Return the persistent object with oid C{oid}. """Return the persistent object with oid 'oid'.
If the object was not in the cache and the object's class is If the object was not in the cache and the object's class is
ghostable, then a ghost will be returned. If the object is ghostable, then a ghost will be returned. If the object is
...@@ -231,10 +241,12 @@ class Connection(ExportImport, object): ...@@ -231,10 +241,12 @@ class Connection(ExportImport, object):
Applications seldom need to call this method, because objects Applications seldom need to call this method, because objects
are loaded transparently during attribute lookup. are loaded transparently during attribute lookup.
@return: persistent object get() raises KeyError if oid does not exist. It is possible
@rtype: L{IPersistent} that an object does not exist as of the current transaction,
@raise KeyError: If C{oid} does not exist. but existed in the past. It may even exist again in the future, if
@raise RuntimeError: If the connection is closed. the transaction that removed it is undone.
get() raises RuntimeError if the connectio is closed.
""" """
if self._storage is None: if self._storage is None:
# XXX Should this be a ZODB-specific exception? # XXX Should this be a ZODB-specific exception?
...@@ -262,26 +274,26 @@ class Connection(ExportImport, object): ...@@ -262,26 +274,26 @@ class Connection(ExportImport, object):
__getitem__ = get __getitem__ = get
def add(self, obj): def add(self, obj):
"""Add a new object C{obj} to the database and assign it an oid. """Add a new object 'obj' to the database and assign it an oid.
A persistent object is normally added to the database and A persistent object is normally added to the database and
assigned an oid when it becomes reachable an object already in assigned an oid when it becomes reachable an object already in
the database. In some cases, it is useful to create a new the database. In some cases, it is useful to create a new
object and uses its oid (C{_p_oid}) in a single transaction. object and uses its oid (_p_oid) in a single transaction.
This method assigns a new oid regardless of whether the object This method assigns a new oid regardless of whether the object
is reachable. is reachable.
The object is added when the transaction commits. The object The object is added when the transaction commits. The object
must implement the L{IPersistent} interface and must not must implement the IPersistent interface and must not
already be associated with a L{Connection}. already be associated with a Connection.
add() raises TypeError if obj is not a persistent object.
@param obj: the object to add add() raises InvalidObjectReference if obj is already associated
@type obj: L{IPersistent}
@raise TypeError: If C{obj} is not a persistent object.
@raise InvalidObjectReference: If C{obj} is already associated
with another connection. with another connection.
@raise RuntimeError: If the connection is closed.
add() raises RuntimeError if the connection is closed.
""" """
if self._storage is None: if self._storage is None:
# XXX Should this be a ZODB-specific exception? # XXX Should this be a ZODB-specific exception?
...@@ -312,16 +324,13 @@ class Connection(ExportImport, object): ...@@ -312,16 +324,13 @@ class Connection(ExportImport, object):
return "%s:%s" % (storage_key, id(self)) return "%s:%s" % (storage_key, id(self))
def _setDB(self, odb): def _setDB(self, odb):
"""Register C{odb}, the L{DB} that this Connection uses. """Register odb, the DB that this Connection uses.
This method is called by the L{DB} every time a C{Connection} This method is called by the DB every time a Connection
is opened. Any invalidations received while the C{Connection} is opened. Any invalidations received while the Connection
was closed will be processed. was closed will be processed.
If L{resetCaches} was caused, the cache will be cleared. If resetCaches() was called, the cache will be cleared.
@param odb: the database that owns the C{Connection}
@type L{DB}
""" """
# XXX Why do we go to all the trouble of setting _db and # XXX Why do we go to all the trouble of setting _db and
...@@ -391,8 +400,8 @@ class Connection(ExportImport, object): ...@@ -391,8 +400,8 @@ class Connection(ExportImport, object):
it into a ghost. It is possible for individual objects to it into a ghost. It is possible for individual objects to
remain active. remain active.
@param dt: The dt argument is provided only for backwards The dt argument is provided only for backwards compatibility.
compatibility. It is ignored. It is ignored.
""" """
if dt is not None: if dt is not None:
warnings.warn("The dt argument to cacheMinimize is ignored.", warnings.warn("The dt argument to cacheMinimize is ignored.",
...@@ -410,9 +419,9 @@ class Connection(ExportImport, object): ...@@ -410,9 +419,9 @@ class Connection(ExportImport, object):
__onCloseCallbacks = None __onCloseCallbacks = None
def onCloseCallback(self, f): def onCloseCallback(self, f):
"""Register a callable C{f} to be called by L{close}. """Register a callable, f, to be called by close().
The callable C{f} will be called at most once, the next time The callable, f, will be called at most once, the next time
the Connection is closed. the Connection is closed.
""" """
if self.__onCloseCallbacks is None: if self.__onCloseCallbacks is None:
...@@ -420,15 +429,15 @@ class Connection(ExportImport, object): ...@@ -420,15 +429,15 @@ class Connection(ExportImport, object):
self.__onCloseCallbacks.append(f) self.__onCloseCallbacks.append(f)
def close(self): def close(self):
"""Close the C{Connection}. """Close the Connection.
A closed C{Connection} should not be used by client code. It A closed Connection should not be used by client code. It
can't load or store objects. Objects in the cache are not can't load or store objects. Objects in the cache are not
freed, because C{Connections} are re-used and the cache are freed, because Connections are re-used and the cache are
expected to be useful to the next client. expected to be useful to the next client.
When the Connection is closed, all callbacks registered by When the Connection is closed, all callbacks registered by
L{onCloseCallback} are invoked and the cache is scanned for onCloseCallback() are invoked and the cache is scanned for
old objects. old objects.
""" """
if self._cache is not None: if self._cache is not None:
...@@ -605,20 +614,17 @@ class Connection(ExportImport, object): ...@@ -605,20 +614,17 @@ class Connection(ExportImport, object):
return self._storage.isReadOnly() return self._storage.isReadOnly()
def invalidate(self, tid, oids): def invalidate(self, tid, oids):
"""Notify the Connection that C{tid} Invalidated C{oids}. """Notify the Connection that transaction 'tid' invalidated oids.
When the next transaction boundary is reached, objects will be When the next transaction boundary is reached, objects will be
invalidated. If any of the invalidated objects is accessed by invalidated. If any of the invalidated objects is accessed by
the current transaction, the revision written before C{tid} the current transaction, the revision written before C{tid}
will be used. will be used.
The L{DB} calls this method, even when the C{Connection} is The DB calls this method, even when the Connection is closed.
closed.
@param tid: id of transaction that committed tid is the storage-level id of the transaction that committed.
@type tid: C{string} oids is a set of oids, represented as a dict with oids as keys.
@param oids: set of oids
@type oids: C{dict} with oids as keys
""" """
self._inv_lock.acquire() self._inv_lock.acquire()
try: try:
...@@ -649,10 +655,12 @@ class Connection(ExportImport, object): ...@@ -649,10 +655,12 @@ class Connection(ExportImport, object):
return self._version return self._version
def register(self, obj): def register(self, obj):
"""Register C{obj} with the current transaction manager. """Register obj with the current transaction manager.
A subclass could override this method to customize the default A subclass could override this method to customize the default
policy of one transaction manager for each thread. policy of one transaction manager for each thread.
obj must be an object loaded from this Connection.
""" """
assert obj._p_jar is self assert obj._p_jar is self
if obj._p_oid is None: if obj._p_oid is None:
...@@ -669,10 +677,9 @@ class Connection(ExportImport, object): ...@@ -669,10 +677,9 @@ class Connection(ExportImport, object):
self.getTransaction().register(obj) self.getTransaction().register(obj)
def root(self): def root(self):
"""Get the database root object. """Return the database root object.
@return: the database root object The root is a PersistentDict.
@rtype: C{persistent.dict.PersistentDict}
""" """
return self.get(z64) return self.get(z64)
...@@ -799,15 +806,14 @@ class Connection(ExportImport, object): ...@@ -799,15 +806,14 @@ class Connection(ExportImport, object):
raise ReadConflictError(object=obj) raise ReadConflictError(object=obj)
def oldstate(self, obj, tid): def oldstate(self, obj, tid):
"""Return copy of C{obj} that was written by C{tid}. """Return copy of obj that was written by tid.
@param obj: the persistent object to retrieve an old revision of obj is a persistent object from this Connection. An earlier
@type obj: L{IPersistent} version of obj's state will be loaded using tid, the id of a
@param tid: id of transaction that wrote revision transaction that wrote an earlier revision.
@type tid: C{string}
@raise KeyError: If C{tid} does not exist or if C{tid} deleted oldstate() raises KeyError if tid does not exist or if tid deleted
a revision of C{obj} a revision of obj.
""" """
assert obj._p_jar is self assert obj._p_jar is self
p = self._storage.loadSerial(obj._p_oid, tid) p = self._storage.loadSerial(obj._p_oid, tid)
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
############################################################################## ##############################################################################
"""Database objects """Database objects
$Id: DB.py,v 1.68 2004/03/02 15:36:40 jeremy Exp $""" $Id: DB.py,v 1.69 2004/03/04 19:48:04 jeremy Exp $"""
import cPickle, cStringIO, sys import cPickle, cStringIO, sys
from thread import allocate_lock from thread import allocate_lock
...@@ -29,38 +29,27 @@ from zLOG import LOG, ERROR ...@@ -29,38 +29,27 @@ from zLOG import LOG, ERROR
class DB(object): class DB(object):
"""The Object Database """The Object Database
The C{DB} class coordinates the activities of multiple database The DB class coordinates the activities of multiple database
L{Connection} instances. Most of the work is done by the Connection instances. Most of the work is done by the
C{Connections} created via the L{open} method. Connections created via the open method.
The C{DB} instance manages a pool of connections. If a connection The DB instance manages a pool of connections. If a connection is
is closed, it is returned to the pool and its object cache is closed, it is returned to the pool and its object cache is
preserved. A subsequent call to open() will reuse the connection. preserved. A subsequent call to open() will reuse the connection.
There is a limit to the pool size; if all its connections are in There is a limit to the pool size; if all its connections are in
use, calls to open() will block until one of the open connections use, calls to open() will block until one of the open connections
is closed. is closed.
@cvar klass: Class used by L{open} to create database connections The class variable 'klass' is used by open() to create database
@type klass: L{Connection} or a subclass connections. It is set to Connection, but a subclass could override
it to provide a different connection implementation.
@group User Methods: __init__, open, close, undo, pack, setClassFactory
@group Inspection Methods: getName, getSize, objectCount, The database provides a few methods intended for application code
getActivityMonitor, setActivityMonitor -- open, close, undo, pack, setClassFactory -- and a large
@group Connection Pool Methods: getPoolSize, getVersionPoolSize, collection of methods for inspecting the database and its connections'
removeVersionPool, setPoolSize, setVersionPoolSize caches.
@group Transaction Methods: invalidate
@group Other Methods: lastTransaction, connectionDebugInfo
@group Version Methods: modifiedInVersion, abortVersion, commitVersion,
versionEmpty
@group Cache Inspection Methods: cacheDetail, cacheExtremeDetail,
cacheFullSweep, cacheLastGCTime, cacheMinimize, cacheMeanAge,
cacheMeanDeac, cacheMeanDeal, cacheSize, cacheDetailSize,
getCacheSize, getVersionCacheSize, setCacheSize, setVersionCacheSize,
cacheStatistics
@group Deprecated Methods: getCacheDeactivateAfter,
setCacheDeactivateAfter,
getVersionCacheDeactivateAfter, setVersionCacheDeactivateAfter
""" """
klass = Connection # Class to use for connections klass = Connection # Class to use for connections
_activity_monitor = None _activity_monitor = None
...@@ -74,18 +63,17 @@ class DB(object): ...@@ -74,18 +63,17 @@ class DB(object):
): ):
"""Create an object database. """Create an object database.
@param storage: storage for the database, e.g. C{FileStorage} The constructor requires one argument, the storage used by the
@param pool_size: maximum number of open connections database, e.g. FileStorage.
@type pool_size: C{int}
@param cache_size: target size of L{Connection} object cache There are several other optional arguments:
@type cache_size: C{int} pool_size: maximum number of open connections
@param cache_deactivate_after: ignored cache_size: target size of Connection object cache
@param version_pool_size: maximum number of connections (per version) cache_deactivate_after: ignored
@type version_pool_size: C{int} version_pool_size: maximum number of connections (per version)
@param version_cache_size: target size of L{Connection} object version_cache_size: target size of Connection object cache for
cache for version connectios version connections
@type version_cache_size: C{int} version_cache_deactivate_after: ignored
@param version_cache_deactivate_after: ignored
""" """
# Allocate locks: # Allocate locks:
l=allocate_lock() l=allocate_lock()
...@@ -209,7 +197,8 @@ class DB(object): ...@@ -209,7 +197,8 @@ class DB(object):
def cacheDetail(self): def cacheDetail(self):
"""Return information on objects in the various caches """Return information on objects in the various caches
Organized by class.""" Organized by class.
"""
detail = {} detail = {}
def f(con, detail=detail, have_detail=detail.has_key): def f(con, detail=detail, have_detail=detail.has_key):
...@@ -386,7 +375,7 @@ class DB(object): ...@@ -386,7 +375,7 @@ class DB(object):
def open(self, version='', transaction=None, temporary=0, force=None, def open(self, version='', transaction=None, temporary=0, force=None,
waitflag=1, mvcc=True): waitflag=1, mvcc=True):
"""Return a database L{Connection} """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
version connection is desired. version connection is desired.
...@@ -396,8 +385,9 @@ class DB(object): ...@@ -396,8 +385,9 @@ class DB(object):
terminated. In addition, connections per transaction are terminated. In addition, connections per transaction are
reused, if possible. reused, if possible.
Note that the connection pool is managed as a stack, to increate the Note that the connection pool is managed as a stack, to
likelihood that the connection's stack will include useful objects. increate the likelihood that the connection's stack will
include useful objects.
""" """
self._a() self._a()
try: try:
...@@ -562,14 +552,16 @@ class DB(object): ...@@ -562,14 +552,16 @@ class DB(object):
The cost of this operation varies by storage, but it is The cost of this operation varies by storage, but it is
usually an expensive operation. usually an expensive operation.
@param t: pack time in seconds since the epoch There are two optional arguments that can be used to set the
@type t: C{float} pack time: t, pack time in seconds since the epcoh, and days,
@param days: days to subtract from C{t} to compute pack time the number of days to substract from t or from the current
@type days: C{int} time if t is not specified.
""" """
if t is None: t=time() if t is None:
t=t-(days*86400) t = time()
try: self._storage.pack(t,referencesf) t -= days * 86400
try:
self._storage.pack(t, referencesf)
except: except:
LOG("ZODB", ERROR, "packing", error=sys.exc_info()) LOG("ZODB", ERROR, "packing", error=sys.exc_info())
raise raise
...@@ -588,14 +580,11 @@ class DB(object): ...@@ -588,14 +580,11 @@ class DB(object):
The database stores objects, but uses Python's standard import The database stores objects, but uses Python's standard import
to load the code for those objects. The class factory is used to load the code for those objects. The class factory is used
by the database serialization layer to find the classes. It by the database serialization layer to find the classes. It
uses L{ZODB.broken.find_global<find_global>} by default. uses ZODB.broken.find_global by default.
This method can be used to override the default class loading This method can be used to override the default class loading
code. See L{ZODB.broken.find_global<find_global>} for details code. See ZODB.broken.find_global for details
about the contract of C{factory}. about the contract of factory.
@param factory: A class factory for unpickling
@type factory: C{function}
""" """
self._classFactory = factory self._classFactory = factory
...@@ -617,21 +606,20 @@ class DB(object): ...@@ -617,21 +606,20 @@ class DB(object):
def cacheStatistics(self): return () # :( def cacheStatistics(self): return () # :(
def undo(self, id, transaction=None): def undo(self, id, transaction=None):
"""Undo a transaction identified by C{id}. """Undo a transaction identified by id.
A transaction can be undone if all of the objects involved in A transaction can be undone if all of the objects involved in
the transaction were not modified subsequently, if any the transaction were not modified subsequently, if any
modifications can be resolved by conflict resolution, or if modifications can be resolved by conflict resolution, or if
subsequent changes resulted in the same object state. subsequent changes resulted in the same object state.
The value of C{id} should be generated by calling C{undoLog} The value of id should be generated by calling undoLog()
or C{undoInfo}. The value of C{id} is not the same as a or undoInfo(). The value of id is not the same as a
transaction id used by other methods; it is unique to C{undo}. transaction id used by other methods; it is unique to undo().
@param id: a storage-specific transaction identifier In addition, a user can pass the optional argument,
@type id: C{string} transaction, which identifies a transaction context to use for
@param transaction: a transaction context to use the undo().
@type transaction: C{Transaction}
""" """
if transaction is None: if transaction is None:
transaction = get_transaction() transaction = get_transaction()
......
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