6.4. Event Notification Framework

6.4.1. Transaction Event Notification
6.4.2. Remote Commit Notification

6.4.1. Transaction Event Notification

Kodo provides callbacks for a number of PersistenceManager-related events. These callbacks provide a mechanism for application code to perform application-specific coding at various key transaction lifecycle points: transaction begin, transaction rollback, and transaction commit.

To receive callbacks, implement one or more of the transaction event callback interfaces and register it with the PersistenceManagerImpls that the callback should be associated with:

import com.solarmetric.kodo.runtime.*;
import com.solarmetric.kodo.runtime.event.*;
import java.util.*;

TransactionCommitListener tl = new TransactionCommitListener ()
    {
        public void transactionCommitted (PersistenceManagerImpl pm, Set added,
            Set updated, Set deleted)
        {
            // do something with the lists of added, updated, and 
            // deleted StateManagerImpl objects
        }
    };

((PersistenceManagerImpl) pm).registerTransactionListener (tl);
        

There are three listener interfaces that can be registered with a PersistenceManagerImpl:

  • TransactionCommitListener

    The TransactionCommitListener interface provides a mechanism for receiving notification before a commit begins and upon successful completion of a transaction. This notification includes collections of StateManagerImpl objects involved in the transaction.

  • TransactionStartListener

    The TransactionStartListener interface provides a method for receiving notification of a Transaction.begin() invocation.

  • TransactionRollbackListener

    The TransactionRollbackListener interface provides a method for receiving notification of a Transaction.rollback() invocation. This is invoked both when rollback() is directly invoked and when a transaction is implicitly rolled back due to a commit-time failure.

6.4.2. Remote Commit Notification

In addition to receiving callbacks when a particular PersistenceManager goes through certain life cycle events, it is possible to receive notification when remote transactions commit with Kodo JDO Enterprise Edition. See the remote commit notification documentation for details on how this works.