Interface EntityCallback<T>

Type Parameters:
T - Entity type used to detect callbacks to invoke via their generic type signature.

@Reflective(PublicMethodReflectiveProcessor.class) public interface EntityCallback<T>
Marker interface for entity callbacks to be implemented in specific callback subtypes. Intended for internal usage within store specific implementations.

Ordering EntityCallback

Multiple entity callbacks are invoked sequentially with the result of the previous callback. Callbacks are unordered by default. It is possible to define the order in which listeners for a certain domain type are to be invoked. To do so, add Spring's common @Order annotation or implement Ordered.

Exception Handling

While it is possible for a EntityCallback to declare that it throws arbitrary exception types, any checked exceptions thrown from a EntityCallback are wrapped in an UndeclaredThrowableException since the callback mechanism can only handle runtime exceptions. Entity callback processing is stopped on the EntityCallback that raised an exception and the caused exception is propagated to the caller.

Domain Type Binding

An EntityCallback can generically declare the domain type that it is able to process by specifying the generic type parameter <T>. When registered with a Spring ApplicationContext, callbacks are filtered accordingly, with the callback getting invoked for assignable domain objects only.

Typically, entity callbacks are invoked after publishing events.

Defining EntityCallback Interfaces

A EntityCallback interface needs to define a callback method accepting an object of the parameterized type as its first argument followed by additional optional arguments.


 public interface BeforeSaveCallback<T> extends EntityCallback<T> {

        T onBeforeSave(T entity, String collection);
 }
 
Since:
2.2
Author:
Mark Paluch, Christoph Strobl
See Also: