|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.amazon.carbonado.Trigger<S>
public abstract class Trigger<S>
Callback mechanism to allow custom code to run when a storable is
persisted. By default, the methods defined in this class do
nothing. Subclass and override trigger conditions of interest, and then
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.
| Nested Class Summary | |
|---|---|
static class |
Trigger.Abort
|
| Constructor Summary | |
|---|---|
Trigger()
|
|
| Method Summary | |
|---|---|
protected Trigger.Abort |
abortTry()
Call to quickly abort a "try" operation, returning false to the caller. |
void |
afterDelete(S storable,
Object state)
Called right after a storable has been successfully deleted. |
void |
afterInsert(S storable,
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,
Object state)
Called right after a storable has been successfully deleted via tryDelete. |
void |
afterTryInsert(S storable,
Object state)
Called right after a storable has been successfully inserted via tryInsert. |
void |
afterTryUpdate(S storable,
Object state)
Called right after a storable has been successfully updated via tryUpdate. |
void |
afterUpdate(S storable,
Object state)
Called right after a storable has been successfully updated. |
Object |
beforeDelete(S storable)
Called before a storable is to be deleted. |
Object |
beforeInsert(S storable)
Called before a storable is to be inserted. |
Object |
beforeTryDelete(S storable)
Called before a storable is to be deleted via tryDelete. |
Object |
beforeTryInsert(S storable)
Called before a storable is to be inserted via tryInsert. |
Object |
beforeTryUpdate(S storable)
Called before a storable is to be updated via tryUpdate. |
Object |
beforeUpdate(S storable)
Called before a storable is to be updated. |
void |
failedDelete(S storable,
Object state)
Called when an delete operation failed because the record was missing or an exception was thrown. |
void |
failedInsert(S storable,
Object state)
Called when an insert operation failed due to a unique constraint violation or an exception was thrown. |
void |
failedUpdate(S storable,
Object state)
Called when an update operation failed because the record was missing or an exception was thrown. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Trigger()
| Method Detail |
|---|
public 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 inserted
PersistException
public Object beforeTryInsert(S storable)
throws PersistException
beforeInsert(S). 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 inserted
PersistExceptionabortTry()
public void afterInsert(S storable,
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 method
PersistException
public void afterTryInsert(S storable,
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 method
PersistExceptionabortTry()
public void failedInsert(S storable,
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 null
public 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 updated
PersistException
public Object beforeTryUpdate(S storable)
throws PersistException
beforeUpdate(S). 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 updated
PersistExceptionabortTry()
public void afterUpdate(S storable,
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 method
PersistException
public void afterTryUpdate(S storable,
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 method
PersistExceptionabortTry()
public void failedUpdate(S storable,
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 null
public 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 deleted
PersistException
public Object beforeTryDelete(S storable)
throws PersistException
beforeDelete(S). 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 deleted
PersistExceptionabortTry()
public void afterDelete(S storable,
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 method
PersistException
public void afterTryDelete(S storable,
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 method
PersistExceptionabortTry()
public void failedDelete(S storable,
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 null
public void afterLoad(S storable)
throws FetchException
storable - storable after being loaded or fetched
FetchException
protected 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.Abort
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||