Commit a8346702 authored by Jim Fulton's avatar Jim Fulton

Renamed DB.open to connection

Added an option to disallow cross-database references.
parent fcfee0d3
...@@ -331,20 +331,6 @@ def getTID(at, before): ...@@ -331,20 +331,6 @@ def getTID(at, before):
return before return before
class Methods(object):
def __init__(self, name, ifunc, cfunc=None):
self.__name__ = name
self.im_func = ifunc
self.cm_func = cfunc
def __get__(self, inst, class_):
if inst is None:
if self.cm_func is None:
raise AttributeError("Only in instances", self.__name__)
return self.cm_func.__get__(class_, type(class_))
return self.im_func.__get__(inst, class_)
class DB(object): class DB(object):
"""The Object Database """The Object Database
------------------- -------------------
...@@ -401,7 +387,7 @@ class DB(object): ...@@ -401,7 +387,7 @@ class DB(object):
historical_timeout=300, historical_timeout=300,
database_name='unnamed', database_name='unnamed',
databases=None, databases=None,
): xrefs=True):
"""Create an object database. """Create an object database.
:Parameters: :Parameters:
...@@ -419,6 +405,8 @@ class DB(object): ...@@ -419,6 +405,8 @@ class DB(object):
the historical connection. the historical connection.
- `historical_timeout`: minimum number of seconds that - `historical_timeout`: minimum number of seconds that
an unused historical connection will be kept, or None. an unused historical connection will be kept, or None.
- `xrefs` - Boolian flag indicating whether implicit cross-database
references are allowed
""" """
if isinstance(storage, basestring): if isinstance(storage, basestring):
from ZODB import FileStorage from ZODB import FileStorage
...@@ -490,6 +478,7 @@ class DB(object): ...@@ -490,6 +478,7 @@ class DB(object):
raise ValueError("database_name %r already in databases" % raise ValueError("database_name %r already in databases" %
database_name) database_name)
databases[database_name] = self databases[database_name] = self
self.xrefs = xrefs
self._setupUndoMethods() self._setupUndoMethods()
self.history = storage.history self.history = storage.history
...@@ -779,14 +768,6 @@ class DB(object): ...@@ -779,14 +768,6 @@ class DB(object):
finally: finally:
self._r() self._r()
def class_open(class_, *args, **kw):
db = class_(*args, **kw)
conn = db.open()
conn.onCloseCallback(db.close)
return conn
open = Methods('open', open, class_open)
def connectionDebugInfo(self): def connectionDebugInfo(self):
result = [] result = []
t = time.time() t = time.time()
...@@ -1010,3 +991,9 @@ class TransactionalUndo(ResourceManager): ...@@ -1010,3 +991,9 @@ class TransactionalUndo(ResourceManager):
# XXX see XXX in ResourceManager # XXX see XXX in ResourceManager
tid, oids = self._db.storage.undo(self._tid, t) tid, oids = self._db.storage.undo(self._tid, t)
self._db.invalidate(tid, dict.fromkeys(oids, 1)) self._db.invalidate(tid, dict.fromkeys(oids, 1))
def connection(*args, **kw):
db = DB(*args, **kw)
conn = db.open()
conn.onCloseCallback(db.close)
return conn
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