Re: No access to getObjectStore().getFlattenedInserts() / getFlattenedDeletes()

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Sat Dec 31 2005 - 01:39:03 EST

  • Next message: jira-norepl..bjectstyle.org: "[OS-JIRA] Created: (CAY-414) Support for (batch) query interception and audit"

    On Dec 30, 2005, at 11:27 PM, Mike Kienenberger wrote:

    > I don't quite understand what you're proposing. How would one get
    > the needed information out of a batch query?

    BatchQuery contain a matrix of values keyed by DbAttribute - this is
    what you need for audit, right? Still need to think how to handle
    deferred generated keys, but if we intercept the query at the right
    moment, they can be already there, solving your other problem as well.

    BatchQuery q;
    List dbAttributes = q.getDbAttributes();
    while(q.next()) {
        for(int i = 0; i < q.size(); i++) {
           DbAttribute a = (DbAttribute) dbAttributes.get(i);
           Object value = q.getValue(i);

           // append this data to the audit log
           // ...

           // note that in UPDATE batches attribute can be either
           // from 'UpdatedAttributes' or 'QualifierAttributes'
        }
    }

    // reset the batch so that Cayenne could process it again later
    q.reset();

    > And then add new objects to the commit? The process of adding
    > more inserts is
    > probably the two-stage commit that you're talking about.

    Yes. If possible you can simply append the audit log to your own
    InsertBatchQuery (maybe attaching it to the DataContext via
    "setUserProperty"). If not, you can create unregistered DataObjects
    (you won't have any relationships in them, right?), register them in
    DataContext after the first commit stage is done, and then commit again.

    > Sounds interesting, but I need something that works in the present,
    > and it
    > sounds like this might require a lot of work before it's ready for
    > use.

    This may not be as bad, but it will certainly require some attention.
    I'll log a Jira improvement task.

    > What I'm doing now works. It isn't clean, but it works.

    I agree and realize that you need a solution now. And I think you
    don't need a patch to use your approach. Subclassing would be enough.
    The trick is to put your subclass in org.objectstyle.cayenne.access
    package (inside your application source tree of course). The fields
    you need to access are not private, they are just not public, so by
    doing that you'll get full access to these methods:

    package org.objectstyle.cayenne.access;

    public class MyDataContext extends DataContext {
         ...

         public List newFlattenedObjects()
         {
             // maybe wrap in new ArrayList() first....
             return getObjectStore().getFlattenedInserts();
         }
         public List deletedFlattenedObjects()
         {
             // maybe wrap in new ArrayList() first....
             return getObjectStore().getFlattenedDeletes();
         }

         ...
    }



    This archive was generated by hypermail 2.0.0 : Sat Dec 31 2005 - 01:39:07 EST