[Zope-CVS] CVS: Products/AdaptableStorage/serial - DeserializationEvent.py:1.2 EventBase.py:1.2 ObjectGateway.py:1.4 ObjectMapper.py:1.2 ObjectSerializer.py:1.2 RecordSchema.py:1.2 SerializationEvent.py:1.3

Shane Hathaway shane@zope.com
Fri, 6 Dec 2002 17:07:21 -0500


Update of /cvs-repository/Products/AdaptableStorage/serial
In directory cvs.zope.org:/tmp/cvs-serv8198/serial

Modified Files:
	DeserializationEvent.py EventBase.py ObjectGateway.py 
	ObjectMapper.py ObjectSerializer.py RecordSchema.py 
	SerializationEvent.py 
Log Message:
Experiment: removed mapper_name from OIDs, with the intent of allowing
loading and storage by different mappers depending on what the classifier
specifies.  Not yet complete.  Involved changes to virtually every module. :-)

I may decide to revert this.  The shane-before-mapper-name-removal tag
was added just before this checkin.


=== Products/AdaptableStorage/serial/DeserializationEvent.py 1.1 => 1.2 ===
--- Products/AdaptableStorage/serial/DeserializationEvent.py:1.1	Wed Nov 27 13:37:06 2002
+++ Products/AdaptableStorage/serial/DeserializationEvent.py	Fri Dec  6 17:06:50 2002
@@ -26,8 +26,8 @@
 
     __implements__ = IFullDeserializationEvent
 
-    def __init__(self, object_mapper, key, object, keyed_ob_sys):
-        EventBase.__init__(self, object_mapper, key, object, keyed_ob_sys)
+    def __init__(self, object_mapper, keychain, object, keyed_ob_sys):
+        EventBase.__init__(self, object_mapper, keychain, object, keyed_ob_sys)
         self._loaded_refs = {}  # { (aspect_name, name) -> object }
 
     # IDeserializationEvent interface methods:
@@ -36,23 +36,15 @@
         """See the IDeserializationEvent interface."""
         self._loaded_refs[(self._aspect_name, name)] = value
 
-    def dereference(self, name, mapper_name=None, key=None,
-                    classification=None):
+    def dereference(self, name, keychain):
         """Retrieves a referenced subobject (usually ghosted initially).
         """
-        dm = self.getObjectMapper().getDomainMapper()
-        if mapper_name is None:
-            classifier = self.getObjectMapper().getClassifier()
-            mapper_name = classifier.chooseMapper(classification)
-            assert mapper_name is not None
-        if key is None:
-            sub_mapper = dm.getMapper(mapper_name)
-            key = sub_mapper.getGateway().makeKey(self, name, 0)
-            assert key is not None
-        mapper = dm.getMapper(mapper_name)
-        class_info = mapper.getSerializer().getClassInfo()
+##        dm = self.getObjectMapper().getDomainMapper()
+##        assert keychain is not None
+##        mapper = dm.getMapper(mapper_name)
+##        class_info = mapper.getSerializer().getClassInfo()
         kos = self.getKeyedObjectSystem()
-        ob = kos.loadStub(mapper_name, key, class_info)
+        ob = kos.loadStub(keychain) #, class_info)
         self.notifyDeserialized(name, ob)
         return ob
 


=== Products/AdaptableStorage/serial/EventBase.py 1.1 => 1.2 ===
--- Products/AdaptableStorage/serial/EventBase.py:1.1	Wed Nov 27 13:37:06 2002
+++ Products/AdaptableStorage/serial/EventBase.py	Fri Dec  6 17:06:50 2002
@@ -24,9 +24,9 @@
 
     _aspect_name = ''
 
-    def __init__(self, object_mapper, key, object, keyed_ob_sys):
+    def __init__(self, object_mapper, keychain, object, keyed_ob_sys):
         self._object_mapper = object_mapper
-        self._key = key
+        self._keychain = keychain
         self._object = object
         self._keyed_ob_sys = keyed_ob_sys
 
@@ -42,9 +42,9 @@
         """Returns the object mapper for the object being (de)serialized."""
         return self._object_mapper
 
-    def getKey(self):
-        """Returns the key of the object being serialized/deserialized."""
-        return self._key
+    def getKeychain(self):
+        """Returns the keychain of the object being serialized/deserialized."""
+        return self._keychain
 
     def getObject(self):
         """Returns the object being serialized."""


=== Products/AdaptableStorage/serial/ObjectGateway.py 1.3 => 1.4 ===
--- Products/AdaptableStorage/serial/ObjectGateway.py:1.3	Thu Dec  5 12:38:46 2002
+++ Products/AdaptableStorage/serial/ObjectGateway.py	Fri Dec  6 17:06:50 2002
@@ -43,7 +43,7 @@
                 res[name] = s
         return res
 
-    def load(self, object_mapper, key):
+    def load(self, object_mapper, keychain):
         """Loads data.
 
         Returns a pair containing the data and an object
@@ -54,7 +54,7 @@
         full_state = {}
         serials = {}
         for name, gw in self._gws.items():
-            state, serial = gw.load(object_mapper, key)
+            state, serial = gw.load(object_mapper, keychain)
             if state is not None:
                 full_state[name] = state
                 if serial is not None:
@@ -63,7 +63,7 @@
         serials.sort()
         return full_state, tuple(serials)
 
-    def store(self, object_mapper, key, full_state):
+    def store(self, object_mapper, keychain, full_state):
         """Stores data.
 
         Returns a new serial.
@@ -71,8 +71,8 @@
         serials = {}
         for name, gw in self._gws.items():
             state = full_state.get(name)
-            # print 'gateway storing', key, name, state
-            serial = gw.store(object_mapper, key, state)
+            # print 'gateway storing', keychain, name, state
+            serial = gw.store(object_mapper, keychain, state)
             if serial is not None:
                 serials[name] = serial
         serials = serials.items()
@@ -81,5 +81,5 @@
 
     def makeKey(self, event, name, stored):
         # By default, use simple path-based keys
-        return event.getKey() + '/' + name
+        return event.getKeychain() + '/' + name
 


=== Products/AdaptableStorage/serial/ObjectMapper.py 1.1 => 1.2 ===
--- Products/AdaptableStorage/serial/ObjectMapper.py:1.1	Wed Nov 27 13:37:06 2002
+++ Products/AdaptableStorage/serial/ObjectMapper.py	Fri Dec  6 17:06:50 2002
@@ -23,26 +23,39 @@
 
     __implements__ = IObjectMapper
 
-    def __init__(self, serializer, gateway, domain_mapper, volatile=1):
+    def __init__(self, parent, serializer, gateway,
+                 classifier=None, volatile=None):
         assert serializer.getSchema() == gateway.getSchema(), (
             serializer.getSchema(), gateway.getSchema())
+        self._sub_mappers = {}
+        self._parent = parent
         self._serializer = serializer
         self._gateway = gateway
-        self._dm = domain_mapper
+        self._classifier = classifier
         self._volatile = volatile
 
+    def addSubMapper(self, name, m):
+        self._sub_mappers[name] = m
+
     def getSerializer(self):
         return self._serializer
 
     def getGateway(self):
         return self._gateway
 
-    def getDomainMapper(self):
-        return self._dm
+    def getSubMapper(self, name):
+        return self._sub_mappers[name]
 
     def getClassifier(self):
-        return self._dm.getClassifier()
+        if self._classifier is not None:
+            return self._classifier
+        if self._parent is not None:
+            return self._parent.getClassifier()
+        return None
 
     def isVolatile(self):
-        return self._volatile
-
+        if self._volatile is not None:
+            return self._volatile
+        if self._parent is not None:
+            return self._parent.isVolatile()
+        return None


=== Products/AdaptableStorage/serial/ObjectSerializer.py 1.1 => 1.2 ===
--- Products/AdaptableStorage/serial/ObjectSerializer.py:1.1	Wed Nov 27 13:37:06 2002
+++ Products/AdaptableStorage/serial/ObjectSerializer.py	Fri Dec  6 17:06:50 2002
@@ -25,8 +25,9 @@
 
     __implements__ = IObjectSerializer
 
-    def __init__(self, class_info):
-        self._class_info = class_info
+    def __init__(self, module, name):
+        self._module = module
+        self._name = name
         self._aspects = []  # [(name, aspect)] -- Order matters.
 
     def addAspect(self, name, aspect):
@@ -44,11 +45,11 @@
         if not hasattr(object, '__class__'):
             return 0
         c = object.__class__
-        info = ((c.__module__, c.__name__), None)
-        return (info == self._class_info)
+        return (c.__module__ == self._module and c.__name__ == self._name)
 
-    def serialize(self, object_mapper, key, object, keyed_ob_sys):
-        event = SerializationEvent(object_mapper, key, object, keyed_ob_sys)
+    def serialize(self, object_mapper, keychain, object, keyed_ob_sys):
+        event = SerializationEvent(object_mapper, keychain,
+                                   object, keyed_ob_sys)
         full_state = {}
         for name, aspect in self._aspects:
             event.setAspectName(name)
@@ -57,14 +58,17 @@
                 full_state[name] = state
         return full_state, event.getExternalRefs()
 
-    def deserialize(self, object_mapper, key, object, keyed_ob_sys,
+    def deserialize(self, object_mapper, keychain, object, keyed_ob_sys,
                     full_state):
-        event = DeserializationEvent(object_mapper, key, object, keyed_ob_sys)
+        event = DeserializationEvent(
+            object_mapper, keychain, object, keyed_ob_sys)
         for name, aspect in self._aspects:
             state = full_state.get(name)
             event.setAspectName(name)
             aspect.deserialize(object, event, state)
 
-    def getClassInfo(self, state=None):
-        return self._class_info
+    def createEmptyInstance(self, full_state=None):
+        m = __import__(self._module, {}, {}, ('__doc__',))
+        c = getattr(m, self._name)
+        return c.__basicnew__()
 


=== Products/AdaptableStorage/serial/RecordSchema.py 1.1 => 1.2 ===
--- Products/AdaptableStorage/serial/RecordSchema.py:1.1	Wed Nov 27 13:37:06 2002
+++ Products/AdaptableStorage/serial/RecordSchema.py	Fri Dec  6 17:06:50 2002
@@ -27,7 +27,7 @@
 # ok_types just constrains the possible types until we figure out
 # what we really want to do here.
 ok_types = ('unicode', 'string', 'int', 'float', 'bool', 'object',
-            'classification')
+            'classification', 'keychain')
 
 
 class Column:


=== Products/AdaptableStorage/serial/SerializationEvent.py 1.2 => 1.3 ===
--- Products/AdaptableStorage/serial/SerializationEvent.py:1.2	Wed Dec  4 23:18:08 2002
+++ Products/AdaptableStorage/serial/SerializationEvent.py	Fri Dec  6 17:06:50 2002
@@ -27,12 +27,12 @@
 
     __implements__ = IFullSerializationEvent
 
-    def __init__(self, object_mapper, key, object, keyed_ob_sys):
-        EventBase.__init__(self, object_mapper, key, object, keyed_ob_sys)
+    def __init__(self, object_mapper, keychain, object, keyed_ob_sys):
+        EventBase.__init__(self, object_mapper, keychain, object, keyed_ob_sys)
         self._attrs = {}
 
         # _refs is the list of externally referenced objects.
-        # It has the form [(mapper_name, key, value)]
+        # It has the form [(keychain, value)]
         self._refs = []
         # _internal_refs:
         # id(ob) -> (aspect_name, name)
@@ -65,17 +65,16 @@
         c = self.getObjectMapper().getClassifier()
         return c.classifyObject(value)
 
-    def makeKey(self, mapper_name, name, stored_key=0):
-        dm = self.getObjectMapper().getDomainMapper()
-        sub_mapper = dm.getMapper(mapper_name)
-        key = sub_mapper.getGateway().makeKey(self, name, stored_key)
-        return key
+    def makeKey(self, name, stored_key=0):
+        raise NotImplementedError
+##        dm = self.getObjectMapper().getDomainMapper()
+##        sub_mapper = dm.getMapper(mapper_name)
+##        key = sub_mapper.getGateway().makeKey(self, name, stored_key)
+##        return key
         
-    def notifySerializedRef(self, name, value, is_attribute,
-                            mapper_name, key):
-        assert mapper_name is not None
-        assert key is not None
-        self._refs.append((mapper_name, key, value))
+    def notifySerializedRef(self, name, value, is_attribute, keychain):
+        assert keychain is not None
+        self._refs.append((keychain, value))
         self.notifySerialized(name, value, is_attribute)
 
     def ignoreAttribute(self, name):