Skip Headers

# Using Java

Previous

Next

Example: Using the Session Event Adapter to Create a Session Event Listener illustrates how to use Java to register a session event listener with a session. TopLink provides a `SessionEventAdapter` to simplify creating a `SessionEventListener`. The `SessionEventAdapter` provides a default implementation of all the methods of the `SessionEventListener` interface. You need only override the specific methods of interest. Typically, you would define session event listeners in a session customizer class (see "Configuring Customizer Class").

Using the Session Event Adapter to Create a Session Event Listener

    ...
    SessionEventAdapter myEventListener = new SessionEventAdapter() {
        // Listen for PostCommitUnitOfWork events
        public void postCommitUnitOfWork(SessionEvent event) {
            // Call the handler routine
            unitOfWorkCommitted();
        }
    };
    mySession.getEventManager().addListener(myEventListener);
    ...

For information on how to add logging to your listeners, see "Logging".