Return-Path: Delivered-To: apmail-incubator-cayenne-user-archive@locus.apache.org Received: (qmail 56977 invoked from network); 31 Oct 2006 16:10:31 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 31 Oct 2006 16:10:31 -0000 Received: (qmail 22183 invoked by uid 500); 31 Oct 2006 16:10:42 -0000 Delivered-To: apmail-incubator-cayenne-user-archive@incubator.apache.org Received: (qmail 21982 invoked by uid 500); 31 Oct 2006 16:10:42 -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 21970 invoked by uid 99); 31 Oct 2006 16:10:42 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 31 Oct 2006 08:10:42 -0800 X-ASF-Spam-Status: No, hits=2.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of cpsmadness@googlemail.com designates 66.249.92.175 as permitted sender) Received: from [66.249.92.175] (HELO ug-out-1314.google.com) (66.249.92.175) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 31 Oct 2006 08:10:28 -0800 Received: by ug-out-1314.google.com with SMTP id y2so1799455uge for ; Tue, 31 Oct 2006 08:10:06 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=googlemail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=XfLX5k9gN8N9jv0cHfAbt63lE+5cZAaNRqeGVVnAPT6KzkAWTBKSnFBU+6UykNZXzr0YrxUMIbfaHsbqta+4a+XTuEqmLAfwafljFzbf0LL/s57AlzklM/R4ZBr74lUM0jHOYyM1xbqpDya4mdxFKDQt89WXHSkMGtStkMCscxc= Received: by 10.67.89.5 with SMTP id r5mr6368508ugl; Tue, 31 Oct 2006 08:10:05 -0800 (PST) Received: by 10.67.92.3 with HTTP; Tue, 31 Oct 2006 08:10:04 -0800 (PST) Message-ID: <469958e20610310810q250c5d9ewc84f48bba3dc5d2@mail.gmail.com> Date: Tue, 31 Oct 2006 16:10:04 +0000 From: "edward pedersson" To: "Cayenne Users" Subject: Re: Capturing DataContextEvent or GraphEvent In-Reply-To: <469958e20610301310n1f1db350mea1ae656ee799bb4@mail.gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_13919_9268730.1162311004902" References: <469958e20610301310n1f1db350mea1ae656ee799bb4@mail.gmail.com> X-Virus-Checked: Checked by ClamAV on apache.org ------=_Part_13919_9268730.1162311004902 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Found the problem. have to register a GraphEvent with the DataChannel to capture DataContext rollbacks but you can register DataContextEvent's with the DataContext to capture commits and willCommit. A little bit confusing... EventManager eventManager = this.getDataContext().getEventManager(); //this never happens and not sure why //gets registered but i believe will only fire if there is an exception in a // commit and the transaction is rolledback eventManager.addListener( this, "dataContextDidRollback", DataContextEvent.class, DataContext.DID_ROLLBACK, this.getDataContext()); //registers and fires the event eventManager.addListener( this, "dataContextDidRollback", GraphEvent.class, DataChannel.GRAPH_ROLLEDBACK_SUBJECT, this.getDataContext()); On 30/10/06, edward pedersson wrote: > > Hi > > I am trying to capture the a rollback event from the dataContext and I > have tried variation of the code below but nothing seems to work. My event > handlers never get called. I would have used the DataObject jandlers but > they don't support rollBack. > > Can anyone see what I am doing wrong? Many thnaks for your help. > > > > public class SomeDataObject() extends MyDataObject { > > > public static DataContextTransactionEventListener > dataContextTransactionListener = new DataContextTransactionEventListener() { > > public void dataContextDidCommit(DataContextEvent event) { > System.out.println("*** xxSomething changed! DID_COMMIT ***"); > } > public void dataContextDidRollback(DataContextEvent event) { > System.out.println("*** xxSomething changed! ROLLEDBACK > ***"); > } > public void dataContextWillCommit(DataContextEvent event) { > System.out.println("*** xxSomething changed! WILL_COMMIT > ***"); > } > }; > > public static DataChannelListener dataChannelListener = new > DataChannelListener() { > public void graphChanged(GraphEvent event) { > System.out.println("*** Something changed! DID_COMMIT ***"); > } > public void graphFlushed(GraphEvent event) { > System.out.println("*** Something changed! ROLLEDBACK ***"); > } > public void graphRolledback(GraphEvent event) { > System.out.println("*** Something changed! WILL_COMMIT > ***"); > } > }; > > > @Override > public void fetchFinished() { > > super.fetchFinished (); > System.out.println("*** FETCH FINISHED! ***" + this.toString()); > > // this.getDataContext() is DataContext.getThreadedContext() > > this.getDataContext().setTransactionEventsEnabled(true); > > DataContext.setTransactionEventsEnabledDefault(true); > > EventUtil.listenForChannelEvents(this.getDataContext().getChannel(), > dataChannelListener); > > EventManager.getDefaultManager().addListener(dataContextTransactionListener,"dataContextDidRollback", > DataContextEvent.class,DataContext.DID_ROLLBACK, null); > } > > > ....more methods > } > > > -- > > > -- e -- -- e ------=_Part_13919_9268730.1162311004902--