Skip Headers

# Configuring a Descriptor Event Listener as an Event Handler

Previous

Next

You can create your own `DescriptorEventListner` and register it with a `DescriptorEventManger` in a descriptor amendment method. You can also configure a `DescriptorEventListner` to be notified of events through the Java event model.

You can register any object that implements the `DescriptorEventListener` interface with the `DescriptorEventManager` owned by a domain object's descriptor to handle any descriptor event type (see Table: Descriptor Events). To quickly implement this interface, you can extend abstract class `DescriptorEventAdapter` and override only the methods for the events you are interested in.

Table: Descriptor Support for Descriptor Event Listener Configuration summarizes which descriptors support descriptor event listener configuration.

Descriptor Support for Descriptor Event Listener Configuration

Descriptor | Using TopLink Workbench | Using Java
--- | --- | ---
Relational Descriptors |  |
Object-Relational Descriptors |  |
EIS Descriptors |  |
XML Descriptors |  |

For example, you create a `DescriptorEventListener` to handle `PostBuildEvent` descriptor events for `Employee` objects. After you register this `DescriptorEventListener` with the `DescriptorEventManager` owned by the `Employee` object's descriptor, whenever the TopLink runtime performs a post-build operation on an instance of `Employee`, the runtime dispatches a `PostBuilEvent` to the event listener's `postBuild` method.

Table: Descriptor Events lists the `DescriptorEventListener` methods associated with each descriptor event. The Descriptor Event Listener Method column lists the `DescriptorEventListener` methods associated with each `DescriptorEvent`.

Descriptor Events

Category | Descriptor Event Listener Method | Description
--- | --- | ---
Delete | `preDelete` | Occurs before an object is deleted from the data source.
| `aboutToDelete` | Occurs when an object is deleted from the data source.
| `postDelete` | Occurs after an object is deleted from the data source.
Insert | `preInsert` | Occurs before an object is inserted in the data source.
| `aboutToInsert` | Occurs when an object is inserted in the data source.
| `postInsert` | Occurs after an object is inserted into the data source.
Post-X | `postBuild` | Occurs after an object is built from the data source.
| `postClone` | Occurs after an object has been cloned into a unit of work.
| `postMerge` | Occurs after an object has been merged from a unit of work.
| `postRefresh` | Occurs after an object is refreshed from the data source.
Update | `preUpdate` | Occurs before an object is updated in the data source. This may be called in a unit of work even if the object has no changes and does not require updating.
| `aboutToUpdate` | Occurs when an object is updated in the data source. This method is called only if the object has changes in the unit of work.
| `postUpdate` | Occurs after an object is updated in the data source.
Write | `preWrite` | Occurs before an object is inserted or updated in the data source. This occurs before `PreInsertEvent` and `PreUpdateEvent`.
| `postWrite` | Occurs after an object is inserted or updated in the data source. This occurs after `PostInsertEvent` and `PostUpdateEvent`.

Alternatively, you can configure a domain object method as an event handler (see "Configuring a Domain Object Method as an Event Handler").