Interface ChangeHook
- All Known Implementing Classes:
DefaultChangeHook
ModelBuilder.changeHooks
when creating the model.
Registering hooks later is not supported.
Methods of hooks are called synchronously when the change actually occurs,
by the thread that does the change.
If a method of a hook fails with an exception,
that exception is "thrown through" to the call causing the change.
If you want to postpone your action until the current transaction commits,
use either
pre
- or
post
-commit hooks.
Note that any new change to persistent data (i.e. other than
returning modified setValues
) done in one of the methods will
cause this hook to be called again.
Without care you may end up with infinite recursion.
Synchronization
There is only one instance of the ChangeHook for each model,
and calls to ChangeHooks are not synchronized.
If multiple threads concurrently change persistent data,
then methods of this hook are called concurrently.
It is highly recommended to override toString
with an informative message about the hook.
This message is returned by Model.getChangeHookString()
.
- See Also:
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptiondefault void
Is called after any item creation.default void
beforeDelete
(Item item) Is called before any item deletion.default SetValue<?>[]
Is called before any item creation.default SetValue<?>[]
Is called before any item modification.
-
Method Details
-
beforeNew
Is called before any item creation. You may change the values of the newly created item by returning changedsetValues
. The default implementation does nothing and returnssetValues
unmodified. -
afterNew
Is called after any item creation. The default implementation does nothing.- See Also:
-
beforeSet
Is called before any item modification. The default implementation does nothing.- Parameters:
setValues
- is never null and never empty- Returns:
- must not return null
- See Also:
-
beforeDelete
Is called before any item deletion. The default implementation does nothing.- See Also:
-