T
- The type of TransactionRunnable which this TransactionRunnable must be run inside of.
A TransactionRunnable which alters a database through Hibernate would fail if it was
started outside of a TransactionRunnable which began and committed a transaction around
it. A class which extends TransactionRunnable<DatabaseTransactionRunnable>
can only be
run inside of a DatabaseTransactionRunnable or a subclass of it. Breaking that rule will
be a compile time error.public class TransactionRunnable<T> extends Object
<T>
specify that it can only be run inside of a certain type of TransactionRunnable.Constructor and Description |
---|
TransactionRunnable() |
Modifier and Type | Method and Description |
---|---|
protected void |
commit()
Commit this and all of the chained runnables.
|
protected void |
complete()
Run onComplete() on this and each of the chained runnables.
|
protected T |
getContext()
Get whatever is required by this TransactionRunnable.
|
protected void |
onCommit()
This will be run after onRun is complete.
|
protected void |
onComplete()
This will be run when after onCommit or onRollback no matter the outcome.
|
protected void |
onPreRun()
This will be run first.
|
protected void |
onRollback()
This will run if the transaction fails.
|
protected void |
onRun()
This will be run after preRun and before onCommit.
|
protected void |
preRun()
PreRun this and all of the chained runnables.
|
protected void |
rollback()
Rollback this and all of the chained runnables.
|
protected void |
run()
Run this and all of the chained runnables.
|
<U extends T> |
runIn(TransactionRunnable<U> parentRunnable)
Run this TransactionRunnable inside of a "parent" runnable.
|
public <U extends T> TransactionRunnable<U> runIn(TransactionRunnable<U> parentRunnable)
TransactionRunnable<DatabaseTransaction>
of a TransactionRunnable which does not offer database
access. However, when you add a runnable which does not need or offer database access to one which
does, this function returns that runnable casted to a type which does offer database access
(since it is running in one which does).
StartableTransactionRunnable<DbTransaction> transaction = new DbTransactionRunnable();
StartableTransactionRunnable<Standalone> standalone = new StandaloneTransactionRunnable();
TransactionRunnable<DbTransaction> runnableRequiringDb = new DbRequiringTransactionRunnable();
// This will not compile:
runnableRequiringDb.runIn(standalone);
// Because if it did, it would allow you to do this:
standalone.start();
// Ut oh, using the database outside of a transaction!
// This will work:
TransactionRunnable<DbTransaction> castedStandalone = standalone.runIn(transaction);
runnableRequiringDb.runIn(castedStandalone);
transaction.start();
U
- The type of capabilities provided by the parent runnable.
This defines the state which the state which the storage engine is guaranteed to be in
when this runnable starts. It must extend the type of capabilities required by this
runnable.parentRunnable
- the TransactionRunnable to run this runnable inside of.IllegalStateException
- if this function has already been called on this runnable because a
TransactionRunnable may only be run once.IllegalArgumentException
- if this runnable is an ancestor of the parentRunnable as it would
create an unresolvable loop.protected T getContext()
ProvidingTransactionRunnable
this will get what is required
by that runnable, not what is provided. To get the provided context from a
ProvidingTransactionRunnable
use ProvidingTransactionRunnable.getProvidedContext()
protected void onPreRun() throws Exception
Exception
- which will cause the execution of
onRollback then onComplete before being wrapped in a TransactionException and rethrown.protected void onRun() throws Exception
Exception
- which will cause a rollback of the transaction and then execution of
onRollback then onComplete before being wrapped in a TransactionException and rethrown.protected void onCommit() throws Exception
Exception
- which will stop the committing process and cause onRollback to be invoked on each
of the runnables in the chain before being wrapped in a TransactionException and
rethrown.protected void onRollback() throws Exception
RootTransactionRunnable
which it cannot be run inside of another runnable.Exception
- which will be reported as the cause of possible storage corruption.
before being wrapped in a TransactionException and rethrown.protected void onComplete() throws Exception
Exception
- which will be reported as a failure which cannot cause database corruption.protected final void preRun() throws TransactionException
TransactionException
- if an exception is thrown by this or one of the chained runnables'
onPreRun() functions, also may contain exceptions thrown by one or more
of the chained runnables' onComplete() functions.protected final void run() throws TransactionException
TransactionException
- made by grouping together whatever is thrown by this or one of the
chained runnables' onRun() functions and whatever might be thrown by
onRollback() or onComplete() which are called if somethign goes wrong.protected final void commit() throws TransactionException
TransactionException
- made from the exception thrown by this or one of the child runnables'
onCommit function or rollback or complete.protected final void rollback() throws TransactionException
TransactionException
- made from gathering whatever exceptions were thrown
running onRollback() on this and the child runnables.protected final void complete() throws TransactionException
TransactionException
- if one or more of the runnables throw any exception.Copyright © 2004–2021 XWiki. All rights reserved.