[Zope-CVS] CVS: Products/AdaptableStorage/zodb - ASConnection.py:1.4 ASStorage.py:1.4 OIDEncoder.py:1.4

Shane Hathaway shane@zope.com
Sat, 7 Dec 2002 00:59:15 -0500


Update of /cvs-repository/Products/AdaptableStorage/zodb
In directory cvs.zope.org:/tmp/cvs-serv21888/zodb

Modified Files:
	ASConnection.py ASStorage.py OIDEncoder.py 
Log Message:
Fixed the bugs in the new strategy (OIDs no longer include mapper_names, 
allowing more flexibility in loading and storage).  Did not resolve new
key generation yet, but everything else seems to be in good shape.


=== Products/AdaptableStorage/zodb/ASConnection.py 1.3 => 1.4 ===
--- Products/AdaptableStorage/zodb/ASConnection.py:1.3	Fri Dec  6 17:06:51 2002
+++ Products/AdaptableStorage/zodb/ASConnection.py	Sat Dec  7 00:59:14 2002
@@ -111,7 +111,7 @@
         return object
 
 
-    def _persistent_load(self, oid, class_info=None):
+    def _persistent_load(self, oid, mapper_names=None):
 
         __traceback_info__=oid
 
@@ -119,27 +119,19 @@
         if obj is not None:
             return obj
 
-        if class_info and class_info[1] is None:
-            klass = class_info[0]
-            # Quick instance reference.  We know all we need to know
-            # to create the instance wo hitting the db, so go for it!
-            if isinstance(klass, TupleType):
-                module, name = klass
-                try: klass=self._db._classFactory(self, module, name)
-                except:
-                    # Eek, we couldn't get the class. Hm.
-                    # Maybe there is more current data in the
-                    # object's actual record!
-                    return self[oid]
-
-            object=klass.__basicnew__()
-            object._p_oid=oid
-            object._p_jar=self
-            object._p_changed=None
-
-            self._cache[oid] = object
-
-            return object
+        if mapper_names is not None:
+            mapper = self.getRootMapper()
+            for mapper_name in mapper_names:
+                mapper = mapper.getSubMapper(mapper_name)
+            ser = mapper.getSerializer()
+            
+            object = ser.createEmptyInstance()
+            if object is not None:
+                object._p_oid=oid
+                object._p_jar=self
+                object._p_changed=None
+                self._cache[oid] = object
+                return object
 
         # We don't have enough info for fast loading.  Load the whole object.
         return self[oid]
@@ -271,22 +263,30 @@
                 keychain = self._db._oid_encoder.decode(oid)
                 mapper = self.getRootMapper()
                 mapper_names = []
-                for i in range(1, len(keychain)):
-                    k = keychain[:i]
-                    o = self[k]
+                oid_encoder = self._db._oid_encoder
+                classification = None
+                if keychain:
+                    # classify the parents.
+                    for i in range(1, len(keychain)):
+                        k = keychain[:i]
+                        o = self[oid_encoder.encode(k)]
+                        cfr = mapper.getClassifier()
+                        classification, sub_mapper_name = \
+                                        cfr.classifyObject(k, o)
+                        mapper_names.append(sub_mapper_name)
+                        mapper = mapper.getSubMapper(sub_mapper_name)
+                    # Now classify this object.
                     cfr = mapper.getClassifier()
-                    classification, sub_mapper_name = cfr.classifyObject(k, o)
+                    classification, sub_mapper_name = cfr.classifyObject(
+                        keychain, object)
                     mapper_names.append(sub_mapper_name)
                     mapper = mapper.getSubMapper(sub_mapper_name)
-                cfr = mapper.getClassifier()
-                classification, dummy_mapper_name = cfr.classifyObject(
-                    keychain, object)
+
                 ser = mapper.getSerializer()
                 if DEBUG:
                     print 'serializing', repr(oid), repr(serial)
                 state, ext_refs = ser.serialize(mapper, keychain, object, self)
                 if ext_refs:
-                    oid_encoder = self._db._oid_encoder
                     for (ext_keychain, ext_ref) in ext_refs:
                         if (not ext_ref._p_serial
                             or ext_ref._p_serial == SERIAL0):
@@ -371,7 +371,7 @@
             #     d=object.__dict__
             #     for k,v in state.items(): d[k]=v
             keychain = self._db._oid_encoder.decode(oid)
-            assert len(keychain) == len(mapper_names) + 1
+            assert len(keychain) == len(mapper_names)
             mapper = self.getRootMapper()
             for mapper_name in mapper_names:
                 mapper = mapper.getSubMapper(mapper_name)
@@ -415,9 +415,9 @@
 
     # IKeyedObjectSystem implementation
 
-    def loadStub(self, keychain, class_info=None):
+    def loadStub(self, keychain, mapper_names=None):
         oid = self._db._oid_encoder.encode(keychain)
-        return self._persistent_load(oid, class_info)
+        return self._persistent_load(oid, mapper_names)
 
     def identifyObject(self, object):
         oid = object._p_oid


=== Products/AdaptableStorage/zodb/ASStorage.py 1.3 => 1.4 ===
--- Products/AdaptableStorage/zodb/ASStorage.py:1.3	Fri Dec  6 17:06:51 2002
+++ Products/AdaptableStorage/zodb/ASStorage.py	Sat Dec  7 00:59:14 2002
@@ -73,20 +73,15 @@
         # The last item in the keychain is for the use by the gateway.
         # (In other words, we should expect there to be one more key
         # than domain changes.)
-        for i in range(1, len(keychain)):
-            k = keychain[:i]
+        classification = None
+        for i in range(len(keychain)):
+            k = keychain[:i + 1]
             cfr = mapper.getClassifier()
             assert cfr is not None, keychain
             classification, sub_mapper_name = cfr.classifyState(mapper, k)
             mapper_names.append(sub_mapper_name)
             mapper = mapper.getSubMapper(sub_mapper_name)
         full_state, serial = mapper.getGateway().load(mapper, keychain)
-        cfr = mapper.getClassifier()
-        if cfr is not None:
-            classification, dummy_mapper_name = cfr.classifyState(
-                mapper, keychain)
-        else:
-            classification = None
         return full_state, serial, classification, mapper_names
         
 
@@ -141,12 +136,13 @@
             u = Unpickler(file)
             classification, mapper_names = u.load()
             state = u.load()
-            assert len(keychain) == len(mapper_names) + 1
+            assert len(keychain) == len(mapper_names)
             mapper = root_mapper
+            cfr = mapper.getClassifier()
             for mapper_name in mapper_names:
+                cfr = mapper.getClassifier()
                 mapper = mapper.getSubMapper(mapper_name)
             new_serial = mapper.getGateway().store(mapper, keychain, state)
-            cfr = mapper.getClassifier()
             if cfr is not None:
                 cfr.store(mapper, keychain, classification)
             new_hash = self.hashSerial(new_serial)


=== Products/AdaptableStorage/zodb/OIDEncoder.py 1.3 => 1.4 ===
--- Products/AdaptableStorage/zodb/OIDEncoder.py:1.3	Fri Dec  6 17:13:23 2002
+++ Products/AdaptableStorage/zodb/OIDEncoder.py	Sat Dec  7 00:59:14 2002
@@ -32,7 +32,7 @@
     def decode(self, oid):
         """Returns a keychain."""
         if oid == ROOT_OID:
-            return ('',)
+            return ()
         keychain = loads(oid)
         assert isinstance(keychain, TupleType)
         return keychain
@@ -40,7 +40,7 @@
     def encode(self, keychain):
         """Returns an OID."""
         assert isinstance(keychain, TupleType)
-        if keychain == ('',):
+        if keychain == ():
             return ROOT_OID
         return dumps(keychain)