|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.multiverse.templates.TransactionTemplate<E>
public abstract class TransactionTemplate<E>
A Template that handles the boilerplate code for transactions. A transaction will be started if none is available around a section and if all goes right, the transaction is committed at the end.
example:
new TransactionTemplate(){
Object execute(Transaction t){
queue.push(1);
return null;
}
}.execute();
TransactionFactory
and createReference read tracking update transaction by default. But if you want a better performance, you need to pass your
own TransactionFactory. One of the biggest reasons is that the system else is not able to do runtime optimizations
like selecting better transaction implementation.
ThreadLocalTransaction for a running transaction, and if one is available, it doesn't createReference its own. But in some
cases you don't want to rely on a threadlocal, for example when you are not using instrumentation, it is possible to
totally ignore the ThreadLocalTransaction.
| Nested Class Summary | |
|---|---|
static class |
TransactionTemplate.InvisibleCheckedException
|
| Constructor Summary | |
|---|---|
TransactionTemplate()
Creates a new TransactionTemplate that uses the STM stored in the GlobalStmInstance and works the the ThreadLocalTransaction. |
|
TransactionTemplate(Stm stm)
Creates a new TransactionTemplate using the provided STM. |
|
TransactionTemplate(TransactionFactory txFactory)
Creates a new TransactionTemplate with the provided TransactionFactory and that is aware of the ThreadLocalTransaction. |
|
TransactionTemplate(TransactionFactory txFactory,
boolean threadLocalAware,
boolean lifecycleListenersEnabled,
boolean retryEnabled)
Creates a new TransactionTemplate with the provided TransactionFactory. |
|
| Method Summary | |
|---|---|
E |
execute()
Executes the template. |
abstract E |
execute(Transaction tx)
This is the method that needs to be implemented. |
E |
executeChecked()
Executes the Template and rethrows the checked exception instead of wrapping it in a InvisibleCheckedException. |
TransactionFactory |
getTransactionFactory()
Returns the TransactionFactory this TransactionTemplate uses to createReference Transactions. |
boolean |
isLifecycleListenersEnabled()
Checks if the lifecycle listeners on this TransactionTemplate have been enabled. |
boolean |
isThreadLocalAware()
Checks if the TransactionTemplate should work together with the ThreadLocalTransaction. |
protected void |
onInit()
Lifecycle method that is called when this TransactionTemplate is about to begin. |
protected void |
onPostAbort()
Transaction lifecycle method that is called before an abort is executed. |
protected void |
onPostCommit()
Lifecycle method that is called when this TransactionTemplate has executed a commit. |
protected void |
onPreAbort(Transaction tx)
Transaction Lifecycle method that is called after a transaction was aborted. |
protected void |
onPreCommit(Transaction tx)
Lifecycle method that is called when this TransactionTemplate wants to execute. |
protected void |
onStart(Transaction tx)
Lifecycle method that is called every time the transaction is started. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public TransactionTemplate()
ThreadLocalTransaction. It automatically creates update transactions that are able to track
reads.
This constructor should only be used for experimentation purposes. If you want something fast, you need to pass
in a TransactionFactory.
public TransactionTemplate(Stm stm)
ThreadLocalTransaction.
It automatically creats read tracking update transactions.
This constructor should only be used for experimentation purposes. If you want something fast, you need to pass
in a TransactionFactory.
stm - the stm to use for transactions.
NullPointerException - if stm is null.public TransactionTemplate(TransactionFactory txFactory)
txFactory - the TransactionFactory used to createReference Transactions.
NullPointerException - if txFactory is null.
public TransactionTemplate(TransactionFactory txFactory,
boolean threadLocalAware,
boolean lifecycleListenersEnabled,
boolean retryEnabled)
txFactory - the TransactionFactory used to createReference Transactions.threadLocalAware - true if this TransactionTemplate should look at the ThreadLocalTransaction and publish
the running transaction there.lifecycleListenersEnabled - true if the lifecycle callback methods should be enabled. Enabling them causes
extra object creation, so if you want to squeeze out more performance, set this to false at the price of
not having the lifecycle methods working.| Method Detail |
|---|
public final boolean isThreadLocalAware()
public final boolean isLifecycleListenersEnabled()
public final TransactionFactory getTransactionFactory()
public abstract E execute(Transaction tx)
throws Exception
tx - the transaction used for this execution.
TransactionTemplate.InvisibleCheckedException - the Exception thrown
Exceptionprotected void onInit()
protected void onStart(Transaction tx)
tx - the Transaction that is started.protected void onPreCommit(Transaction tx)
tx - the Transaction that wants to commit.protected void onPostCommit()
protected void onPreAbort(Transaction tx)
tx - the transaction that currently is in the process of being aborted.protected void onPostAbort()
public final E execute()
execute(org.multiverse.api.Transaction) method.
TransactionTemplate.InvisibleCheckedException - if a checked exception was thrown while executing the execute(org.multiverse.api.Transaction) method.
DeadTransactionException - if the exception was explicitly aborted.
TooManyRetriesException - if the template retried the transaction too many times. The cause of the last
failure (also an exception) is included as cause. So you have some idea where
to look for problems
public final E executeChecked()
throws Exception
TransactionTemplate.InvisibleCheckedException - the Exception thrown inside the execute(org.multiverse.api.Transaction)
method.
DeadTransactionException - if the exception was explicitly aborted.
TooManyRetriesException - if the template retried the transaction too many times. The cause of the last
failure (also an exception) is included as cause. So you have some idea where to
look for problems
Exception
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||