Re: accessing ObjectStore graph changes [WAS reverting changes and displaying commited changes]

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Tue Nov 07 2006 - 16:59:26 EST

  • Next message: Damir Bijuklic: "Nested data context problems"

    Just to reiterate, these solutions where already mentioned:

    * Compare data with snapshot as Bryan suggested (drawback -
    relationship handling can be non-trivial)
    * Use non-public method ObjectStore.getChanges with a custom
    GraphChangeHandler to analyze the changes. The simplest and probably
    best performing solution. Drawback - non-public API is subject to
    change without notice.

    I just thought of one more solution (haven't tried it yet)... It is
    more consistent with the "modern" Cayenne API and is sort of a
    combination of the two approaches above:

    * Compare the state of the objects with a state of unmodified objects
    in a peer context, using ClassDescriptor.visitProperties(..) method:

    if(context.hasChanges()) {
       ObjectContext peer = context.getParentDataDomain
    ().createDataContext();
       PropertyVisitor visitor = ... // this class will analyze the changes,
               // using peer context to obtain unmodified objects

       // updated
       Iterator it = context.modifiedObjects().iterator();
       while(it.hasNext()) {
          Persistent o = (Persistent) it.next();
          ObjectId id = o.getObjectId();
          ClassDescriptor descriptor = context.getEntityResolver
    ().getClassDescriptor(id.getEntityName());

          descriptor.visitProperties(visitor);
       }

       // inserted and deleted can be analyzed without ClassDescriptor
    }

    Andrus

    On Nov 7, 2006, at 11:51 AM, edward pedersson wrote:
    > Hi
    >
    > I am trying to display the changes in the object graph as granular as
    > possible and I have come stuck in the objectStore. These methods
    > and fields
    >
    > protected Map changes = new HashMap();
    >
    > ObjectStoreGraphDiff getChanges() {
    > return new ObjectStoreGraphDiff(this);
    > }
    >
    >
    > Map getChangesByObjectId() {
    > return changes;
    > }
    >
    > are all encapsulated quite heavily and I have no access to them
    > other than
    > creating a class in the org.apache.cayenne.access either as a
    > subclass of
    > ObjectStore or a stand alone class with an objectStore reference.
    >
    > I can't see any other way to display any more useful information to
    > the user
    > other than the default DataObject.toString() which really only
    > tells the
    > user the object has changed but nothing more.
    >
    > Has any body tried to do this before? Many thanks for your help.
    >
    >
    >
    > e--
    >
    > ---------- Forwarded message ----------
    > From: edward pedersson <cpsmadnes..ooglemail.com>
    > Date: 09-Oct-2006 11:11
    > Subject: reverting changes and displaying commited changes
    > To: Cayenne Users <cayenne-use..ncubator.apache.org>
    >
    > Hi
    >
    > I have built an application using Cayenne and Tapestry running under
    > Tomcat on a Linux server. I am using the latest released versions of
    > all of the above.
    >
    > I would like to be able to display to the user the current changes in
    > the DataContext and allow the user to revert individual changes. I
    > would also like them to be able to see what values the object had
    > before the change.
    >
    > I have read the documentation and thought about having nested contexts
    > but at times I would have to deal with 50+ context so it seems a bit
    > unmanageable.
    >
    > Any thought would be most helpful.
    >
    > Thanks in advance.
    >
    > --
    >
    >
    > -- e
    >
    >
    > --
    >
    >
    > -- e



    This archive was generated by hypermail 2.0.0 : Tue Nov 07 2006 - 17:01:05 EST