public abstract class Trigger<S>
extends java.lang.Object
register it. Each overridden trigger method is
called in the same transaction scope as the persist operation. Trigger
implementations are encouraged to override the equals method, to prevent
accidental double registration.
To ensure proper nesting, all "before" events are run in the opposite order that the trigger was registered. All "after" and "failed" events are run in the same order that the trigger was registered. In other words, the last added trigger is at the outermost nesting level.
Triggers always run within the same transaction as the triggering operation. The exact isolation level and update mode is outside the trigger's control. If an explicit isolation level or update mode is required, create a nested transaction within a trigger method. A trigger's nested transaction can also be defined to span the entire triggering operation. To do this, enter the transaction in the "before" method, but return the transaction object without exiting it. The "after" method is responsible for exiting the transaction. It extracts (or simply casts) the transaction from the state object passed into it. When creating spanning transactions like this, it is critical that the "failed" method be defined to properly exit the transaction upon failure.
| Modifier and Type | Class and Description |
|---|---|
static class |
Trigger.Abort |
| Constructor and Description |
|---|
Trigger() |
| Modifier and Type | Method and Description |
|---|---|
protected Trigger.Abort |
abortTry()
Call to quickly abort a "try" operation, returning false to the
caller.
|
void |
afterDelete(S storable,
java.lang.Object state)
Called right after a storable has been successfully deleted.
|
void |
afterInsert(S storable,
java.lang.Object state)
Called right after a storable has been successfully inserted.
|
void |
afterLoad(S storable)
Called right after a storable has been successfully loaded or
fetched.
|
void |
afterTryDelete(S storable,
java.lang.Object state)
Called right after a storable has been successfully deleted via
tryDelete.
|
void |
afterTryInsert(S storable,
java.lang.Object state)
Called right after a storable has been successfully inserted via
tryInsert.
|
void |
afterTryUpdate(S storable,
java.lang.Object state)
Called right after a storable has been successfully updated via
tryUpdate.
|
void |
afterUpdate(S storable,
java.lang.Object state)
Called right after a storable has been successfully updated.
|
java.lang.Object |
beforeDelete(S storable)
Called before a storable is to be deleted.
|
java.lang.Object |
beforeDelete(Transaction txn,
S storable)
Called before a storable is to be deleted.
|
java.lang.Object |
beforeInsert(S storable)
Called before a storable is to be inserted.
|
java.lang.Object |
beforeInsert(Transaction txn,
S storable)
Called before a storable is to be inserted.
|
java.lang.Object |
beforeTryDelete(S storable)
Called before a storable is to be deleted via tryDelete.
|
java.lang.Object |
beforeTryDelete(Transaction txn,
S storable)
Called before a storable is to be deleted via tryDelete.
|
java.lang.Object |
beforeTryInsert(S storable)
Called before a storable is to be inserted via tryInsert.
|
java.lang.Object |
beforeTryInsert(Transaction txn,
S storable)
Called before a storable is to be inserted via tryInsert.
|
java.lang.Object |
beforeTryUpdate(S storable)
Called before a storable is to be updated via tryUpdate.
|
java.lang.Object |
beforeTryUpdate(Transaction txn,
S storable)
Called before a storable is to be updated via tryUpdate.
|
java.lang.Object |
beforeUpdate(S storable)
Called before a storable is to be updated.
|
java.lang.Object |
beforeUpdate(Transaction txn,
S storable)
Called before a storable is to be updated.
|
void |
failedDelete(S storable,
java.lang.Object state)
Called when an delete operation failed because the record was missing or
an exception was thrown.
|
void |
failedInsert(S storable,
java.lang.Object state)
Called when an insert operation failed due to a unique constraint
violation or an exception was thrown.
|
void |
failedUpdate(S storable,
java.lang.Object state)
Called when an update operation failed because the record was missing or
an exception was thrown.
|
public java.lang.Object beforeInsert(S storable) throws PersistException
Any exception thrown by this method will cause the insert operation to rollback and all remaining triggers to not run. The exception is ultimately passed to the caller of the insert method.
storable - storable before being insertedPersistExceptionpublic java.lang.Object beforeInsert(Transaction txn, S storable) throws PersistException
beforeInsert(Object). Only override if access to
the transaction is required.
Any exception thrown by this method will cause the insert operation to rollback and all remaining triggers to not run. The exception is ultimately passed to the caller of the insert method.
txn - nested transaction which trigger runs instorable - storable before being insertedPersistExceptionpublic java.lang.Object beforeTryInsert(S storable) throws PersistException
beforeInsert(Object). Only override
if trigger needs to distinguish between different insert variants.
Any exception thrown by this method will cause the tryInsert operation to rollback and all remaining triggers to not run. The exception is ultimately passed to the caller of the tryInsert method.
storable - storable before being insertedPersistExceptionabortTry()public java.lang.Object beforeTryInsert(Transaction txn, S storable) throws PersistException
beforeTryInsert(Object). Only
override if trigger needs access to the transaction and to distinguish
between different insert variants.
Any exception thrown by this method will cause the tryInsert operation to rollback and all remaining triggers to not run. The exception is ultimately passed to the caller of the tryInsert method.
txn - nested transaction which trigger runs instorable - storable before being insertedPersistExceptionabortTry()public void afterInsert(S storable, java.lang.Object state) throws PersistException
Any exception thrown by this method will cause the insert operation to rollback and all remaining triggers to not run. The exception is ultimately passed to the caller of the insert method.
storable - storable after being insertedstate - object returned by beforeInsert methodPersistExceptionpublic void afterTryInsert(S storable, java.lang.Object state) throws PersistException
afterInsert(S, java.lang.Object).
Only override if trigger needs to distinguish between different insert
variants.
Any exception thrown by this method will cause the tryInsert operation to rollback and all remaining triggers to not run. The exception is ultimately passed to the caller of the tryInsert method.
storable - storable after being insertedstate - object returned by beforeTryInsert methodPersistExceptionabortTry()public void failedInsert(S storable, java.lang.Object state)
Any exception thrown by this method will be passed to the current thread's uncaught exception handler.
storable - storable which failed to be insertedstate - object returned by beforeInsert method, but it may be nullpublic java.lang.Object beforeUpdate(S storable) throws PersistException
Any exception thrown by this method will cause the update operation to rollback and all remaining triggers to not run. The exception is ultimately passed to the caller of the update method.
storable - storable before being updatedPersistExceptionpublic java.lang.Object beforeUpdate(Transaction txn, S storable) throws PersistException
beforeUpdate(Object). Only override if access to
the transaction is required.
Any exception thrown by this method will cause the update operation to rollback and all remaining triggers to not run. The exception is ultimately passed to the caller of the update method.
txn - nested transaction which trigger runs instorable - storable before being updatedPersistExceptionpublic java.lang.Object beforeTryUpdate(S storable) throws PersistException
beforeUpdate(Object). Only override
if trigger needs to distinguish between different update variants.
Any exception thrown by this method will cause the tryUpdate operation to rollback and all remaining triggers to not run. The exception is ultimately passed to the caller of the tryUpdate method.
storable - storable before being updatedPersistExceptionabortTry()public java.lang.Object beforeTryUpdate(Transaction txn, S storable) throws PersistException
beforeTryUpdate(Object). Only
override if trigger needs access to the transaction and to distinguish
between different update variants.
Any exception thrown by this method will cause the tryUpdate operation to rollback and all remaining triggers to not run. The exception is ultimately passed to the caller of the tryUpdate method.
txn - nested transaction which trigger runs instorable - storable before being updatedPersistExceptionabortTry()public void afterUpdate(S storable, java.lang.Object state) throws PersistException
Any exception thrown by this method will cause the update operation to rollback and all remaining triggers to not run. The exception is ultimately passed to the caller of the update method.
storable - storable after being updatedstate - optional object returned by beforeUpdate methodPersistExceptionpublic void afterTryUpdate(S storable, java.lang.Object state) throws PersistException
afterUpdate(S, java.lang.Object).
Only override if trigger needs to distinguish between different update
variants.
Any exception thrown by this method will cause the tryUpdate operation to rollback and all remaining triggers to not run. The exception is ultimately passed to the caller of the tryUpdate method.
storable - storable after being updatedstate - object returned by beforeTryUpdate methodPersistExceptionabortTry()public void failedUpdate(S storable, java.lang.Object state)
Any exception thrown by this method will be passed to the current thread's uncaught exception handler.
storable - storable which failed to be updatedstate - optional object returned by beforeUpdate
method, but it may be nullpublic java.lang.Object beforeDelete(S storable) throws PersistException
Any exception thrown by this method will cause the delete operation to rollback and all remaining triggers to not run. The exception is ultimately passed to the caller of the delete method.
storable - storable before being deletedPersistExceptionpublic java.lang.Object beforeDelete(Transaction txn, S storable) throws PersistException
beforeDelete(Object). Only override if access to
the transaction is required.
Any exception thrown by this method will cause the delete operation to rollback and all remaining triggers to not run. The exception is ultimately passed to the caller of the delete method.
txn - nested transaction which trigger runs instorable - storable before being deletedPersistExceptionpublic java.lang.Object beforeTryDelete(S storable) throws PersistException
beforeDelete(Object). Only override
if trigger needs to distinguish between different delete variants.
Any exception thrown by this method will cause the tryDelete operation to rollback and all remaining triggers to not run. The exception is ultimately passed to the caller of the tryDelete method.
storable - storable before being deletedPersistExceptionabortTry()public java.lang.Object beforeTryDelete(Transaction txn, S storable) throws PersistException
beforeTryDelete(Object). Only
override if trigger needs access to the transaction and to distinguish
between different delete variants.
Any exception thrown by this method will cause the tryDelete operation to rollback and all remaining triggers to not run. The exception is ultimately passed to the caller of the tryDelete method.
txn - nested transaction which trigger runs instorable - storable before being deletedPersistExceptionabortTry()public void afterDelete(S storable, java.lang.Object state) throws PersistException
Any exception thrown by this method will cause the delete operation to rollback and all remaining triggers to not run. The exception is ultimately passed to the caller of the delete method.
storable - storable after being deletedstate - optional object returned by beforeDelete methodPersistExceptionpublic void afterTryDelete(S storable, java.lang.Object state) throws PersistException
afterDelete(S, java.lang.Object).
Only override if trigger needs to distinguish between different delete
variants.
Any exception thrown by this method will cause the tryDelete operation to rollback and all remaining triggers to not run. The exception is ultimately passed to the caller of the tryDelete method.
storable - storable after being deletedstate - object returned by beforeTryDelete methodPersistExceptionabortTry()public void failedDelete(S storable, java.lang.Object state)
Any exception thrown by this method will be passed to the current thread's uncaught exception handler.
storable - storable which failed to be deletedstate - optional object returned by beforeDelete
method, but it may be nullpublic void afterLoad(S storable) throws FetchException
storable - storable after being loaded or fetchedFetchExceptionprotected Trigger.Abort abortTry() throws Trigger.Abort
This method never returns normally, but as a convenience, a return
type is defined. The abort exception can be thrown by throw abortTry(),
but the throw keyword is not needed.
Trigger.AbortCopyright © 2006-2013 Amazon Technologies, Inc.. All Rights Reserved.