Skip Headers

# Configuring a Domain Object Method as an Event Handler

Previous

Next

You can associate a domain object method with any of the descriptor events shown in Table: Descriptor Events. You can register any domain object method that:

- Is public.

- Returns void.

- Takes a single parameter of type `DescriptorEvent`

Table: Descriptor Support for Domain Object Method Event Handler Configuration summarizes which descriptors support domain object method event handler configuration.

Descriptor Support for Domain Object Method Event Handler Configuration

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

For example, you can add a method `handlePostDelete` (that is public, returns void, and takes a single parameter of type `DescriptorEvent`) to your `Employee` object to handle `PostDeleteEvent` descriptor events. After you register that method with the `DescriptorEventManager` owned by the `Employee` object's descriptor as the handler for `PostDeleteEvent` descriptor events, whenever the Oracle TopLink runtime performs a post-delete operation on an instance of the `Employee` object, the runtime dispatches a `PostDeleteEvent` to the `handlePostDelete` method on the instance of the `Employee` object associated with that `PostDeleteEvent`.

The Descriptor Event ID column in Table: Descriptor Events lists the `DescriptorEventManager` field name used to identify a particular event. The `DescriptorEvent` method `getEventCode` returns this value. For example:

    if (descriptorEvent.getEventCode() == DescriptorEventManager.PreUpdateEvent) {
        // descriptorEvent represents a pre-update event
    }

Descriptor Events

Category | Descriptor Event ID | Description
--- | --- | ---
Delete | `PreDeleteEvent` | Occurs before an object is deleted from the data source.
| `AboutToDeleteEvent` | Occurs when an object is deleted from the data source.
| `PostDelete` `Event` | Occurs after an object is deleted from the data source.
Insert | `PreInsert` `Event` | Occurs before an object is inserted in the data source.
| `AboutToInsert` `Event` | Occurs when an object is inserted in the data source.
| `PostInsertEvent` | Occurs after an object is inserted into the data source.
Post-X | `PostBuildEvent` | Occurs after an object is built from the data source.
| `PostCloneEvent` | Occurs after an object has been cloned into a unit of work.
| `PostMergeEvent` | Occurs after an object has been merged from a unit of work.
| `PostRefreshEvent` | Occurs after an object is refreshed from the data source.
Update | `PreUpdate` `Event` | 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` `Event` | 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.
| `PostUpdateEvent` | Occurs after an object is updated in the data source.
Write | `PreWrite` `Event` | Occurs before an object is inserted or updated in the data source. This occurs before `PreInsertEvent` and `PreUpdateEvent`.
| `PostWriteEvent` | Occurs after an object is inserted or updated in the data source. This occurs after `PostInsertEvent` and `PostUpdateEvent`.

Alternatively, you can configure a descriptor event listener as an event handler (see "Configuring a Descriptor Event Listener as an Event Handler").