@Dependent @Alternative public class EnvironmentAwareTransactionStrategy extends BeanManagedUserTransactionStrategy
This alternative TransactionStrategy uses auto-detection and
can be used for different (parallel) persistence-units which use different transaction-types or
if different environments (dev., prod.,...) should use different transaction-types.
This implementation can be used for environments which allow a mixed usage of JTA and RESOURCE_LOCAL. (Within a transactional call it isn't possible to mix different transaction-types.) E.g.: in an application-server this class allows to use a persistence-unit with transaction-type="RESOURCE_LOCAL" + non-jta-data-source in parallel to a persistence-unit with transaction-type="JTA" + jta-data-source
Optional:
E.g. in case of a project-stage based logic
org.apache.deltaspike.core.api.exclude.Exclude can be used to switch between different
producer-beans.
It's a better alternative than extending
BeanManagedUserTransactionStrategy
(which would lead to an impl. dependency) only for using
org.apache.deltaspike.core.api.exclude.Exclude at the custom
TransactionStrategy
(or doing a custom veto-extension).
USER_TRANSACTION_JNDI_NAME| Constructor and Description |
|---|
EnvironmentAwareTransactionStrategy() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
beforeProceed(EntityManagerEntry entityManagerEntry)
Needed because the
EntityManager might get created outside of the UserTransaction
(e.g. depending on the implementation of the producer). |
protected EntityManagerEntry |
createEntityManagerEntry(javax.persistence.EntityManager entityManager,
Class<? extends Annotation> qualifier) |
protected javax.persistence.EntityTransaction |
getTransaction(EntityManagerEntry entityManagerEntry) |
protected void |
onCloseTransactionScope() |
applyTransactionTimeout, getDefaultTransactionTimeoutInSeconds, resolveUserTransactionexecute, prepareException, resolveEntityManagerBeanprotected EntityManagerEntry createEntityManagerEntry(javax.persistence.EntityManager entityManager, Class<? extends Annotation> qualifier)
createEntityManagerEntry in class BeanManagedUserTransactionStrategyprotected void beforeProceed(EntityManagerEntry entityManagerEntry)
BeanManagedUserTransactionStrategyEntityManager might get created outside of the UserTransaction
(e.g. depending on the implementation of the producer).
Can't be in BeanManagedUserTransactionStrategy.UserTransactionAdapter.begin()
because ResourceLocalTransactionStrategy needs to do
if (!transaction.isActive())
{
transaction.begin();
}
for the EntityTransaction of every EntityManager
and BeanManagedUserTransactionStrategy.UserTransactionAdapter.isActive()
can only use the status information of the UserTransaction and therefore
BeanManagedUserTransactionStrategy.UserTransactionAdapter.begin()
will only executed once, but EntityManager.joinTransaction()
needs to be called for every EntityManager.beforeProceed in class BeanManagedUserTransactionStrategyentityManagerEntry - entry of the current entity-managerprotected javax.persistence.EntityTransaction getTransaction(EntityManagerEntry entityManagerEntry)
getTransaction in class BeanManagedUserTransactionStrategyentityManagerEntry - entry of the current entity-managerEntityTransaction of the given EntityManager.
A subclass can also return an adapter e.g. for an UserTransactionprotected void onCloseTransactionScope()
onCloseTransactionScope in class ResourceLocalTransactionStrategyCopyright © 2011-2013 The Apache Software Foundation. All Rights Reserved.