Commit b4d418aa authored by Barry Warsaw's avatar Barry Warsaw

__init__(): Add back the ability to pass in your own DBEnv object for

the environment.  No type checking is done, except that if env is not
a string or not None, then it's the caller's responsibility to pass in
a valid DBEnv.
parent a07a3c37
...@@ -25,7 +25,7 @@ from bsddb3 import db ...@@ -25,7 +25,7 @@ from bsddb3 import db
from ZODB import POSException from ZODB import POSException
from ZODB.BaseStorage import BaseStorage from ZODB.BaseStorage import BaseStorage
__version__ = '$Revision: 1.12 $'.split()[-2:][0] __version__ = '$Revision: 1.13 $'.split()[-2:][0]
...@@ -38,12 +38,22 @@ class BerkeleyBase(BaseStorage): ...@@ -38,12 +38,22 @@ class BerkeleyBase(BaseStorage):
name is an arbitrary name for this storage. It is returned by the name is an arbitrary name for this storage. It is returned by the
getName() method. getName() method.
Optional env is the database environment name, essentially the name of Optional env, if given, is either a string or a DBEnv object. If it
a directory into which BerkeleyDB will store all its supporting files. is a non-empty string, it names the database environment,
If env is a non-empty string, it is passed directly to DbEnv().open(), i.e. essentially the name of a directory into which BerkeleyDB will
which in turn is passed to the BerkeleyDB function store all its supporting files. It is passed directly to
DbEnv().open(), which in turn is passed to the BerkeleyDB function
DBEnv->open() as the db_home parameter. DBEnv->open() as the db_home parameter.
Note that if you want to customize the underlying Berkeley DB
parameters, this directory can contain a DB_CONFIG file as per the
Sleepycat documentation.
If env is given and it is not a string, it must be an opened DBEnv
object as returned by bsddb3.db.DBEnv(). In this case, it is your
responsibility to create the object and open it with the proper
flags.
Optional prefix is the string to prepend to name when passed to Optional prefix is the string to prepend to name when passed to
DB.open() as the dbname parameter. IOW, prefix+name is passed to the DB.open() as the dbname parameter. IOW, prefix+name is passed to the
BerkeleyDb function DB->open() as the database parameter. It defaults BerkeleyDb function DB->open() as the database parameter. It defaults
...@@ -59,19 +69,14 @@ class BerkeleyBase(BaseStorage): ...@@ -59,19 +69,14 @@ class BerkeleyBase(BaseStorage):
if env == '': if env == '':
raise TypeError, 'environment name is empty' raise TypeError, 'environment name is empty'
elif not isinstance(env, StringType): elif isinstance(env, StringType):
# We used to test isinstance(env, db.DBEnv) but that isn't a valid self._env = env_from_string(env)
# test since db.DBEnv() is a factory function, not a class. else:
# AFAIK, there's no way to pass an existing DBEnv into this self._env = env
# constructor. Note that the most likely reason for wanting to do
# this is to increase the lock size of the environment. Use a
# DB_CONFIG file for that instead (see www.sleepycat.com).
raise TypeError, 'env must be a string: %s' % env
BaseStorage.__init__(self, name) BaseStorage.__init__(self, name)
# Initialize a few other things # Initialize a few other things
self._env = env_from_string(env)
self._prefix = prefix self._prefix = prefix
self._commitlog = None self._commitlog = None
# Give the subclasses a chance to interpose into the database setup # Give the subclasses a chance to interpose into the database setup
......
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