cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <and...@objectstyle.org>
Subject Re: Capturing DataContextEvent or GraphEvent
Date Wed, 01 Nov 2006 02:00:17 GMT
Yeah, using internal event mechanism in the application can be  
confusing. Been there myself, so now I am advertising the  
(unreleased) 3.0 callbacks as a better substitute :-)

Andrus


On Oct 31, 2006, at 11:10 AM, edward pedersson wrote:
> 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 <cpsmadness@googlemail.com> 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


Mime
View raw message