Re: Reconnecting serialized DataObjects

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Mon Sep 26 2005 - 18:59:41 EDT

  • Next message: Jürgen Saar: "Transient Attributes"

    On Sep 26, 2005, at 6:03 PM, Andrus Adamchik wrote:
    > My solution for that (I haven't tried it yet) was to rely on thread
    > DataContext during de-serialization and substitute deserialized
    > object clone with an object from that DataContext using
    > 'readResolve'. This would minimize the serialized footprint and
    > maintain uniquing.

    Ok, I figured I'd test my idea - see an attachment to CAY-298. In
    short - it works (with my today's TempObjectId CVS fix). Wedge
    DataObject superclass can be as simple as this:

    public class WedgeDataObject extends CayenneDataObject {

         /**
          * Substitute self with an object registered in thread
    DataContext with the same ID.
          */
         protected Object readResolve() throws ObjectStreamException {

             DataContext context;

             try {
                 context = DataContext.getThreadDataContext();
             }
             catch (IllegalStateException e) {
                 throw new NotActiveException("Can't deserialize object
    for id '"
                         + getObjectId()
                         + "' - no DataContext bound to thread.");
             }

             return context.registeredObject(getObjectId());
         }
    }

    Andrus



    This archive was generated by hypermail 2.0.0 : Mon Sep 26 2005 - 18:59:44 EDT