You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by gp...@apache.org on 2012/06/06 14:06:29 UTC
git commit: DELTASPIKE-175 cleanup and fixed dispose of
@TransactionScoped beans
Updated Branches:
refs/heads/master f9becf71d -> 3b16c367a
DELTASPIKE-175 cleanup and fixed dispose of @TransactionScoped beans
Project: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/commit/3b16c367
Tree: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/tree/3b16c367
Diff: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/diff/3b16c367
Branch: refs/heads/master
Commit: 3b16c367a829f28192f2d4d7509057fef73b72bf
Parents: f9becf7
Author: gpetracek <gp...@apache.org>
Authored: Wed Jun 6 14:03:59 2012 +0200
Committer: gpetracek <gp...@apache.org>
Committed: Wed Jun 6 14:03:59 2012 +0200
----------------------------------------------------------------------
.../transaction/PersistenceStrategyHelper.java | 14 ++---------
.../ResourceLocalPersistenceStrategy.java | 18 ++++----------
.../context/TransactionBeanStorage.java | 12 +++++----
.../transaction/context/TransactionContext.java | 1 -
4 files changed, 15 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/3b16c367/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/PersistenceStrategyHelper.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/PersistenceStrategyHelper.java b/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/PersistenceStrategyHelper.java
index f9c102a..3202d44 100644
--- a/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/PersistenceStrategyHelper.java
+++ b/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/PersistenceStrategyHelper.java
@@ -30,6 +30,7 @@ import javax.persistence.EntityManager;
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@@ -59,9 +60,7 @@ public class PersistenceStrategyHelper implements Serializable
public Set<Class<? extends Annotation>> resolveEntityManagerQualifiers(Transactional transactionalAnnotation,
Class interceptedTargetClass)
{
- HashSet<Class<? extends Annotation>> emQualifiers;
-
-
+ Set<Class<? extends Annotation>> emQualifiers = new HashSet<Class<? extends Annotation>>();
Class<? extends Annotation>[] qualifierClasses = null;
if (transactionalAnnotation != null)
@@ -73,17 +72,12 @@ public class PersistenceStrategyHelper implements Serializable
{
// this means we have no special EntityManager configured in the interceptor
// thus we should scan all the EntityManagers ourselfs from the intercepted class
- emQualifiers = new HashSet<Class<? extends Annotation>>();
collectEntityManagerQualifiersOnClass(emQualifiers, interceptedTargetClass);
}
else
{
// take the qualifierKeys from the qualifierClasses
- emQualifiers = new HashSet<Class<? extends Annotation>>();
- for (Class<? extends Annotation> qualifier : qualifierClasses)
- {
- emQualifiers.add(qualifier);
- }
+ Collections.addAll(emQualifiers, qualifierClasses);
}
return emQualifiers;
@@ -188,6 +182,4 @@ public class PersistenceStrategyHelper implements Serializable
return null;
}
-
-
}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/3b16c367/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/ResourceLocalPersistenceStrategy.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/ResourceLocalPersistenceStrategy.java b/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/ResourceLocalPersistenceStrategy.java
index f69935e..9742f02 100644
--- a/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/ResourceLocalPersistenceStrategy.java
+++ b/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/ResourceLocalPersistenceStrategy.java
@@ -73,7 +73,6 @@ public class ResourceLocalPersistenceStrategy implements PersistenceStrategy
@Inject
private PersistenceStrategyHelper persistenceHelper;
-
public Object execute(InvocationContext invocationContext) throws Exception
{
Transactional transactionalAnnotation = persistenceHelper.extractTransactionalAnnotation(invocationContext);
@@ -93,9 +92,9 @@ public class ResourceLocalPersistenceStrategy implements PersistenceStrategy
}
// the 'layer' of the transactional invocation, aka the refCounter
+ @SuppressWarnings("UnusedDeclaration")
int transactionLayer = transactionBeanStorage.incrementRefCounter();
-
for (Class<? extends Annotation> emQualifier : emQualifiers)
{
EntityManager entityManager = resolveEntityManagerForQualifier(emQualifier);
@@ -105,7 +104,6 @@ public class ResourceLocalPersistenceStrategy implements PersistenceStrategy
ems.add(entityManager);
}
-
Exception firstException = null;
try
@@ -153,7 +151,7 @@ public class ResourceLocalPersistenceStrategy implements PersistenceStrategy
}
}
- // drop all EntityManagers from the ThreadLocal
+ // drop all EntityManagers from the request-context cache
transactionBeanStorage.cleanUsedEntityManagers();
}
@@ -162,7 +160,6 @@ public class ResourceLocalPersistenceStrategy implements PersistenceStrategy
// rethrow the exception
throw e;
-
}
finally
{
@@ -175,7 +172,6 @@ public class ResourceLocalPersistenceStrategy implements PersistenceStrategy
// commit stability over various databases!
if (isOutermostInterceptor)
{
-
// only commit all transactions if we didn't rollback
// them already
if (firstException == null)
@@ -227,11 +223,9 @@ public class ResourceLocalPersistenceStrategy implements PersistenceStrategy
}
}
}
-
- // and now we close the open transaction scope
- transactionBeanStorage.endTransactionScope();
}
-
+ // and now we close the open transaction scope
+ transactionBeanStorage.endTransactionScope();
}
transactionBeanStorage.decrementRefCounter();
@@ -244,7 +238,6 @@ public class ResourceLocalPersistenceStrategy implements PersistenceStrategy
}
}
-
private EntityManager resolveEntityManagerForQualifier(Class<? extends Annotation> emQualifier)
{
Bean<EntityManager> entityManagerBean = resolveEntityManagerBean(emQualifier);
@@ -267,11 +260,10 @@ public class ResourceLocalPersistenceStrategy implements PersistenceStrategy
*/
protected Exception prepareException(Exception e)
{
+ //TODO integrate with the exception-handler provided by ds-core
return e;
}
-
-
protected Bean<EntityManager> resolveEntityManagerBean(Class<? extends Annotation> qualifierClass)
{
Set<Bean<?>> entityManagerBeans = beanManager.getBeans(EntityManager.class, new AnyLiteral());
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/3b16c367/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/context/TransactionBeanStorage.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/context/TransactionBeanStorage.java b/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/context/TransactionBeanStorage.java
index f6a6b49..f892663 100644
--- a/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/context/TransactionBeanStorage.java
+++ b/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/context/TransactionBeanStorage.java
@@ -107,7 +107,6 @@ public class TransactionBeanStorage
return currentTci.refCounter.decrementAndGet();
}
-
/**
* @return <code>true</code> if we are the outermost interceptor over all qualifiers
* and the TransactionBeanStorage is yet empty.
@@ -119,7 +118,6 @@ public class TransactionBeanStorage
/**
* Start a new TransactionScope
- * @return the
*/
public void startTransactionScope()
{
@@ -142,7 +140,6 @@ public class TransactionBeanStorage
* in the context.
*
* This method only gets used if we leave a transaction with REQUIRES_NEW.
- * In all other cases we use {@link #endAllTransactionScopes()}.
*/
public void endTransactionScope()
{
@@ -156,6 +153,7 @@ public class TransactionBeanStorage
if (oldTci.size() > 0)
{
currentTci = oldTci.pop();
+ endTransactionScope();
}
else
{
@@ -199,6 +197,10 @@ public class TransactionBeanStorage
@PreDestroy
public void requestEnded()
{
+ if (!isEmpty())
+ {
+ LOGGER.warning("the current TransactionContextInfo isn't empty. a fallback cleanup will be performed.");
+ }
endAllTransactionScopes();
}
@@ -216,9 +218,9 @@ public class TransactionBeanStorage
*/
private void destroyBeans(Map<Contextual, TransactionBeanEntry> activeBeans)
{
- for (TransactionBeanEntry beanBag : activeBeans.values())
+ for (TransactionBeanEntry beanEntry : activeBeans.values())
{
- beanBag.getBean().destroy(beanBag.getContextualInstance(), beanBag.getCreationalContext());
+ beanEntry.getBean().destroy(beanEntry.getContextualInstance(), beanEntry.getCreationalContext());
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/3b16c367/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/context/TransactionContext.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/context/TransactionContext.java b/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/context/TransactionContext.java
index f75e4fe..7a86b53 100644
--- a/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/context/TransactionContext.java
+++ b/deltaspike/modules/jpa/impl/src/main/java/org/apache/deltaspike/jpa/impl/transaction/context/TransactionContext.java
@@ -42,7 +42,6 @@ public class TransactionContext implements Context
// got started.
private TransactionBeanStorage beanStorage;
-
public <T> T get(Contextual<T> component)
{
Map<Contextual, TransactionBeanEntry> transactionBeanEntryMap = getBeanStorage().getActiveTransactionContext();