Return-Path: Delivered-To: apmail-incubator-cayenne-user-archive@locus.apache.org Received: (qmail 56542 invoked from network); 26 Aug 2006 19:58:36 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 26 Aug 2006 19:58:36 -0000 Received: (qmail 82447 invoked by uid 500); 26 Aug 2006 19:58:36 -0000 Delivered-To: apmail-incubator-cayenne-user-archive@incubator.apache.org Received: (qmail 82434 invoked by uid 500); 26 Aug 2006 19:58:35 -0000 Mailing-List: contact cayenne-user-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cayenne-user@incubator.apache.org Delivered-To: mailing list cayenne-user@incubator.apache.org Received: (qmail 82424 invoked by uid 99); 26 Aug 2006 19:58:35 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 26 Aug 2006 12:58:35 -0700 X-ASF-Spam-Status: No, hits=0.5 required=10.0 tests=DNS_FROM_RFC_ABUSE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of mkienenb@gmail.com designates 64.233.166.179 as permitted sender) Received: from [64.233.166.179] (HELO py-out-1112.google.com) (64.233.166.179) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 26 Aug 2006 12:58:34 -0700 Received: by py-out-1112.google.com with SMTP id c30so1721480pyc for ; Sat, 26 Aug 2006 12:58:14 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=EKeOsJJ8t3110rmoll6AOCCvdZ8i9Kg7mpdrxx/MQUp3wn4piBlHLkleEbNc6+5NE5rzlkMiW2wEySEaNeVAHHS3kX14wOqor1q2dsYdt46/6VuRDMdLvhPd2myJ9dozQQrLtWuXjlicgMLdhDSZwqqL53RaAGyb2mX1FaVX8GE= Received: by 10.65.126.4 with SMTP id d4mr5178275qbn; Sat, 26 Aug 2006 12:58:14 -0700 (PDT) Received: by 10.65.253.14 with HTTP; Sat, 26 Aug 2006 12:58:14 -0700 (PDT) Message-ID: <8f985b960608261258i38678fd4scb0f8dc118b511e2@mail.gmail.com> Date: Sat, 26 Aug 2006 15:58:14 -0400 From: "Mike Kienenberger" To: cayenne-user@incubator.apache.org Subject: Intercepting BatchQueries after sql is generated In-Reply-To: <8f985b960608261256w44dc9261h558a6acbac965211@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <8f985b960608261256w44dc9261h558a6acbac965211@mail.gmail.com> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N > 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? Now that I've looked at the BatchQuery object, this was a naive question :-) The BatchQuery contains EXACTLY the information I need. Thanks for being patient :-) Furthermore, I don't think I need to set relationships if I'm using the direct values. The only question will be how I can get the foreign keys injected into my Log object relationships without breaking them. Probably not insurmountable. It looks like the best place to intercept the queries is in DataDomainFlushAction.flush(), right between runQueries() and postprocess(context). Since we have access to the DataContext, this seems like it'd be a reasonable place to call a DataContextDelegate.queriesDidRun(List queries) method. So I need to set a user-managed transaction, create a DataContextDelegate that reparses all of the queries, turning them into Log objects (or into datarows), let the first commit finish, then recommit again with the new Log objects and close out the user transaction. On 12/31/05, Andrus Adamchik wrote: > > > 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(); > } > > ... > } > >