org.axonframework.unitofwork
Class CurrentUnitOfWork

java.lang.Object
  extended by org.axonframework.unitofwork.CurrentUnitOfWork

public abstract class CurrentUnitOfWork
extends Object

Default entry point to gain access to the current UnitOfWork. Components managing transactional boundaries can register and clear UnitOfWork instances, which components can use.

Since:
0.6
Author:
Allard Buijze

Method Summary
static void clear(UnitOfWork unitOfWork)
          Clears the UnitOfWork currently bound to the current thread, if that UnitOfWork is the given unitOfWork.
static void commit()
          Commits the current UnitOfWork.
static UnitOfWork get()
          Gets the UnitOfWork bound to the current thread.
static boolean isStarted()
          Indicates whether a unit of work has already been started.
static void set(UnitOfWork unitOfWork)
          Binds the given unitOfWork to the current thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isStarted

public static boolean isStarted()
Indicates whether a unit of work has already been started. This method can be used by interceptors to prevent nesting of UnitOfWork instances.

Returns:
whether a UnitOfWork has already been started.

get

public static UnitOfWork get()
Gets the UnitOfWork bound to the current thread. If no UnitOfWork has been started, an IllegalStateException is thrown.

To verify whether a UnitOfWork is already active, use isStarted().

Returns:
The UnitOfWork bound to the current thread.
Throws:
IllegalStateException - if no UnitOfWork is active

commit

public static void commit()
Commits the current UnitOfWork. If no UnitOfWork was started, an IllegalStateException is thrown.

Throws:
IllegalStateException - if no UnitOfWork is currently started.
See Also:
UnitOfWork.commit()

set

public static void set(UnitOfWork unitOfWork)
Binds the given unitOfWork to the current thread. If other UnitOfWork instances were bound, they will be marked as inactive until the given UnitOfWork is cleared.

Parameters:
unitOfWork - The UnitOfWork to bind to the current thread.

clear

public static void clear(UnitOfWork unitOfWork)
Clears the UnitOfWork currently bound to the current thread, if that UnitOfWork is the given unitOfWork. Otherwise, nothing happens.

Parameters:
unitOfWork - The UnitOfWork expected to be bound to the current thread.
Throws:
IllegalStateException - when the given UnitOfWork was not the current active UnitOfWork. This exception indicates a potentially wrong nesting of Units Of Work.


Copyright © 2010-2016. All Rights Reserved.