[Zope-CVS] CVS: Products/Ape/lib/apelib/zodb3 -
connection.py:1.6.2.1 db.py:1.5.2.1 interfaces.py:1.1.8.1
oidencoder.py:NONE
Shane Hathaway
shane at zope.com
Sat Dec 13 23:25:18 EST 2003
Update of /cvs-repository/Products/Ape/lib/apelib/zodb3
In directory cvs.zope.org:/tmp/cvs-serv28325/zodb3
Modified Files:
Tag: ape-0_8-branch
connection.py db.py interfaces.py
Removed Files:
Tag: ape-0_8-branch
oidencoder.py
Log Message:
Continued refactoring to fit new names.
=== Products/Ape/lib/apelib/zodb3/connection.py 1.6 => 1.6.2.1 ===
--- Products/Ape/lib/apelib/zodb3/connection.py:1.6 Wed Jul 30 17:33:12 2003
+++ Products/Ape/lib/apelib/zodb3/connection.py Sat Dec 13 23:24:47 2003
@@ -33,7 +33,7 @@
from consts import HASH0, DEBUG
from apelib.core.io import ObjectSystemIO, ClassifiedState
-from apelib.core.interfaces import IKeyedObjectSystem
+from apelib.core.interfaces import IObjectDatabase
class ApeConnection (Connection):
@@ -49,7 +49,7 @@
_osio = None
_scan_ctl = None
- __implements__ = (IKeyedObjectSystem,
+ __implements__ = (IObjectDatabase,
getattr(Connection, '__implements__', ()))
@@ -69,8 +69,8 @@
def getObjectSystemIO(self):
osio = self._osio
if osio is None:
- root_mapper = self._db._mapper_resource.access(self)
- osio = ObjectSystemIO(root_mapper, self)
+ conf = self._db._conf_resource.access(self)
+ osio = ObjectSystemIO(conf, self)
self._osio = osio
return osio
@@ -82,7 +82,7 @@
finally:
if db is not None and self._osio is not None:
self._osio = None
- db._mapper_resource.release(self)
+ db._conf_resource.release(self)
def __getitem__(self, oid, tt=type(())):
@@ -103,17 +103,17 @@
raise "Could not load oid %s, pickled data in traceback info may\
contain clues" % (oid)
osio = self.getObjectSystemIO()
- object = osio.newObject(classified_state)
- assert object is not None
+ obj = osio.newObject(classified_state)
+ assert obj is not None
- object._p_oid=oid
- object._p_jar=self
- object._p_changed=None
+ obj._p_oid=oid
+ obj._p_jar=self
+ obj._p_changed=None
- self._cache[oid] = object
+ self._cache[oid] = obj
if oid=='\0\0\0\0\0\0\0\0':
- self._root_=object # keep a ref
- return object
+ self._root_=obj # keep a ref
+ return obj
def _persistent_load(self, oid, hints=None):
@@ -125,17 +125,17 @@
return obj
if hints:
- mapper_names = hints.get('mapper_names')
- if mapper_names is not None:
- classified_state = ClassifiedState(None, None, mapper_names)
+ mapper_name = hints.get('mapper_name')
+ if mapper_name is not None:
+ classified_state = ClassifiedState(None, None, mapper_name)
osio = self.getObjectSystemIO()
- object = osio.newObject(classified_state)
- if object is not None:
- object._p_oid=oid
- object._p_jar=self
- object._p_changed=None
- self._cache[oid] = object
- return object
+ obj = osio.newObject(classified_state)
+ if obj is not None:
+ obj._p_oid=oid
+ obj._p_jar=self
+ obj._p_changed=None
+ self._cache[oid] = obj
+ return obj
# We don't have enough info for fast loading. Load the whole object.
return self[oid]
@@ -147,8 +147,8 @@
self._begun = 1
- def commit(self, object, transaction):
- if object is self:
+ def commit(self, obj, transaction):
+ if obj is self:
self.mayBegin(transaction)
# We registered ourself. Execute a commit action, if any.
if self._Connection__onCommitActions is not None:
@@ -156,8 +156,8 @@
self._Connection__onCommitActions.pop(0)
apply(getattr(self, method_name), (transaction,) + args, kw)
return
- oid=object._p_oid
- assert oid != 'unmanaged', repr(object)
+ oid=obj._p_oid
+ assert oid != 'unmanaged', repr(obj)
#invalid=self._invalidated.get
invalid = self._invalid
@@ -165,20 +165,20 @@
if modified is None:
modified = self._invalidating
- if oid is None or object._p_jar is not self:
+ if oid is None or obj._p_jar is not self:
# new object
oid = self.new_oid()
- object._p_jar=self
- object._p_oid=oid
+ obj._p_jar=self
+ obj._p_oid=oid
self._creating.append(oid)
- elif object._p_changed:
+ elif obj._p_changed:
if (
- (invalid(oid) and not hasattr(object, '_p_resolveConflict'))
+ (invalid(oid) and not hasattr(obj, '_p_resolveConflict'))
or
invalid(None)
):
- raise ConflictError(object=object)
+ raise ConflictError(object=obj)
modified.append(oid)
else:
@@ -187,7 +187,7 @@
self.mayBegin(transaction)
- stack=[object]
+ stack=[obj]
file=StringIO()
seek=file.seek
@@ -205,11 +205,11 @@
version=self._version
while stack:
- object=stack[-1]
+ obj=stack[-1]
del stack[-1]
- oid=object._p_oid
- assert oid != 'unmanaged', repr(object)
- serial = self.getSerial(object)
+ oid=obj._p_oid
+ assert oid != 'unmanaged', repr(obj)
+ serial = self.getSerial(obj)
if serial == HASH0:
# new object
self._creating.append(oid)
@@ -219,29 +219,27 @@
# for the first object on the stack.
if (
(invalid(oid) and
- not hasattr(object, '_p_resolveConflict'))
+ not hasattr(obj, '_p_resolveConflict'))
or
invalid(None)
):
- raise ConflictError(object=object)
+ raise ConflictError(object=obj)
modified.append(oid)
# SDH: hook in the serializer.
- # state=object.__getstate__()
- oid_encoder = self._db._oid_encoder
- keychain = oid_encoder.decode(oid)
+ # state=obj.__getstate__()
osio = self.getObjectSystemIO()
- event, classified_state = osio.serialize(keychain, object)
- ext_refs = event.getExternalRefs()
+ event, classified_state = osio.serialize(oid, obj)
+ ext_refs = event.external
if ext_refs:
- for (ext_keychain, ext_ref) in ext_refs:
+ for (ext_oid, ext_ref) in ext_refs:
if self.getSerial(ext_ref) == HASH0:
- ext_oid = oid_encoder.encode(ext_keychain)
+ # New object
if ext_ref._p_jar is not None:
if ext_ref._p_jar is not self:
raise InvalidObjectReference, (
"Can't refer from %s in %s to %s in %s"
- % (repr(object), repr(self), repr(ext_ref),
+ % (repr(obj), repr(self), repr(ext_ref),
repr(ext_ref._p_jar)))
else:
ext_ref._p_jar = self
@@ -252,9 +250,8 @@
ext_ref._p_oid = ext_oid
stack.append(ext_ref)
- unmanaged = event.getUnmanagedPersistentObjects()
- if unmanaged:
- self.handleUnmanaged(object, unmanaged)
+ if event.upos:
+ self.handleUnmanaged(obj, event.upos)
seek(0)
clear_memo()
@@ -266,7 +263,7 @@
# Put the object in the cache before handling the
# response, just in case the response contains the
# serial number for a newly created object
- try: cache[oid] = object
+ try: cache[oid] = obj
except ValueError:
# "Cannot re-register an object under a different
# oid". This can happen when the user is working on
@@ -274,20 +271,20 @@
# was used recently. Try to fix it by minimizing
# the cache and trying again.
cache.minimize()
- cache[oid] = object
+ cache[oid] = obj
except:
- if aq_base(object) is not object:
+ if aq_base(obj) is not obj:
# Yuck, someone tried to store a wrapper. Try to
# cache it unwrapped.
- cache[oid] = aq_base(object)
+ cache[oid] = aq_base(obj)
else:
raise
self._handle_serial(s, oid)
- def setstate(self, object):
- oid=object._p_oid
+ def setstate(self, obj):
+ oid=obj._p_oid
if self._storage is None:
msg = ("Shouldn't load state for %s "
@@ -312,9 +309,9 @@
#invalid = self._invalidated.get
invalid = self._invalid
if invalid(oid) or invalid(None):
- if not hasattr(object.__class__, '_p_independent'):
+ if not hasattr(obj.__class__, '_p_independent'):
get_transaction().register(self)
- raise ReadConflictError(object=object)
+ raise ReadConflictError(object=obj)
invalid=1
else:
invalid=0
@@ -331,23 +328,21 @@
# else:
# d=object.__dict__
# for k,v in state.items(): d[k]=v
- keychain = self._db._oid_encoder.decode(oid)
osio = self.getObjectSystemIO()
- event = osio.deserialize(keychain, object, classified_state)
+ event = osio.deserialize(oid, obj, classified_state)
- unmanaged = event.getUnmanagedPersistentObjects()
- if unmanaged:
- self.handleUnmanaged(object, unmanaged)
+ if event.upos:
+ self.handleUnmanaged(obj, event.upos)
- self.setSerial(object, serial)
+ self.setSerial(obj, serial)
if invalid:
- if object._p_independent():
+ if obj._p_independent():
try: del self._invalidated[oid]
except KeyError: pass
else:
get_transaction().register(self)
- raise ConflictError(object=object)
+ raise ConflictError(object=obj)
except ConflictError:
raise
@@ -357,12 +352,12 @@
raise
- def register(self, object):
+ def register(self, obj):
"""Register an object with the appropriate transaction manager.
"""
- assert object._p_jar is self
- if object._p_oid is not None:
- get_transaction().register(object)
+ assert obj._p_jar is self
+ if obj._p_oid is not None:
+ get_transaction().register(obj)
# else someone is trying to trick ZODB into registering an
# object with no OID. OFS.Image.File._read_data() does this.
# Since ApeConnection really needs meaningful OIDs, just ignore
@@ -377,24 +372,23 @@
return '<%s at %08x%s>' % (self.__class__.__name__, id(self), ver)
- def handleUnmanaged(self, object, unmanaged):
+ def handleUnmanaged(self, obj, unmanaged):
+ # Add an event handler to unmanaged subobjects.
+ # The event handler calls self.register() when it changes.
for o in unmanaged:
if isinstance(o, Persistent):
if o._p_jar is None:
o._p_oid = 'unmanaged'
- o._p_jar = UnmanagedJar(self, object._p_oid)
+ o._p_jar = UnmanagedJar(self, obj._p_oid)
else:
- # Turn off the "changed" flag
o._p_changed = 0
- # IKeyedObjectSystem implementation
+ # IObjectDatabase implementation
- def getObject(self, keychain, hints=None):
- oid = self._db._oid_encoder.encode(keychain)
- return self._persistent_load(oid, hints)
+ getObject = _persistent_load
- def identifyObject(self, obj):
+ def identify(self, obj):
oid = obj._p_oid
if oid is None:
return None
@@ -402,14 +396,7 @@
raise InvalidObjectReference, (
"Can't refer to %s, located in %s, from %s"
% (repr(obj), repr(obj._p_jar), repr(self)))
- return self._db._oid_encoder.decode(oid)
-
- def newKey(self):
- oid = self.new_oid()
- keychain = self._db._oid_encoder.decode(oid)
- return keychain[-1]
-
- loadStub = getObject # Deprecated
+ return oid
def getClass(self, module, name):
@@ -426,11 +413,9 @@
if ob._p_changed is not None:
p, serial = self._storage.load(oid, self._version)
if serial != self.getSerial(ob):
- keychain = self._db._oid_encoder.decode(oid)
raise StorageError(
- "Inconsistent serial for keychain %s" % repr(keychain))
+ "Inconsistent serial for oid %s" % repr(oid))
-
def exportFile(self, oid, file=None):
raise NotImplementedError, 'ZEXP Export not implemented'
=== Products/Ape/lib/apelib/zodb3/db.py 1.5 => 1.5.2.1 ===
--- Products/Ape/lib/apelib/zodb3/db.py:1.5 Thu Aug 14 16:22:36 2003
+++ Products/Ape/lib/apelib/zodb3/db.py Sat Dec 13 23:24:47 2003
@@ -18,18 +18,16 @@
from ZODB.DB import DB, Transaction, cPickle, cStringIO, allocate_lock
-from apelib.core.interfaces import IMapper
-from apelib.core.exceptions import ConfigurationError
+from apelib.core.interfaces import ConfigurationError
from connection import ApeConnection
from storage import ApeStorage
-from oidencoder import OIDEncoder
from resource import StaticResource
-from interfaces import IResourceAccess, IOIDEncoder
+from interfaces import IResourceAccess
-def callMapperFactory(factory, kw):
- """Returns (mapper, tpc_conns) given the name of a factory and arguments.
+def callConfFactory(factory, kw):
+ """Returns (conf, conns) given the name of a factory and arguments.
"""
pos = factory.rfind('.')
if pos < 0:
@@ -50,9 +48,8 @@
# SDH: some extra args.
def __init__(self, storage,
- mapper_resource=None,
+ conf_resource=None,
factory=None,
- oid_encoder=None,
scan_interval=10,
pool_size=7,
cache_size=400,
@@ -64,25 +61,25 @@
):
"""Create an object database.
"""
- if mapper_resource is None:
+ if conf_resource is None:
if factory is not None:
- # Use a mapper factory
- mapper, connections = callMapperFactory(factory, kw)
- assert IMapper.isImplementedBy(mapper)
- mapper_resource = StaticResource(mapper)
+ # Use a configuration factory
+ conf, connections = callConfFactory(factory, kw)
+ conf_resource = StaticResource(conf)
else:
if kw:
raise ConfigurationError('Extra keyword args: %s' % kw)
if isinstance(storage, ApeStorage):
- # Use the mapper from the storage
- mapper_resource = storage.getMapperResource()
+ # Use the configuration from the storage
+ conf_resource = storage.getConfResource()
else:
- raise ConfigurationError('No mapper or factory specified')
+ raise ConfigurationError(
+ 'No configuration or factory specified')
else:
- # mapper_resource was specified
+ # conf_resource was specified
if kw:
raise ConfigurationError('Extra keyword args: %s' % kw)
- assert IResourceAccess.isImplementedBy(mapper_resource)
+ assert IResourceAccess.isImplementedBy(conf_resource)
assert factory is None
# Allocate locks:
@@ -107,12 +104,7 @@
storage.registerDB(self, None)
if not hasattr(storage,'tpc_vote'): storage.tpc_vote=lambda *args: None
- if oid_encoder is None:
- oid_encoder = OIDEncoder()
- else:
- assert IOIDEncoder.isImplementedBy(oid_encoder)
- self._oid_encoder = oid_encoder
- self._mapper_resource = mapper_resource
+ self._conf_resource = conf_resource
scan_interval = int(scan_interval)
if scan_interval > 0:
from scanner import ScanControl
=== Products/Ape/lib/apelib/zodb3/interfaces.py 1.1 => 1.1.8.1 ===
--- Products/Ape/lib/apelib/zodb3/interfaces.py:1.1 Wed Apr 9 23:09:58 2003
+++ Products/Ape/lib/apelib/zodb3/interfaces.py Sat Dec 13 23:24:47 2003
@@ -19,15 +19,6 @@
from Interface import Interface
-class IOIDEncoder (Interface):
-
- def decode(oid):
- "Returns a keychain (a tuple) given an OID"
-
- def encode(keychain):
- "Returns an OID (a string) given a keychain"
-
-
class IResourceAccess (Interface):
"""Provides access to a resource that may need periodic updates.
"""
=== Removed File Products/Ape/lib/apelib/zodb3/oidencoder.py ===
More information about the Zope-CVS
mailing list