tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject [1/2] tomee git commit: persistence synchronization parameter
Date Tue, 07 Apr 2015 22:12:35 GMT
Repository: tomee
Updated Branches:
  refs/heads/master f3f3c7b9f -> 3bf595f3c


persistence synchronization parameter


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/dc66eb50
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/dc66eb50
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/dc66eb50

Branch: refs/heads/master
Commit: dc66eb500fc72e6c245fa4888cff8b4572a018ad
Parents: f3f3c7b
Author: Romain Manni-Bucau <rmannibucau@apache.org>
Authored: Wed Apr 8 00:05:53 2015 +0200
Committer: Romain Manni-Bucau <rmannibucau@apache.org>
Committed: Wed Apr 8 00:05:53 2015 +0200

----------------------------------------------------------------------
 .../assembler/classic/JndiEncBuilder.java       |  3 ++-
 .../PersistenceContextReferenceInfo.java        |  1 +
 .../openejb/config/JndiEncInfoBuilder.java      |  1 +
 .../openejb/persistence/JtaEntityManager.java   | 14 ++++++++---
 .../persistence/JtaEntityManagerRegistry.java   | 17 ++++++++++---
 .../openejb/jee/PersistenceContextRef$JAXB.java | 17 +++++++++++++
 .../openejb/jee/PersistenceContextRef.java      | 10 ++++++++
 .../jee/PersistenceContextSynchronization.java  | 26 ++++++++++++++++++++
 .../tomee/catalina/TomcatJndiBuilder.java       |  2 +-
 9 files changed, 82 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/dc66eb50/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java
b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java
index ab1142c..ac37574 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java
@@ -429,7 +429,8 @@ public class JndiEncBuilder {
                 throw new OpenEJBException("PersistenceUnit '" + contextInfo.unitId + "'
not found for EXTENDED ref '" + contextInfo.referenceName + "'");
             }
 
-            final JtaEntityManager jtaEntityManager = new JtaEntityManager(contextInfo.persistenceUnitName,
jtaEntityManagerRegistry, factory, contextInfo.properties, contextInfo.extended);
+            final JtaEntityManager jtaEntityManager = new JtaEntityManager(
+                    contextInfo.persistenceUnitName, jtaEntityManagerRegistry, factory, contextInfo.properties,
contextInfo.extended, contextInfo.synchronizationType);
             final Reference reference = new PersistenceContextReference(jtaEntityManager);
             bindings.put(normalize(contextInfo.referenceName), reference);
         }

http://git-wip-us.apache.org/repos/asf/tomee/blob/dc66eb50/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/PersistenceContextReferenceInfo.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/PersistenceContextReferenceInfo.java
b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/PersistenceContextReferenceInfo.java
index 00b98dd..2a68748 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/PersistenceContextReferenceInfo.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/PersistenceContextReferenceInfo.java
@@ -26,6 +26,7 @@ public class PersistenceContextReferenceInfo extends InjectableInfo {
     public String persistenceUnitName;
     public String unitId;
     public boolean extended;
+    public String synchronizationType;
     public final Properties properties = new Properties();
 
 }

http://git-wip-us.apache.org/repos/asf/tomee/blob/dc66eb50/container/openejb-core/src/main/java/org/apache/openejb/config/JndiEncInfoBuilder.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/JndiEncInfoBuilder.java
b/container/openejb-core/src/main/java/org/apache/openejb/config/JndiEncInfoBuilder.java
index 2b57c46..223a2d3 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/config/JndiEncInfoBuilder.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/config/JndiEncInfoBuilder.java
@@ -269,6 +269,7 @@ public class JndiEncInfoBuilder {
             final PersistenceContextReferenceInfo info = new PersistenceContextReferenceInfo();
             info.referenceName = contextRef.getPersistenceContextRefName();
             info.persistenceUnitName = contextRef.getPersistenceUnitName();
+            info.synchronizationType = contextRef.getPersistenceContextSynchronization()
!= null ? contextRef.getPersistenceContextSynchronization().name() : null;
             info.unitId = contextRef.getMappedName();
             info.location = buildLocationInfo(contextRef);
             info.extended = contextRef.getPersistenceContextType() == PersistenceContextType.EXTENDED;

http://git-wip-us.apache.org/repos/asf/tomee/blob/dc66eb50/container/openejb-core/src/main/java/org/apache/openejb/persistence/JtaEntityManager.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/persistence/JtaEntityManager.java
b/container/openejb-core/src/main/java/org/apache/openejb/persistence/JtaEntityManager.java
index e5bfced..deac5a0 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/persistence/JtaEntityManager.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/persistence/JtaEntityManager.java
@@ -32,6 +32,7 @@ import javax.persistence.FlushModeType;
 import javax.persistence.LockModeType;
 import javax.persistence.Query;
 import javax.persistence.StoredProcedureQuery;
+import javax.persistence.SynchronizationType;
 import javax.persistence.TransactionRequiredException;
 import javax.persistence.TypedQuery;
 import javax.persistence.criteria.CriteriaBuilder;
@@ -44,6 +45,7 @@ import java.io.Serializable;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
@@ -76,15 +78,18 @@ public class JtaEntityManager implements EntityManager, Serializable {
     private final EntityManagerFactory entityManagerFactory;
     private final Map properties;
     private final boolean extended;
+    private final SynchronizationType synchronizationType;
     private final String unitName;
     private final Logger logger;
     private final boolean wrapNoTxQueries;
 
-    public JtaEntityManager(final JtaEntityManagerRegistry registry, final EntityManagerFactory
entityManagerFactory, final Map properties, final String unitName) {
-        this(unitName, registry, entityManagerFactory, properties, false);
+    public JtaEntityManager(final JtaEntityManagerRegistry registry, final EntityManagerFactory
entityManagerFactory,
+                            final Map properties, final String unitName, final String synchronizationType)
{
+        this(unitName, registry, entityManagerFactory, properties, false, synchronizationType);
     }
 
-    public JtaEntityManager(final String unitName, final JtaEntityManagerRegistry registry,
final EntityManagerFactory entityManagerFactory, final Map properties, final boolean extended)
{
+    public JtaEntityManager(final String unitName, final JtaEntityManagerRegistry registry,
final EntityManagerFactory entityManagerFactory,
+                            final Map properties, final boolean extended, final String synchronizationType)
{
         if (registry == null) {
             throw new NullPointerException("registry is null");
         }
@@ -96,6 +101,7 @@ public class JtaEntityManager implements EntityManager, Serializable {
         this.entityManagerFactory = entityManagerFactory;
         this.properties = properties;
         this.extended = extended;
+        this.synchronizationType = synchronizationType == null ? null : SynchronizationType.valueOf(synchronizationType.toUpperCase(Locale.ENGLISH));
         logger = unitName == null ? baseLogger : baseLogger.getChildLogger(unitName);
         final String wrapConfig = ReloadableEntityManagerFactory.class.isInstance(entityManagerFactory)
?
                 ReloadableEntityManagerFactory.class.cast(entityManagerFactory).getUnitProperties().getProperty("openejb.jpa.query.wrap-no-tx",
"true") : "true";
@@ -103,7 +109,7 @@ public class JtaEntityManager implements EntityManager, Serializable {
     }
 
     EntityManager getEntityManager() {
-        return registry.getEntityManager(entityManagerFactory, properties, extended, unitName);
+        return registry.getEntityManager(entityManagerFactory, properties, extended, unitName,
synchronizationType);
     }
 
     boolean isTransactionActive() {

http://git-wip-us.apache.org/repos/asf/tomee/blob/dc66eb50/container/openejb-core/src/main/java/org/apache/openejb/persistence/JtaEntityManagerRegistry.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/persistence/JtaEntityManagerRegistry.java
b/container/openejb-core/src/main/java/org/apache/openejb/persistence/JtaEntityManagerRegistry.java
index c87c00e..082303b 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/persistence/JtaEntityManagerRegistry.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/persistence/JtaEntityManagerRegistry.java
@@ -24,6 +24,7 @@ import org.apache.openejb.util.Logger;
 
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
+import javax.persistence.SynchronizationType;
 import javax.persistence.TransactionRequiredException;
 import javax.transaction.Status;
 import javax.transaction.Synchronization;
@@ -81,7 +82,9 @@ public class JtaEntityManagerRegistry {
      *                               instance already registered
      */
     @Geronimo
-    public EntityManager getEntityManager(final EntityManagerFactory entityManagerFactory,
final Map properties, final boolean extended, final String unitName) throws IllegalStateException
{
+    public EntityManager getEntityManager(final EntityManagerFactory entityManagerFactory,
+                                          final Map properties, final boolean extended, final
String unitName,
+                                          final SynchronizationType synchronizationType)
throws IllegalStateException {
         if (entityManagerFactory == null) {
             throw new NullPointerException("entityManagerFactory is null");
         }
@@ -106,7 +109,9 @@ public class JtaEntityManagerRegistry {
 
             // if transaction is active, we need to register the entity manager with the
transaction manager
             if (transactionActive) {
-                entityManager.joinTransaction();
+                if (synchronizationType != SynchronizationType.UNSYNCHRONIZED) {
+                    entityManager.joinTransaction();
+                }
                 transactionRegistry.putResource(txKey, entityManager);
             }
 
@@ -115,7 +120,13 @@ public class JtaEntityManagerRegistry {
 
             // create a new entity manager
             final EntityManager entityManager;
-            if (properties != null) {
+            if (synchronizationType != null) {
+                if (properties != null) {
+                    entityManager = entityManagerFactory.createEntityManager(synchronizationType,
properties);
+                } else {
+                    entityManager = entityManagerFactory.createEntityManager(synchronizationType);
+                }
+            } else if (properties != null) {
                 entityManager = entityManagerFactory.createEntityManager(properties);
             } else {
                 entityManager = entityManagerFactory.createEntityManager();

http://git-wip-us.apache.org/repos/asf/tomee/blob/dc66eb50/container/openejb-jee-accessors/src/main/java/org/apache/openejb/jee/PersistenceContextRef$JAXB.java
----------------------------------------------------------------------
diff --git a/container/openejb-jee-accessors/src/main/java/org/apache/openejb/jee/PersistenceContextRef$JAXB.java
b/container/openejb-jee-accessors/src/main/java/org/apache/openejb/jee/PersistenceContextRef$JAXB.java
index a636776..8850bf3 100644
--- a/container/openejb-jee-accessors/src/main/java/org/apache/openejb/jee/PersistenceContextRef$JAXB.java
+++ b/container/openejb-jee-accessors/src/main/java/org/apache/openejb/jee/PersistenceContextRef$JAXB.java
@@ -146,6 +146,12 @@ public class PersistenceContextRef$JAXB
                 if (persistenceContextType != null) {
                     persistenceContextRef.persistenceContextType = persistenceContextType;
                 }
+            } else if (("persistence-context-synchronization" == elementReader.getLocalName())
&& ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
+                // ELEMENT: persistenceContextType
+                final PersistenceContextSynchronization synchronization = parsePersistenceContextSynchronization(elementReader,
context, elementReader.getElementAsString());
+                if (synchronization != null) {
+                    persistenceContextRef.persistenceContextSynchronization = synchronization;
+                }
             } else if (("persistence-property" == elementReader.getLocalName()) &&
("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
                 // ELEMENT: persistenceProperty
                 final Property persistencePropertyItem = readProperty(elementReader, context);
@@ -372,4 +378,15 @@ public class PersistenceContextRef$JAXB
         context.afterMarshal(persistenceContextRef, LifecycleCallback.NONE);
     }
 
+    // should be in PersistenceContextSynchronization$JAXB but no need to generate the full
sxc bean since we only need it here for now
+    public static PersistenceContextSynchronization parsePersistenceContextSynchronization(final
XoXMLStreamReader reader, final RuntimeContext context, final String value)
+            throws Exception {
+        if ("Synchronized".equals(value)) {
+            return PersistenceContextSynchronization.SYNCHRONIZED;
+        } else if ("Unsynchronized".equals(value)) {
+            return PersistenceContextSynchronization.UNSYNCHRONIZED;
+        }
+        context.unexpectedEnumValue(reader, PersistenceContextType.class, value, "Synchronized",
"Unsynchronized");
+        return null;
+    }
 }

http://git-wip-us.apache.org/repos/asf/tomee/blob/dc66eb50/container/openejb-jee/src/main/java/org/apache/openejb/jee/PersistenceContextRef.java
----------------------------------------------------------------------
diff --git a/container/openejb-jee/src/main/java/org/apache/openejb/jee/PersistenceContextRef.java
b/container/openejb-jee/src/main/java/org/apache/openejb/jee/PersistenceContextRef.java
index 5912fe2..b664fa4 100644
--- a/container/openejb-jee/src/main/java/org/apache/openejb/jee/PersistenceContextRef.java
+++ b/container/openejb-jee/src/main/java/org/apache/openejb/jee/PersistenceContextRef.java
@@ -80,6 +80,8 @@ public class PersistenceContextRef implements JndiReference, PersistenceRef
{
     protected String persistenceUnitName;
     @XmlElement(name = "persistence-context-type")
     protected PersistenceContextType persistenceContextType;
+    @XmlElement(name = "persistence-context-synchronization")
+    protected PersistenceContextSynchronization persistenceContextSynchronization;
     @XmlElement(name = "persistence-property", required = true)
     protected List<Property> persistenceProperty;
     @XmlElement(name = "mapped-name")
@@ -212,6 +214,14 @@ public class PersistenceContextRef implements JndiReference, PersistenceRef
{
         this.persistenceContextType = value;
     }
 
+    public PersistenceContextSynchronization getPersistenceContextSynchronization() {
+        return persistenceContextSynchronization;
+    }
+
+    public void setPersistenceContextSynchronization(PersistenceContextSynchronization persistenceContextSynchronization)
{
+        this.persistenceContextSynchronization = persistenceContextSynchronization;
+    }
+
     public List<Property> getPersistenceProperty() {
         if (persistenceProperty == null) {
             persistenceProperty = new ArrayList<Property>();

http://git-wip-us.apache.org/repos/asf/tomee/blob/dc66eb50/container/openejb-jee/src/main/java/org/apache/openejb/jee/PersistenceContextSynchronization.java
----------------------------------------------------------------------
diff --git a/container/openejb-jee/src/main/java/org/apache/openejb/jee/PersistenceContextSynchronization.java
b/container/openejb-jee/src/main/java/org/apache/openejb/jee/PersistenceContextSynchronization.java
new file mode 100644
index 0000000..b90cf70
--- /dev/null
+++ b/container/openejb-jee/src/main/java/org/apache/openejb/jee/PersistenceContextSynchronization.java
@@ -0,0 +1,26 @@
+/**
+ *
+ * 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.openejb.jee;
+
+import javax.xml.bind.annotation.XmlEnumValue;
+
+public enum PersistenceContextSynchronization {
+    @XmlEnumValue("Synchronized")SYNCHRONIZED,
+    @XmlEnumValue("Unsynchronized")UNSYNCHRONIZED;
+}

http://git-wip-us.apache.org/repos/asf/tomee/blob/dc66eb50/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatJndiBuilder.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatJndiBuilder.java
b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatJndiBuilder.java
index 8baa4e4..cb8c774 100644
--- a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatJndiBuilder.java
+++ b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatJndiBuilder.java
@@ -557,7 +557,7 @@ public class TomcatJndiBuilder {
             }
 
             final JtaEntityManagerRegistry jtaEntityManagerRegistry = SystemInstance.get().getComponent(JtaEntityManagerRegistry.class);
-            setResource(resource, new JtaEntityManager(ref.persistenceUnitName, jtaEntityManagerRegistry,
factory, ref.properties, ref.extended));
+            setResource(resource, new JtaEntityManager(ref.persistenceUnitName, jtaEntityManagerRegistry,
factory, ref.properties, ref.extended, ref.synchronizationType));
         }
 
         if (addEntry) {


Mime
View raw message