[Zope-CVS] CVS: Products/Ape/lib/apelib/zodb3 -
connection.py:1.6.2.3 db.py:1.5.2.2 scanner.py:1.2.2.2
serializers.py:1.3.2.3
Shane Hathaway
shane at zope.com
Sat Dec 20 02:31:38 EST 2003
Update of /cvs-repository/Products/Ape/lib/apelib/zodb3
In directory cvs.zope.org:/tmp/cvs-serv30479/zodb3
Modified Files:
Tag: ape-0_8-branch
connection.py db.py scanner.py serializers.py
Log Message:
Continued refactoring and renaming.
Over 60 tests now pass.
=== Products/Ape/lib/apelib/zodb3/connection.py 1.6.2.2 => 1.6.2.3 ===
--- Products/Ape/lib/apelib/zodb3/connection.py:1.6.2.2 Fri Dec 19 21:52:49 2003
+++ Products/Ape/lib/apelib/zodb3/connection.py Sat Dec 20 02:31:08 2003
@@ -23,7 +23,8 @@
from cPickle import Unpickler, Pickler
from Acquisition import aq_base
-from ZODB import Persistent
+from Persistence import Persistent
+from ZODB.Transaction import Transaction
from ZODB.POSException \
import ConflictError, ReadConflictError, InvalidObjectReference, \
StorageError
@@ -31,7 +32,7 @@
from ZODB.ConflictResolution import ResolvedSerial
from zLOG import LOG, ERROR
-from consts import HASH0, DEBUG
+from consts import ROOT_OID, HASH0, DEBUG
from apelib.core.io import ObjectSystemIO, ClassifiedState
from apelib.core.interfaces import IObjectDatabase
@@ -66,6 +67,25 @@
self._flush_invalidations()
+ def _prepareRoot(self):
+ oid = ROOT_OID
+ try:
+ self[oid]
+ except KeyError:
+ # Create the root object..
+ from Persistence import PersistentMapping
+ root = PersistentMapping()
+ root._p_jar = self
+ root._p_changed = 1
+ root._p_oid = oid
+ t = Transaction()
+ t.note('Initial database creation')
+ self.tpc_begin(t)
+ self.commit(root, t)
+ self.tpc_vote(t)
+ self.tpc_finish(t)
+
+
def getObjectSystemIO(self):
osio = self._osio
if osio is None:
@@ -389,7 +409,10 @@
getObject = _persistent_load
def identify(self, obj):
- oid = obj._p_oid
+ try:
+ oid = obj._p_oid
+ except AttributeError:
+ raise TypeError("%s does not subclass Persistent" % repr(obj))
if oid is None:
return None
if obj._p_jar is not self:
=== Products/Ape/lib/apelib/zodb3/db.py 1.5.2.1 => 1.5.2.2 ===
--- Products/Ape/lib/apelib/zodb3/db.py:1.5.2.1 Sat Dec 13 23:24:47 2003
+++ Products/Ape/lib/apelib/zodb3/db.py Sat Dec 20 02:31:08 2003
@@ -16,8 +16,10 @@
$Id$
"""
-from ZODB.DB import DB, Transaction, cPickle, cStringIO, allocate_lock
+import cPickle
+import cStringIO
+from ZODB.DB import DB, Transaction, allocate_lock
from apelib.core.interfaces import ConfigurationError
from connection import ApeConnection
@@ -123,4 +125,11 @@
if hasattr(storage, 'undoInfo'):
self.undoInfo=storage.undoInfo
+
+ # Create the root object if it doesn't exist
+ c = self.open()
+ try:
+ c._prepareRoot()
+ finally:
+ c.close()
=== Products/Ape/lib/apelib/zodb3/scanner.py 1.2.2.1 => 1.2.2.2 ===
--- Products/Ape/lib/apelib/zodb3/scanner.py:1.2.2.1 Wed Dec 17 23:43:54 2003
+++ Products/Ape/lib/apelib/zodb3/scanner.py Sat Dec 20 02:31:08 2003
@@ -251,9 +251,10 @@
# Update the sources with new states for the committed OIDs.
to_scan = {} # { repo -> { source -> state } }
for oid, sources in t.items():
- for source, state in sources.items():
- repo, location = source
- to_scan.setdefault(repo, {})[source] = state
+ if sources:
+ for source, state in sources.items():
+ repo, location = source
+ to_scan.setdefault(repo, {})[source] = state
changes = {}
for repo, d in to_scan.items():
c = repo.poll(d)
@@ -261,10 +262,11 @@
changes.update(c)
for oid, sources in t.items():
new_sources = {}
- for source, state in sources.items():
- state = changes.get(source, state)
- new_sources[source] = state
- self.setSources(oid, new_sources)
+ if sources:
+ for source, state in sources.items():
+ state = changes.get(source, state)
+ new_sources[source] = state
+ self.setPollSources(oid, new_sources)
def afterAbort(self, tid):
=== Products/Ape/lib/apelib/zodb3/serializers.py 1.3.2.2 => 1.3.2.3 ===
--- Products/Ape/lib/apelib/zodb3/serializers.py:1.3.2.2 Fri Dec 19 21:52:49 2003
+++ Products/Ape/lib/apelib/zodb3/serializers.py Sat Dec 20 02:31:08 2003
@@ -18,7 +18,7 @@
import os
from cStringIO import StringIO
-from cPickle import Pickler, Unpickler, UnpickleableError
+from cPickle import Pickler, Unpickler, UnpickleableError, loads, dumps
import time
from types import DictType
@@ -32,11 +32,11 @@
from apelib.core.schemas import RowSequenceSchema, FieldSchema
-class BasicPersistentMapping:
- """Basic PersistentMapping (de)serializer
+class StringToPersistentPM:
+ """String-to-Persistent PersistentMapping (de)serializer
- This version assumes the PM maps string keys to first-class
- persistent objects.
+ Requires that the PM maps string keys to first-class persistent
+ objects.
"""
__implements__ = ISerializer
@@ -68,6 +68,41 @@
event.obj.__init__(data)
+class StringToPicklePM:
+ """String-to-Pickle PersistentMapping (de)serializer
+
+ Requires that the PM maps string keys to second-class persistent
+ objects.
+ """
+ __implements__ = ISerializer
+
+ schema = RowSequenceSchema()
+ schema.addField('key', 'string', 1)
+ schema.addField('value', 'string')
+
+ def canSerialize(self, obj):
+ return isinstance(obj, PersistentMapping)
+
+ def serialize(self, event):
+ assert self.canSerialize(event.obj)
+ res = []
+ for key, value in event.obj.items():
+ res.append((key, dumps(value)))
+ event.serialized(key, value, False)
+ event.ignore(('data', '_container'))
+ return res
+
+ def deserialize(self, event, state):
+ assert self.canSerialize(event.obj)
+ data = {}
+ for (key, p) in state:
+ value = loads(p)
+ data[key] = value
+ event.deserialized(key, value)
+ event.obj.__init__(data)
+
+
+
##class FixedPersistentMapping:
## """Unchanging persistent mapping.
@@ -136,8 +171,8 @@
missed.append(repr(k))
if missed:
raise SerializationError(
- 'Attribute(s) %s of object at %s not serialized' %
- (', '.join(missed), repr(event.getOid())))
+ 'Attribute(s) %s of object %s, oid=%s, not serialized' %
+ (', '.join(missed), repr(event.obj), repr(event.oid)))
return None
def deserialize(self, event, state):
More information about the Zope-CVS
mailing list