Package org.apache.cayenne.reflect

# Class LifecycleCallbackRegistry

java.lang.Object
org.apache.cayenne.reflect.LifecycleCallbackRegistry

public class LifecycleCallbackRegistry extends Object
A registry of lifecycle callbacks for all callback event types. Valid event types are defined in `LifecycleEvent` enum.

Since:
  3.0

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `LifecycleCallbackRegistry(EntityResolver resolver)`
  Creates an empty callback registry.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addCallback(LifecycleEvent type, Class<?> entityClass, Method method)`
  Registers a callback method to be invoked on an entity class instances when a lifecycle event occurs.
  `void`
  `addCallback(LifecycleEvent type, Class<?> entityClass, String methodName)`
  Registers a callback method to be invoked on an entity class instances when a lifecycle event occurs.
  `void`
  `addDefaultListener(LifecycleListener listener)`
  Registers a `LifecycleListener` for all events on all entities.
  `void`
  `addDefaultListener(LifecycleEvent type, Object listener, String methodName)`
  Registers a callback method to be invoked on a provided non-entity object when a lifecycle event occurs on any entity that does not suppress default callbacks.
  `void`
  `addListener(Class<?> entityClass, LifecycleListener listener)`
  Registers a `LifecycleListener` for all events on all entities.
  `void`
  `addListener(Object listener)`
  Adds a listener, mapping its methods to events based on annotations.
  `void`
  `addListener(LifecycleEvent type, Class<?> entityClass, Object listener, String methodName)`
  Registers callback method to be invoked on a provided non-entity object when a lifecycle event occurs for a specific entity.
  `void`
  `clear()`
  Removes all listeners for all event types.
  `void`
  `clear(int type)`
  Removes listeners for a single event type.
  `boolean`
  `isEmpty(LifecycleEvent type)`
  Returns true if there are no listeners for a specific event type.
  `void`
  `performCallbacks(LifecycleEvent type, Collection<?> objects)`
  Invokes callbacks of a specific type for a collection of entity objects.
  `void`
  `performCallbacks(LifecycleEvent type, Persistent object)`
  Invokes callbacks of a specific type for a given entity object.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### LifecycleCallbackRegistry

    public LifecycleCallbackRegistry(EntityResolver resolver)
    Creates an empty callback registry.

- ## Method Details

  - ### clear

    public void clear()
    Removes all listeners for all event types.

  - ### clear

    public void clear(int type)
    Removes listeners for a single event type.

  - ### isEmpty

    public boolean isEmpty(LifecycleEvent type)
    Returns true if there are no listeners for a specific event type.

  - ### addDefaultListener

    public void addDefaultListener(LifecycleListener listener)
    Registers a `LifecycleListener` for all events on all entities. Note that listeners are not required to implement `LifecycleListener` interface. Other methods in this class can be used to register arbitrary listeners.

  - ### addDefaultListener

    public void addDefaultListener(LifecycleEvent type, Object listener, String methodName)
    Registers a callback method to be invoked on a provided non-entity object when a lifecycle event occurs on any entity that does not suppress default callbacks.

  - ### addListener

    public void addListener(Class<?> entityClass, LifecycleListener listener)
    Registers a `LifecycleListener` for all events on all entities. Note that listeners are not required to implement `LifecycleListener` interface. Other methods in this class can be used to register arbitrary listeners.

  - ### addListener

    public void addListener(LifecycleEvent type, Class<?> entityClass, Object listener, String methodName)
    Registers callback method to be invoked on a provided non-entity object when a lifecycle event occurs for a specific entity.

  - ### addCallback

    public void addCallback(LifecycleEvent type, Class<?> entityClass, String methodName)
    Registers a callback method to be invoked on an entity class instances when a lifecycle event occurs.
    Since:
      4.0

  - ### addCallback

    public void addCallback(LifecycleEvent type, Class<?> entityClass, Method method)
    Registers a callback method to be invoked on an entity class instances when a lifecycle event occurs.
    Parameters:
      `type` - of the lifecycle event
      `entityClass` - type of the entity
      `method` - callback method reference
    Since:
      4.2

  - ### addListener

    public void addListener(Object listener)
    Adds a listener, mapping its methods to events based on annotations.
    Since:
      3.1

  - ### performCallbacks

    public void performCallbacks(LifecycleEvent type, Persistent object)
    Invokes callbacks of a specific type for a given entity object.

  - ### performCallbacks

    public void performCallbacks(LifecycleEvent type, Collection<?> objects)
    Invokes callbacks of a specific type for a collection of entity objects.