Oracle TopLink Developer's Guide
10g Release 3 (10.1.3) B13593-01 |
|
![]() Previous |
![]() Next |
As you perform persistence operations with a session, the session produces various events (see "Session Event Manager Events") that the TopLink runtime uses to coordinate its various components. You can configure a session with one or more session event listeners (see "Session Event Listeners") to customize session behavior and debug session operations. For example, session event listeners play an important role in the configuration of isolated sessions (see "Configuring Isolated Client Sessions").
Table 77-14 summarizes which sessions support event listeners.
Table 77-14 Session Support for Event LIsteners
Session | Using TopLink Workbench
|
Using Java
|
---|---|---|
|
|
|
Session Broker and Client Sessions |
|
|
|
|
|
Session Event Listeners
To specify the event listener class in a session, use this procedure:
Select a session in the Navigator. Its properties appear in the Editor.
Click the Options tab. The Options tab appears.
To add a new event listener, click Add, then select the event listener class for this session.
To remove an existing event listener, select the Event Listener and click Remove.
Example 77-8 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").
Example 77-8 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); ...