|
||||||||||
| 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.
| Field Summary |
|---|
| Fields inherited from interface org.multiverse.MultiverseConstants |
|---|
___BUGSHAKER_ENABLED, ___TRACING_ENABLED |
| 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 transactionFactory)
Creates a new TransactionTemplate with the provided TransactionFactory and that is aware of the ThreadLocalTransaction. |
|
TransactionTemplate(TransactionFactory transactionFactory,
boolean threadLocalAware,
boolean lifecycleListenersEnabled)
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 |
onPostStart(Transaction tx)
Lifecycle method that is called every time the transaction is started. |
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. |
| 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 creates 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 transactionFactory)
transactionFactory - the TransactionFactory used to createReference Transactions.
NullPointerException - if txFactory is null.
public TransactionTemplate(TransactionFactory transactionFactory,
boolean threadLocalAware,
boolean lifecycleListenersEnabled)
transactionFactory - 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 abstract E execute(Transaction tx)
throws Exception
tx - the transaction used for this execution.
Exception - the Exception thrownpublic final boolean isThreadLocalAware()
public final boolean isLifecycleListenersEnabled()
public final TransactionFactory getTransactionFactory()
protected void onInit()
protected void onPostStart(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.
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
Exception - 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
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||