Package com.groiss.component
Class BeanManager
java.lang.Object
com.groiss.component.BeanManager
Manages transaction aware components (="beans").
The beans should implement
javax.ejb.SessionSynchronization
.-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Add a bean to the list of known user bean classes.static void
Add a bean to the list of known bean classes.static void
afterCommit
(VoidCallable callable) Register a callable to be executed after transaction commit.static void
afterRollback
(VoidCallable callable) Register a callable to be executed after transaction rollback.static void
beforeCompletion
(VoidCallable callable) Register a callable to be executed before transaction commit.static void
Deprecated, for removal: This API element is subject to removal in a future version.static void
commit()
Commits the transaction and releases all beans.static void
executeDeferred
(VoidCallable callable) Register a callable to be executed by the EventDispatcher thread after transaction commit.static Object
Gets a bean instance for a bean class registered with a key.static UserTransaction
The client or the bean manager itself gets a UserTransaction.static UserTransaction
getUserTransaction
(String name) The client or the bean manager itself gets a UserTransaction.static boolean
static void
rollback()
Rolls back the transaction and releases all beans.static void
static void
setExplicitTransactionMode
(boolean value) Deprecated, for removal: This API element is subject to removal in a future version.static void
-
Method Details
-
beforeCompletion
Register a callable to be executed before transaction commit. Exceptions thrown by the callable will lead to rollback of the transaction.- Parameters:
callable
- the VoidCallable to execute
-
afterCommit
Register a callable to be executed after transaction commit. Exceptions thrown by the callable will be caught and ignored.- Parameters:
callable
- the VoidCallable to execute
-
afterRollback
Register a callable to be executed after transaction rollback. Exceptions thrown by the callable will be caught and ignored.- Parameters:
callable
- the VoidCallable to execute
-
executeDeferred
Register a callable to be executed by the EventDispatcher thread after transaction commit. Each callable is executed in its own transaction. Exceptions lead to rollback of this separate transaction.- Parameters:
callable
- the VoidCallable to execute
-
getBean
Gets a bean instance for a bean class registered with a key.- Parameters:
key
- the key which was used to register a bean class- Returns:
- a bean instance
-
addBean
Add a bean to the list of known bean classes.- Parameters:
key
- a unique key for the beanservice
- the beans classisSystemBean
- true, if the bean is an internal @enterprise bean. Do not use this call in application code.
-
addBean
Add a bean to the list of known user bean classes.- Parameters:
key
- a unique key for the beanservice
- the beans class
-
commit
public static void commit()Commits the transaction and releases all beans. -
rollback
public static void rollback()Rolls back the transaction and releases all beans. -
rollbackTransaction
-
hasActiveUserTransaction
public static boolean hasActiveUserTransaction() -
getUserTransaction
The client or the bean manager itself gets a UserTransaction. -
getUserTransaction
The client or the bean manager itself gets a UserTransaction. -
bindThreadToTransaction
@Deprecated(since="11.0", forRemoval=true) public static void bindThreadToTransaction(UserTransaction ut) Deprecated, for removal: This API element is subject to removal in a future version. -
unbindThreadFromTransaction
public static void unbindThreadFromTransaction() -
setExplicitTransactionMode
@Deprecated(since="11.0", forRemoval=true) public static void setExplicitTransactionMode(boolean value) Deprecated, for removal: This API element is subject to removal in a future version.If set to true, a thread will not get a usertransaction when calling methodgetUserTransaction()
or methodgetUserTransaction(String)
with null as parameter. Instead an exception will be thrown.
-