[ZODB-Dev] Custom DataManager / Changing __class__

Sebastien Bigaret Sebastien.Bigaret@inqual.com
27 Aug 2002 11:48:47 +0200


        Hi,

I have problems with ZODB.Persistence for python2.1 [zodb4 does exhibit none
of the problems w/ py2.2].

I'm willing to use the Persistent class in my own framework, while making sure
that the ZODB itself, if used (such as in Zope), is not broken by my changes.

My first problem was: how to have a DM/_p_jar that gets registered when changes
are observed? 

I end up digging in the (C-)code and finally found out that the Transaction
object gets registered, not the DM as in zodb4. Thus I made the following
changes [see patch below] in Transaction.py so that my DM gets notified when
appropriate. As you can see I'm using a special marker on objects that should
depend on my DM, not on get_transaction(). What do you think, is it ok? Is
there a risk to break other things? Or is there a cleaner way??


2nd question: how can I dynamically change the class of a Persistent object? 

My use-case is: an object 'obj', class A1 is created but is a ghost.
  When the object is unghostified, it may be that it is, in fact, belonging to
  class A2 (inheriting from A1) ; hence, I need to change the object's class,
  but couldn't find a way to do this.
Does anyone have an idea?
  

-- Sebastien.


----------------------------------------------------------------------
*** ZODB/Transaction.py.ori     Tue Aug 27 10:43:06 2002
--- ZODB/Transaction.py Tue Aug 27 10:42:49 2002
***************
*** 320,326 ****
  
      def register(self,object):
          'Register the given object for transaction control.'
!         self._append(object)
  
      def note(self, text):
          if self.description:
--- 320,329 ----
  
      def register(self,object):
          'Register the given object for transaction control.'
!         if getattr(object._p_jar, '_redirect_to_p_jar_', None):
!             object._p_jar.register(object)
!         else:
!             self._append(object)
  
      def note(self, text):

----------------------------------------------------------------------