Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

EXTCDI-305 do qualifier check only for EntityManagers

Other beans can have any Qualifier. 
This commit also fixes the ending of the TransactionContext to allow using
fresh transactions in a @PreDestroy of @TransactionScoped beans.


git-svn-id: https://svn.apache.org/repos/asf/myfaces/extensions/cdi/trunk@1440724 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
commit 72f34fa055cb43ace0a25001857914831d68e989 1 parent 7645eb2
@struberg struberg authored
View
2  ...jpa-module/api/src/main/java/org/apache/myfaces/extensions/cdi/jpa/api/Transactional.java
@@ -34,8 +34,6 @@
* The optional qualifier can be used to specify different entity managers.
*/
-//TODO instead of using #qualifier it should be possible to use a custom qualifier annotated with @TransactionQualifier
-
@InterceptorBinding
@Documented
@Inherited
View
49 .../apache/myfaces/extensions/cdi/jpa/impl/transaction/TransactionalInterceptorStrategy.java
@@ -136,33 +136,23 @@ public Object execute(InvocationContext invocationContext) throws Exception
for (Map.Entry<String, EntityManager> emsEntry: emsEntries.entrySet())
{
EntityManager em = emsEntry.getValue();
-
- try
+ transaction = em.getTransaction();
+ if (transaction != null && transaction.isActive())
{
- transaction = em.getTransaction();
-
- if (transaction != null && transaction.isActive())
+ try
{
- try
- {
- transaction.rollback();
- }
- catch (Exception eRollback)
+ transaction.rollback();
+ }
+ catch (Exception eRollback)
+ {
+ if(LOGGER.isLoggable(Level.SEVERE))
{
- if(LOGGER.isLoggable(Level.SEVERE))
- {
- LOGGER.log(Level.SEVERE,
- "Got additional Exception while subsequently " +
- "rolling back other SQL transactions", eRollback);
- }
+ LOGGER.log(Level.SEVERE,
+ "Got additional Exception while subsequently " +
+ "rolling back other SQL transactions", eRollback);
}
}
}
- catch (IllegalStateException e2)
- {
- //just happens if the setup is wrong -> we can't do a proper cleanup
- //but we have to continue to cleanup the scope
- }
}
// drop all EntityManagers from the ThreadLocal
@@ -240,15 +230,18 @@ public Object execute(InvocationContext invocationContext) throws Exception
}
}
+ ems.remove();
+ ems.set(null);
+
+ refCounterMaps.set(null);
+ refCounterMaps.remove();
+
// and now we close all open transactionscopes and reset the storage
- TransactionBeanStorage.getStorage().endAllTransactionScopes();
- TransactionBeanStorage.resetStorage();
- }
- else
- {
- //just happens if the wrong qualifier is used in an application
- TransactionBeanStorage.getStorage().endAllTransactionScopes();
+ TransactionBeanStorage oldStorage = TransactionBeanStorage.getStorage();
TransactionBeanStorage.resetStorage();
+
+ // we do this delayed to allow new transactions in a PreDestroy method
+ oldStorage.endAllTransactionScopes();
}
}
else
View
9 ...va/org/apache/myfaces/extensions/cdi/jpa/impl/transaction/context/TransactionContext.java
@@ -27,6 +27,7 @@
import javax.enterprise.context.spi.Contextual;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.Typed;
+import javax.persistence.EntityManager;
import java.lang.annotation.Annotation;
import java.util.Map;
@@ -88,6 +89,14 @@
private void checkTransactionBeanEntry(TransactionBeanEntry<?> transactionBeanEntry)
{
+ if (! (transactionBeanEntry.getContextualInstance() instanceof EntityManager))
+ {
+ return;
+ }
+
+ // we only do this special check for EntityManagers
+ // this detects the problem when someone uses a @Transactional(SomeQualifier.class)
+ // while using an @Inject @AnotherQualifier EntityManager em; ...
String activeTransactionKey = TransactionBeanStorage.getStorage().getActiveTransactionKey();
for(Annotation qualifier : transactionBeanEntry.getQualifiers())
Please sign in to comment.
Something went wrong with that request. Please try again.