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

From: Bryan Lewis (brya..aine.rr.com)
Date: Tue Nov 07 2006 - 13:24:29 EST

  • Next message: Andrus Adamchik: "Re: accessing ObjectStore graph changes [WAS reverting changes and displaying commited changes]"

    I've been able to do a similar thing for the purposes of a change
    history. We wanted to look at each change and write a history record
    only for the ones we cared about, ignoring phantom changes, to-many
    relationships and a few other properties that we specify as don't-care.
    I didn't need to deal with the GraphDiff methods. The ObjectStore will
    give me the object's previous snapshot and that's sufficient. Here's
    the attribute part:

    Map snapshot = dc.getObjectStore().getSnapshot(object.getObjectId());

    ObjEntity entity = object.getObjEntity();
    String entityName = object.getEntityName();

    Collection properties = entity.getAttributes();
    for (Iterator pit = properties.iterator(); pit.hasNext(); ) {
        ObjAttribute attribute = (ObjAttribute) pit.next();
        String name = attribute.getName();
        Object newValue = object.readProperty(name);

        // The snapshot uses database attribute names.
        String dbName = attribute.getDbAttributePath();
        Object oldValue = snapshot.get(dbName);

        if (!nullSafeEquals(oldValue, newValue)) {
            log.debug("# Real change in " + entityName + "." + name);
        }

    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
    >
    >



    This archive was generated by hypermail 2.0.0 : Tue Nov 07 2006 - 13:25:01 EST