org.axonframework.commandhandling.interceptors
Class TransactionInterceptor<T>

java.lang.Object
  extended by org.axonframework.commandhandling.interceptors.TransactionInterceptor<T>
Type Parameters:
T - The type of object representing the transaction
All Implemented Interfaces:
CommandHandlerInterceptor
Direct Known Subclasses:
SpringTransactionalInterceptor

public abstract class TransactionInterceptor<T>
extends Object
implements CommandHandlerInterceptor

Abstract implementation of a CommandHandlerInterceptor that starts a transaction and binds a UnitOfWork to the current thread.

Upon successful execution of the command, the transaction is committed. If execution fails, the UnitOfWork and the transaction are rolled back.

Since:
0.6
Author:
Allard Buijze

Constructor Summary
TransactionInterceptor()
           
 
Method Summary
protected abstract  void commitTransaction(T transaction)
          Commits the transaction for the command execution described by the given context.
 Object handle(Object command, UnitOfWork unitOfWork, InterceptorChain interceptorChain)
          The handle method is invoked each time a command is dispatched through the event bus that the CommandHandlerInterceptor is declared on.
protected abstract  void rollbackTransaction(T transaction)
          Rolls back a transaction for a command execution described by the given context.
protected abstract  T startTransaction()
          Start a new transaction for a command execution described by the given context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TransactionInterceptor

public TransactionInterceptor()
Method Detail

handle

public Object handle(Object command,
                     UnitOfWork unitOfWork,
                     InterceptorChain interceptorChain)
              throws Throwable
Description copied from interface: CommandHandlerInterceptor
The handle method is invoked each time a command is dispatched through the event bus that the CommandHandlerInterceptor is declared on. The incoming command and contextual information can be found in the given commandContext.

The interceptor is responsible for the continuation of the dispatch process by invoking the InterceptorChain.proceed(Object) method on the given interceptorChain.

Any information gathered by interceptors may be attached to the command context. This information is made available to the CommandCallback provided by the dispatching component.

Interceptors are highly recommended not to change the type of the command handling result, as the dispatching component might expect a result of a specific type.

Specified by:
handle in interface CommandHandlerInterceptor
Parameters:
command - The command being dispatched
unitOfWork - The UnitOfWork in which
interceptorChain - The interceptor chain that allows this interceptor to proceed the dispatch process
Returns:
the result of the command handler. May have been modified by interceptors.
Throws:
Throwable - any exception that occurs while handling the command

startTransaction

protected abstract T startTransaction()
Start a new transaction for a command execution described by the given context. The given unitOfWork is the unitOfWork bound to the current thread.

Returns:
A reference to the current transaction

commitTransaction

protected abstract void commitTransaction(T transaction)
Commits the transaction for the command execution described by the given context. The given unitOfWork is the unitOfWork bound to the current thread.

Parameters:
transaction - The transaction object returned during during startTransaction()

rollbackTransaction

protected abstract void rollbackTransaction(T transaction)
Rolls back a transaction for a command execution described by the given context. The given unitOfWork is the unitOfWork bound to the current thread.

Parameters:
transaction - The transaction object returned during during startTransaction()


Copyright © 2011. All Rights Reserved.