Hello Chris Spencer,

Saturday, October 29, 2005, 7:16:43 AM, you wrote:

CS> Would it be possible to support some system of class versioning in ZODB, 
CS> to aid to handling modifications to source code? For instance, suppose 
CS> each class definition has a __version__ attribute. Upon serialization, 
CS> this version is saved for each instance. Then, if the class is updated, 
CS> signified by incrementing the class's __version__, ZODB could take 
CS> action, for example, by executing an optional __upgrade_to_x(self) in 
CS> the new class definition.
 you can easily derive your own class from Persistent class, and add some 
system of class versioning
 to them.

 for example ( untested )

 class Persistent(_Persistent):
    # attributes for version tag support
    _class_version = None
    _class_tag   = None
    _version_tag = None

    def __class_init__(self): # works only for extension classes
        tags = [ self._class_version ]
        for base in self.__bases__:
            if hasattr( base, '_class_tag' ):
               tags.append( base._class_tag )

        self._class_tag = hash( tuple(tags) )

    def __setstate__( self, state ):
        _Persistent.__setstate__( self, state )
        if self.tagChanged():
            self.doSomething()
            
    def doSomething(self):
        self._version_tag = self._class_tag
        
    def tagChanged(self):
        return self._version_tag <> self._class_tag
        
 class A(Persistent):
    _class_version = 1.3

 class B(A):
    _class_version = 1.45

-- 
Best regards,
 Victor Safronovich
 NauMen.NauDoc.SoftwareDeveloper  http://www.naumen.ru

_______________________________________________
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zodb-dev

Reply via email to