Capturing DataContextEvent or GraphEvent

From: edward pedersson (cpsmadnes..ooglemail.com)
Date: Mon Oct 30 2006 - 16:10:49 EST

  • Next message: Watkins, Garry: "Re: Is there an awakeFromInsertion equivalent in cayenne?"

    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 ***");
            }
          };

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



    This archive was generated by hypermail 2.0.0 : Mon Oct 30 2006 - 16:11:17 EST