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 <cpsmadnes..ooglemail.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
> ***");
> }
> };
>
>
> ..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
---- e
This archive was generated by hypermail 2.0.0 : Tue Oct 31 2006 - 11:10:33 EST