You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2012/01/26 23:29:08 UTC
svn commit: r1236419 - in /openejb/trunk/openejb/container/openejb-core/src:
main/java/org/apache/openejb/core/stateful/StatefulContainer.java
test/java/org/apache/openejb/core/stateful/PassivationWithEmTest.java
Author: rmannibucau
Date: Thu Jan 26 22:29:08 2012
New Revision: 1236419
URL: http://svn.apache.org/viewvc?rev=1236419&view=rev
Log:
OPENEJB-1759 don't use cache for stateful with extended persistence context - keeping it in fresh cache of the container
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/PassivationWithEmTest.java
Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java?rev=1236419&r1=1236418&r2=1236419&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContainer.java Thu Jan 26 22:29:08 2012
@@ -269,11 +269,13 @@ public class StatefulContainer implement
beanContext.setContainer(null);
beanContext.setContainerData(null);
- cache.removeAll(new CacheFilter<Instance>() {
- public boolean matches(Instance instance) {
- return beanContext == instance.beanContext;
- }
- });
+ if (!containsExtendedPersistenceContext(beanContext)) {
+ cache.removeAll(new CacheFilter<Instance>() {
+ public boolean matches(Instance instance) {
+ return beanContext == instance.beanContext;
+ }
+ });
+ }
}
public synchronized void deploy(BeanContext beanContext) throws OpenEJBException {
@@ -350,6 +352,11 @@ public class StatefulContainer implement
}
}
+ private static boolean containsExtendedPersistenceContext(final BeanContext beanContext) {
+ final Index<EntityManagerFactory, Map> factories = beanContext.getExtendedEntityManagerFactories();
+ return factories != null && factories.size() > 0;
+ }
+
protected ProxyInfo createEJBObject(BeanContext beanContext, Method callMethod, Object[] args, InterfaceType interfaceType) throws OpenEJBException {
// generate a new primary key
Object primaryKey = newPrimaryKey();
@@ -396,7 +403,9 @@ public class StatefulContainer implement
}
// add to cache
- cache.add(primaryKey, instance);
+ if (!containsExtendedPersistenceContext(beanContext)) { // no need to cache it it will never expires
+ cache.add(primaryKey, instance);
+ }
// instance starts checked-out
checkedOutInstances.put(primaryKey, instance);
@@ -661,7 +670,7 @@ public class StatefulContainer implement
Instance instance;
synchronized (primaryKey) {
instance = checkedOutInstances.get(primaryKey);
- if (instance == null) {
+ if (instance == null) { // no need to check for extended persistence contexts it shouldn't happen
try {
instance = cache.checkOut(primaryKey);
} catch (OpenEJBException e) {
@@ -755,7 +764,7 @@ public class StatefulContainer implement
// no longer in use
instance.setInUse(false);
- if (instance.getTransaction() == null) {
+ if (instance.getTransaction() == null && !containsExtendedPersistenceContext(instance.beanContext)) {
synchronized (instance.primaryKey) {
// return to cache
cache.checkIn(instance.primaryKey);
@@ -773,7 +782,9 @@ public class StatefulContainer implement
}
Instance instance = checkedOutInstances.remove(primaryKey);
- cache.remove(primaryKey);
+ if (!containsExtendedPersistenceContext(instance.beanContext)) {
+ cache.remove(primaryKey);
+ }
if (null != instance && null != instance.creationalContext) {
instance.creationalContext.release();
Modified: openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/PassivationWithEmTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/PassivationWithEmTest.java?rev=1236419&r1=1236418&r2=1236419&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/PassivationWithEmTest.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/PassivationWithEmTest.java Thu Jan 26 22:29:08 2012
@@ -36,7 +36,6 @@ public class PassivationWithEmTest {
}
@Test
- @Ignore("not working - extended should be ignred")
public void passivationExtendedTest() throws Exception {
final PassivationWithEmExtended ejb = (PassivationWithEmExtended) SystemInstance.get()
.getComponent(ContainerSystem.class).getJNDIContext()
@@ -59,7 +58,7 @@ public class PassivationWithEmTest {
public Persistence persistence() throws Exception {
PersistenceUnit unit = new PersistenceUnit("passivation-unit");
unit.addClass(MyEntity.class);
- unit.setTransactionType(TransactionType.RESOURCE_LOCAL);
+ unit.setTransactionType(TransactionType.JTA);
unit.setProperty("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
unit.getProperties().setProperty("openjpa.RuntimeUnenhancedClasses", "supported");
unit.setExcludeUnlistedClasses(true);