Author: gnodet
Date: Fri Sep 5 09:41:57 2014
New Revision: 1622665
URL: http://svn.apache.org/r1622665
Log:
[ARIES-885] Backport to jpa20
Added:
aries/trunk/jpa20/jpa-api/src/main/java/org/apache/aries/jpa/container/sync/
aries/trunk/jpa20/jpa-api/src/main/java/org/apache/aries/jpa/container/sync/Synchronization.java
aries/trunk/jpa20/jpa-api/src/main/java/org/apache/aries/jpa/container/sync/packageinfo
Modified:
aries/trunk/jpa20/jpa-api/pom.xml
aries/trunk/jpa20/jpa-blueprint-aries/pom.xml
aries/trunk/jpa20/jpa-blueprint-aries/src/main/java/org/apache/aries/jpa/blueprint/aries/impl/NSHandler.java
aries/trunk/jpa20/jpa-blueprint-aries/src/main/resources/org/apache/aries/jpa/blueprint/aries/nls/ariesBlueprintJpaMessages.properties
aries/trunk/jpa20/jpa-container-context/pom.xml
aries/trunk/jpa20/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/impl/ManagedPersistenceContextFactory.java
aries/trunk/jpa20/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/impl/PersistenceContextManager.java
aries/trunk/jpa20/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/transaction/impl/JTAEntityManager.java
aries/trunk/jpa20/jpa-container-itest/src/test/java/org/apache/aries/jpa/context/itest/JPAContextTest.java
Modified: aries/trunk/jpa20/jpa-api/pom.xml
URL:
http://svn.apache.org/viewvc/aries/trunk/jpa20/jpa-api/pom.xml?rev=1622665&r1=1622664&r2=1622665&view=diff
==============================================================================
--- aries/trunk/jpa20/jpa-api/pom.xml (original)
+++ aries/trunk/jpa20/jpa-api/pom.xml Fri Sep 5 09:41:57 2014
@@ -47,6 +47,7 @@
<aries.osgi.export.pkg>
org.apache.aries.jpa.container.parsing,
org.apache.aries.jpa.container,
+ org.apache.aries.jpa.container.sync,
org.apache.aries.jpa.container.context
</aries.osgi.export.pkg>
<aries.osgi.import>
Added:
aries/trunk/jpa20/jpa-api/src/main/java/org/apache/aries/jpa/container/sync/Synchronization.java
URL:
http://svn.apache.org/viewvc/aries/trunk/jpa20/jpa-api/src/main/java/org/apache/aries/jpa/container/sync/Synchronization.java?rev=1622665&view=auto
==============================================================================
---
aries/trunk/jpa20/jpa-api/src/main/java/org/apache/aries/jpa/container/sync/Synchronization.java
(added)
+++
aries/trunk/jpa20/jpa-api/src/main/java/org/apache/aries/jpa/container/sync/Synchronization.java
Fri Sep 5 09:41:57 2014
@@ -0,0 +1,27 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.jpa.container.sync;
+
+public interface Synchronization {
+
+ void preCall();
+
+ void postCall();
+
+}
Added:
aries/trunk/jpa20/jpa-api/src/main/java/org/apache/aries/jpa/container/sync/packageinfo
URL:
http://svn.apache.org/viewvc/aries/trunk/jpa20/jpa-api/src/main/java/org/apache/aries/jpa/container/sync/packageinfo?rev=1622665&view=auto
==============================================================================
---
aries/trunk/jpa20/jpa-api/src/main/java/org/apache/aries/jpa/container/sync/packageinfo
(added)
+++
aries/trunk/jpa20/jpa-api/src/main/java/org/apache/aries/jpa/container/sync/packageinfo
Fri Sep 5 09:41:57 2014
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+version 1.0.0
Modified: aries/trunk/jpa20/jpa-blueprint-aries/pom.xml
URL:
http://svn.apache.org/viewvc/aries/trunk/jpa20/jpa-blueprint-aries/pom.xml?rev=1622665&r1=1622664&r2=1622665&view=diff
==============================================================================
--- aries/trunk/jpa20/jpa-blueprint-aries/pom.xml (original)
+++ aries/trunk/jpa20/jpa-blueprint-aries/pom.xml Fri Sep 5 09:41:57 2014
@@ -76,9 +76,9 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.apache.aries.jpa</groupId>
+ <groupId>org.apache.aries.jpa20</groupId>
<artifactId>org.apache.aries.jpa.api</artifactId>
- <version>1.0.0</version>
+ <version>1.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Modified:
aries/trunk/jpa20/jpa-blueprint-aries/src/main/java/org/apache/aries/jpa/blueprint/aries/impl/NSHandler.java
URL:
http://svn.apache.org/viewvc/aries/trunk/jpa20/jpa-blueprint-aries/src/main/java/org/apache/aries/jpa/blueprint/aries/impl/NSHandler.java?rev=1622665&r1=1622664&r2=1622665&view=diff
==============================================================================
---
aries/trunk/jpa20/jpa-blueprint-aries/src/main/java/org/apache/aries/jpa/blueprint/aries/impl/NSHandler.java
(original)
+++
aries/trunk/jpa20/jpa-blueprint-aries/src/main/java/org/apache/aries/jpa/blueprint/aries/impl/NSHandler.java
Fri Sep 5 09:41:57 2014
@@ -18,6 +18,7 @@
*/
package org.apache.aries.jpa.blueprint.aries.impl;
+import java.lang.reflect.Method;
import java.net.URL;
import java.util.Arrays;
import java.util.Collection;
@@ -34,6 +35,7 @@ import javax.persistence.PersistenceCont
import javax.persistence.PersistenceContextType;
import javax.persistence.PersistenceUnit;
+import org.apache.aries.blueprint.Interceptor;
import org.apache.aries.blueprint.NamespaceHandler;
import org.apache.aries.blueprint.ParserContext;
import org.apache.aries.blueprint.PassThroughMetadata;
@@ -42,8 +44,10 @@ import org.apache.aries.blueprint.mutabl
import org.apache.aries.blueprint.mutable.MutableReferenceMetadata;
import org.apache.aries.jpa.container.PersistenceUnitConstants;
import org.apache.aries.jpa.container.context.PersistenceContextProvider;
+import org.apache.aries.jpa.container.sync.Synchronization;
import org.apache.aries.util.nls.MessageUtil;
import org.osgi.framework.Bundle;
+import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
import org.osgi.service.blueprint.reflect.BeanMetadata;
import org.osgi.service.blueprint.reflect.ComponentMetadata;
@@ -236,6 +240,41 @@ public class NSHandler implements Namesp
} else {
_logger.warn(MESSAGES.getMessage("no.persistence.context.provider",
client.getSymbolicName() + '/' + client.getVersion(), unitName, properties));
}
+ boolean foundSync = false;
+ try {
+ Collection<ServiceReference<Synchronization>> refs =
client.getBundleContext().getServiceReferences(Synchronization.class, "(" +
PersistenceUnitConstants.OSGI_UNIT_NAME + "=" + unitName + ")");
+ if (refs.size() > 0) {
+ final Synchronization sync =
client.getBundleContext().getService(refs.iterator().next());
+
context.getComponentDefinitionRegistry().registerInterceptorWithComponent(
+ component,
+ new Interceptor() {
+ @Override
+ public Object preCall(ComponentMetadata
componentMetadata, Method method, Object... objects) throws Throwable {
+ sync.preCall();
+ return null;
+ }
+ @Override
+ public void
postCallWithReturn(ComponentMetadata componentMetadata, Method method, Object
o, Object o2) throws Throwable {
+ sync.postCall();
+ }
+ @Override
+ public void
postCallWithException(ComponentMetadata componentMetadata, Method method,
Throwable throwable, Object o) throws Throwable {
+ sync.postCall();
+ }
+ @Override
+ public int getRank() {
+ return 0;
+ }
+ }
+ );
+ foundSync = true;
+ }
+ } catch (InvalidSyntaxException e) {
+ // Ignore
+ }
+ if (!foundSync) {
+
_logger.error(MESSAGES.getMessage("no.synchronization.registered",
client.getSymbolicName() + '/' + client.getVersion(), unitName, properties));
+ }
} else {
_logger.debug("No bundle: this must be a dry, parse only
run.");
}
Modified:
aries/trunk/jpa20/jpa-blueprint-aries/src/main/resources/org/apache/aries/jpa/blueprint/aries/nls/ariesBlueprintJpaMessages.properties
URL:
http://svn.apache.org/viewvc/aries/trunk/jpa20/jpa-blueprint-aries/src/main/resources/org/apache/aries/jpa/blueprint/aries/nls/ariesBlueprintJpaMessages.properties?rev=1622665&r1=1622664&r2=1622665&view=diff
==============================================================================
---
aries/trunk/jpa20/jpa-blueprint-aries/src/main/resources/org/apache/aries/jpa/blueprint/aries/nls/ariesBlueprintJpaMessages.properties
(original)
+++
aries/trunk/jpa20/jpa-blueprint-aries/src/main/resources/org/apache/aries/jpa/blueprint/aries/nls/ariesBlueprintJpaMessages.properties
Fri Sep 5 09:41:57 2014
@@ -41,4 +41,5 @@ jpa.support.gone=Managed persistence con
# {0} The index
index.not.a.number=Unable to parse {0}. An index must be a number.
# {0} The map of properties
-map.not.well.formed=An unexpected condition was encountered. The map of JPA
properties did not contain the expected data.
\ No newline at end of file
+map.not.well.formed=An unexpected condition was encountered. The map of JPA
properties did not contain the expected data.
+no.synchronization.registered=No
org.apache.aries.jpa.container.sync.Synchronization service registered.
\ No newline at end of file
Modified: aries/trunk/jpa20/jpa-container-context/pom.xml
URL:
http://svn.apache.org/viewvc/aries/trunk/jpa20/jpa-container-context/pom.xml?rev=1622665&r1=1622664&r2=1622665&view=diff
==============================================================================
--- aries/trunk/jpa20/jpa-container-context/pom.xml (original)
+++ aries/trunk/jpa20/jpa-container-context/pom.xml Fri Sep 5 09:41:57 2014
@@ -90,9 +90,9 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.apache.aries.jpa</groupId>
+ <groupId>org.apache.aries.jpa20</groupId>
<artifactId>org.apache.aries.jpa.api</artifactId>
- <version>1.0.0</version>
+ <version>1.0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Modified:
aries/trunk/jpa20/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/impl/ManagedPersistenceContextFactory.java
URL:
http://svn.apache.org/viewvc/aries/trunk/jpa20/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/impl/ManagedPersistenceContextFactory.java?rev=1622665&r1=1622664&r2=1622665&view=diff
==============================================================================
---
aries/trunk/jpa20/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/impl/ManagedPersistenceContextFactory.java
(original)
+++
aries/trunk/jpa20/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/impl/ManagedPersistenceContextFactory.java
Fri Sep 5 09:41:57 2014
@@ -39,6 +39,7 @@ import org.apache.aries.jpa.container.co
import org.apache.aries.jpa.container.context.transaction.impl.DestroyCallback;
import
org.apache.aries.jpa.container.context.transaction.impl.JTAEntityManager;
import
org.apache.aries.jpa.container.context.transaction.impl.JTAPersistenceContextRegistry;
+import org.apache.aries.jpa.container.sync.Synchronization;
import org.osgi.framework.ServiceReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -50,7 +51,7 @@ import org.slf4j.LoggerFactory;
*
* Also this class receives a callback on cleanup
*/
-public class ManagedPersistenceContextFactory implements EntityManagerFactory,
DestroyCallback {
+public class ManagedPersistenceContextFactory implements Synchronization,
EntityManagerFactory, DestroyCallback {
/** Logger */
private static final Logger _logger =
LoggerFactory.getLogger("org.apache.aries.jpa.container.context");
@@ -60,6 +61,7 @@ public class ManagedPersistenceContextFa
private final PersistenceContextType type;
private final AtomicLong activeCount = new AtomicLong(0);
private final String unitName;
+ private final JTAEntityManager em;
private final AtomicReference<QuiesceTidyUp> tidyUp = new
AtomicReference<QuiesceTidyUp>();
@@ -72,6 +74,16 @@ public class ManagedPersistenceContextFa
registry = contextRegistry;
//Remove our internal property so that it doesn't get passed on the
createEntityManager call
type = (PersistenceContextType)
properties.remove(PersistenceContextProvider.PERSISTENCE_CONTEXT_TYPE);
+
+ //Getting the BundleContext is a privileged operation that the
+ //client might not be able to do.
+ EntityManagerFactory factory = AccessController.doPrivileged(
+ new PrivilegedAction<EntityManagerFactory>() {
+ public EntityManagerFactory run() {
+ return (EntityManagerFactory)
emf.getBundle().getBundleContext().getService(emf);
+ }
+ });
+ em = new JTAEntityManager(factory, properties, registry, activeCount,
this);
}
public EntityManager createEntityManager() {
@@ -79,17 +91,9 @@ public class ManagedPersistenceContextFa
_logger.debug("Creating a container managed entity manager for the
perstence unit {} with the following properties {}",
new Object[] {emf, properties});
}
- //Getting the BundleContext is a privileged operation that the
- //client might not be able to do.
- EntityManagerFactory factory = AccessController.doPrivileged(
- new PrivilegedAction<EntityManagerFactory>() {
- public EntityManagerFactory run() {
- return (EntityManagerFactory)
emf.getBundle().getBundleContext().getService(emf);
- }
- });
-
+
if(type == PersistenceContextType.TRANSACTION || type == null)
- return new JTAEntityManager(factory, properties, registry, activeCount,
this);
+ return em;
else {
_logger.error(NLS.MESSAGES.getMessage("extended.em.not.supported"));
return null;
@@ -97,6 +101,16 @@ public class ManagedPersistenceContextFa
}
+ @Override
+ public void preCall() {
+ em.preCall();
+ }
+
+ @Override
+ public void postCall() {
+ em.postCall();
+ }
+
public void close() {
throw new UnsupportedOperationException();
}
Modified:
aries/trunk/jpa20/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/impl/PersistenceContextManager.java
URL:
http://svn.apache.org/viewvc/aries/trunk/jpa20/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/impl/PersistenceContextManager.java?rev=1622665&r1=1622664&r2=1622665&view=diff
==============================================================================
---
aries/trunk/jpa20/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/impl/PersistenceContextManager.java
(original)
+++
aries/trunk/jpa20/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/impl/PersistenceContextManager.java
Fri Sep 5 09:41:57 2014
@@ -36,6 +36,7 @@ import org.apache.aries.jpa.container.Pe
import org.apache.aries.jpa.container.context.PersistenceContextProvider;
import org.apache.aries.jpa.container.context.transaction.impl.DestroyCallback;
import
org.apache.aries.jpa.container.context.transaction.impl.JTAPersistenceContextRegistry;
+import org.apache.aries.jpa.container.sync.Synchronization;
import org.apache.aries.util.AriesFrameworkUtil;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -284,7 +285,8 @@ public class PersistenceContextManager e
BundleContext persistenceBundleContext =
unit.getBundle().getBundleContext();
reg = persistenceBundleContext.registerService(
- EntityManagerFactory.class.getName(), entityManagerServiceFactory,
props);
+ new String[] {EntityManagerFactory.class.getName(),
+ Synchronization.class.getName()},
entityManagerServiceFactory, props);
} finally {
//As we have to register from outside a synchronized then someone may be
trying to
//unregister us. They will try to wait for us to finish, but in order to
prevent
Modified:
aries/trunk/jpa20/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/transaction/impl/JTAEntityManager.java
URL:
http://svn.apache.org/viewvc/aries/trunk/jpa20/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/transaction/impl/JTAEntityManager.java?rev=1622665&r1=1622664&r2=1622665&view=diff
==============================================================================
---
aries/trunk/jpa20/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/transaction/impl/JTAEntityManager.java
(original)
+++
aries/trunk/jpa20/jpa-container-context/src/main/java/org/apache/aries/jpa/container/context/transaction/impl/JTAEntityManager.java
Fri Sep 5 09:41:57 2014
@@ -19,6 +19,8 @@
package org.apache.aries.jpa.container.context.transaction.impl;
import java.util.Map;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import javax.persistence.EntityManager;
@@ -34,13 +36,14 @@ import javax.persistence.criteria.Criter
import javax.persistence.metamodel.Metamodel;
import org.apache.aries.jpa.container.context.impl.NLS;
+import org.apache.aries.jpa.container.sync.Synchronization;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* A <code>PersistenceContextType.TRANSACTION</code> {@link EntityManager}
instance
*/
-public class JTAEntityManager implements EntityManager {
+public class JTAEntityManager implements EntityManager, Synchronization {
/** Logger */
private static final Logger _logger =
LoggerFactory.getLogger("org.apache.aries.jpa.container.context");
@@ -54,14 +57,20 @@ public class JTAEntityManager implements
private final AtomicLong instanceCount;
/** A callback for when we're quiescing */
private final DestroyCallback callback;
-
-
- /**
- * The entity manager to use when there is no transaction. Note that there
is one of these
- * per injection site.
- */
- private EntityManager detachedManager = null;
-
+
+
+ private final ThreadLocal<AtomicInteger> activeCalls = new
ThreadLocal<AtomicInteger>() {
+ @Override
+ protected AtomicInteger initialValue() {
+ return new AtomicInteger(0);
+ }
+ };
+
+ private final ThreadLocal<EntityManager> activeManager = new
ThreadLocal<EntityManager>();
+
+ private final ConcurrentLinkedQueue<EntityManager> pool = new
ConcurrentLinkedQueue<EntityManager>();
+
+
public JTAEntityManager(EntityManagerFactory factory,
Map<String, Object> properties, JTAPersistenceContextRegistry registry,
AtomicLong activeCount,
DestroyCallback onDestroy) {
@@ -72,7 +81,24 @@ public class JTAEntityManager implements
callback = onDestroy;
}
- /**
+ @Override
+ public void preCall() {
+ activeCalls.get().incrementAndGet();
+ }
+
+ @Override
+ public void postCall() {
+ if (activeCalls.get().decrementAndGet() == 0) {
+ EntityManager manager = activeManager.get();
+ if (manager != null) {
+ activeManager.set(null);
+ manager.clear();
+ pool.add(manager);
+ }
+ }
+ }
+
+ /**
* Get the target persistence context
* @param forceTransaction Whether the returned entity manager needs to be
bound to a transaction
* @throws TransactionRequiredException if forceTransaction is true and no
transaction is available
@@ -81,28 +107,31 @@ public class JTAEntityManager implements
private EntityManager getPersistenceContext(boolean forceTransaction)
{
if (forceTransaction) {
+ EntityManager manager = activeManager.get();
+ if (manager != null) {
+ manager.clear();
+ }
return reg.getCurrentPersistenceContext(emf, props, instanceCount,
callback);
} else {
if (reg.isTransactionActive()) {
+ EntityManager manager = activeManager.get();
+ if (manager != null) {
+ manager.clear();
+ }
return reg.getCurrentPersistenceContext(emf, props, instanceCount,
callback);
} else {
if(!!!reg.jtaIntegrationAvailable() && _logger.isDebugEnabled())
_logger.debug("No integration with JTA transactions is available. No
transaction context is active.");
-
- if (detachedManager == null) {
- EntityManager temp = emf.createEntityManager(props);
-
- synchronized (this) {
- if (detachedManager == null) {
- detachedManager = new SynchronizedEntityManagerWrapper(temp);
- temp = null;
- }
+
+ EntityManager manager = activeManager.get();
+ if (manager == null) {
+ manager = pool.poll();
+ if (manager == null) {
+ manager = emf.createEntityManager(props);
}
-
- if (temp != null)
- temp.close();
+ activeManager.set(manager);
}
- return detachedManager;
+ return manager;
}
}
}
@@ -111,15 +140,10 @@ public class JTAEntityManager implements
* Called reflectively by blueprint
*/
public void internalClose() {
- EntityManager temp = null;
-
- synchronized (this) {
- temp = detachedManager;
- detachedManager = null;
- }
-
- if (temp != null)
+ EntityManager temp;
+ while ((temp = pool.poll()) != null) {
temp.close();
+ }
}
public void clear()
@@ -134,80 +158,37 @@ public class JTAEntityManager implements
public boolean contains(Object arg0)
{
- EntityManager em = getPersistenceContext(false);
- try {
- return em.contains(arg0);
- } finally {
- if(em == detachedManager)
- em.clear();
- }
+ return getPersistenceContext(false).contains(arg0);
}
public Query createNamedQuery(String arg0)
{
- EntityManager em = getPersistenceContext(false);
- try {
- return em.createNamedQuery(arg0);
- } finally {
- if(em == detachedManager)
- em.clear();
- }
+ return getPersistenceContext(false).createNamedQuery(arg0);
}
public Query createNativeQuery(String arg0)
{
- EntityManager em = getPersistenceContext(false);
- try {
- return em.createNativeQuery(arg0);
- } finally {
- if(em == detachedManager)
- em.clear();
- }
+ return getPersistenceContext(false).createNativeQuery(arg0);
}
- @SuppressWarnings("unchecked")
public Query createNativeQuery(String arg0, Class arg1)
{
- EntityManager em = getPersistenceContext(false);
- try {
- return em.createNativeQuery(arg0, arg1);
- } finally {
- if(em == detachedManager)
- em.clear();
- }
+ return getPersistenceContext(false).createNativeQuery(arg0, arg1);
}
public Query createNativeQuery(String arg0, String arg1)
{
- EntityManager em = getPersistenceContext(false);
- try {
- return em.createNativeQuery(arg0, arg1);
- } finally {
- if(em == detachedManager)
- em.clear();
- }
+ return getPersistenceContext(false).createNativeQuery(arg0, arg1);
}
public Query createQuery(String arg0)
{
- EntityManager em = getPersistenceContext(false);
- try {
- return em.createQuery(arg0);
- } finally {
- if(em == detachedManager)
- em.clear();
- }
+ return getPersistenceContext(false).createQuery(arg0);
}
public <T> T find(Class<T> arg0, Object arg1)
{
- EntityManager em = getPersistenceContext(false);
- try {
- return em.find(arg0, arg1);
- } finally {
- if(em == detachedManager)
- em.clear();
- }
+ return getPersistenceContext(false).find(arg0, arg1);
}
/**
@@ -230,13 +211,7 @@ public class JTAEntityManager implements
public <T> T getReference(Class<T> arg0, Object arg1)
{
- EntityManager em = getPersistenceContext(false);
- try {
- return em.getReference(arg0, arg1);
- } finally {
- if(em == detachedManager)
- em.clear();
- }
+ return getPersistenceContext(false).getReference(arg0, arg1);
}
public EntityTransaction getTransaction()
@@ -296,66 +271,32 @@ public class JTAEntityManager implements
public void setFlushMode(FlushModeType arg0)
{
- EntityManager em = getPersistenceContext(false);
- try {
- em.setFlushMode(arg0);
- } finally {
- if(em == detachedManager)
- em.clear();
- }
+ getPersistenceContext(false).setFlushMode(arg0);
}
public <T> TypedQuery<T> createNamedQuery(String arg0, Class<T> arg1)
{
- EntityManager em = getPersistenceContext(false);
- try {
- return em.createNamedQuery(arg0, arg1);
- } finally {
- if(em == detachedManager)
- em.clear();
- }
+ return getPersistenceContext(false).createNamedQuery(arg0, arg1);
}
public <T> TypedQuery<T> createQuery(CriteriaQuery<T> arg0)
{
- EntityManager em = getPersistenceContext(false);
- try {
- return em.createQuery(arg0);
- } finally {
- if(em == detachedManager)
- em.clear();
- }
+ return getPersistenceContext(false).createQuery(arg0);
}
public <T> TypedQuery<T> createQuery(String arg0, Class<T> arg1)
{
- EntityManager em = getPersistenceContext(false);
- try {
- return em.createQuery(arg0, arg1);
- } finally {
- if(em == detachedManager)
- em.clear();
- }
+ return getPersistenceContext(false).createQuery(arg0, arg1);
}
public void detach(Object arg0)
{
- EntityManager em = getPersistenceContext(false);
- //The detatched manager auto-detaches everything, so only
- //detach from a "real" entity manager
- if(em != detachedManager)
- em.detach(arg0);
+ getPersistenceContext(false).detach(arg0);
}
public <T> T find(Class<T> arg0, Object arg1, Map<String, Object> arg2)
{
- EntityManager em = getPersistenceContext(false);
- try {
- return em.find(arg0, arg1, arg2);
- } finally {
- if(em == detachedManager)
- em.clear();
- }
+ return getPersistenceContext(false).find(arg0, arg1, arg2);
}
/**
@@ -363,13 +304,7 @@ public class JTAEntityManager implements
*/
public <T> T find(Class<T> arg0, Object arg1, LockModeType arg2)
{
- EntityManager em = getPersistenceContext(arg2 != LockModeType.NONE);
- try {
- return em.find(arg0, arg1, arg2);
- } finally {
- if(em == detachedManager)
- em.clear();
- }
+ return getPersistenceContext(arg2 != LockModeType.NONE).find(arg0, arg1,
arg2);
}
/**
@@ -377,13 +312,7 @@ public class JTAEntityManager implements
*/
public <T> T find(Class<T> arg0, Object arg1, LockModeType arg2, Map<String,
Object> arg3)
{
- EntityManager em = getPersistenceContext(arg2 != LockModeType.NONE);
- try {
- return em.find(arg0, arg1, arg2, arg3);
- } finally {
- if(em == detachedManager)
- em.clear();
- }
+ return getPersistenceContext(arg2 != LockModeType.NONE).find(arg0, arg1,
arg2, arg3);
}
public CriteriaBuilder getCriteriaBuilder()
@@ -448,23 +377,11 @@ public class JTAEntityManager implements
public void setProperty(String arg0, Object arg1)
{
- EntityManager em = getPersistenceContext(false);
- try {
- em.setProperty(arg0, arg1);
- } finally {
- if(em == detachedManager)
- em.clear();
- }
+ getPersistenceContext(false).setProperty(arg0, arg1);
}
public <T> T unwrap(Class<T> arg0)
{
- EntityManager em = getPersistenceContext(false);
- try {
- return em.unwrap(arg0);
- } finally {
- if(em == detachedManager)
- em.clear();
- }
+ return getPersistenceContext(false).unwrap(arg0);
}
}
Modified:
aries/trunk/jpa20/jpa-container-itest/src/test/java/org/apache/aries/jpa/context/itest/JPAContextTest.java
URL:
http://svn.apache.org/viewvc/aries/trunk/jpa20/jpa-container-itest/src/test/java/org/apache/aries/jpa/context/itest/JPAContextTest.java?rev=1622665&r1=1622664&r2=1622665&view=diff
==============================================================================
---
aries/trunk/jpa20/jpa-container-itest/src/test/java/org/apache/aries/jpa/context/itest/JPAContextTest.java
(original)
+++
aries/trunk/jpa20/jpa-container-itest/src/test/java/org/apache/aries/jpa/context/itest/JPAContextTest.java
Fri Sep 5 09:41:57 2014
@@ -333,9 +333,9 @@ public abstract class JPAContextTest ext
assertEquals("black", list.get(0).getColour());
assertEquals("C3CCC", list.get(0).getNumberPlate());
- assertEquals(5, list.get(1).getNumberOfSeats());
- assertEquals(1200, list.get(1).getEngineSize());
- assertEquals("blue", list.get(1).getColour());
+ assertEquals(2, list.get(1).getNumberOfSeats());
+ assertEquals(2000, list.get(1).getEngineSize());
+ assertEquals("red", list.get(1).getColour());
assertEquals("A1AAA", list.get(1).getNumberPlate());
}