tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject tomee git commit: jpa 2.1 infra (we still need openjpa for full impl)
Date Tue, 07 Apr 2015 21:29:41 GMT
Repository: tomee
Updated Branches:
  refs/heads/master fd572f8dd -> f3f3c7b9f


jpa 2.1 infra (we still need openjpa for full impl)


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

Branch: refs/heads/master
Commit: f3f3c7b9fd38ee309e1e3d00b5a48ea2e1702de2
Parents: fd572f8
Author: Romain Manni-Bucau <rmannibucau@apache.org>
Authored: Tue Apr 7 23:29:26 2015 +0200
Committer: Romain Manni-Bucau <rmannibucau@apache.org>
Committed: Tue Apr 7 23:29:26 2015 +0200

----------------------------------------------------------------------
 .../classic/ReloadableEntityManagerFactory.java |  51 ++++++++
 .../openejb/persistence/JtaEntityManager.java   | 121 ++++++++++++++++++-
 .../persistence/QueryLogEntityManager.java      |  60 +++++++++
 .../java/org/apache/openejb/jee/JaxbJavaee.java |   4 +-
 .../org/apache/openejb/jee/Persistence.java     |   2 +-
 .../jee/jpa/unit/JaxbPersistenceFactory.java    |  27 +++--
 6 files changed, 249 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/f3f3c7b9/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ReloadableEntityManagerFactory.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ReloadableEntityManagerFactory.java
b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ReloadableEntityManagerFactory.java
index cae1834..8b4bb59 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ReloadableEntityManagerFactory.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ReloadableEntityManagerFactory.java
@@ -44,10 +44,13 @@ import javax.management.ObjectName;
 import javax.management.openmbean.TabularData;
 import javax.naming.NamingException;
 import javax.persistence.Cache;
+import javax.persistence.EntityGraph;
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.PersistenceUnitUtil;
+import javax.persistence.Query;
 import javax.persistence.SharedCacheMode;
+import javax.persistence.SynchronizationType;
 import javax.persistence.ValidationMode;
 import javax.persistence.criteria.CriteriaBuilder;
 import javax.persistence.metamodel.Metamodel;
@@ -169,6 +172,54 @@ public class ReloadableEntityManagerFactory implements EntityManagerFactory,
Ser
     }
 
     @Override
+    public EntityManager createEntityManager(final SynchronizationType synchronizationType)
{
+        EntityManager em;
+        try {
+            em = delegate.createEntityManager(synchronizationType);
+        } catch (final LinkageError le) {
+            em = delegate.createEntityManager(synchronizationType);
+        }
+
+        if (logCriteriaJpql) {
+            return new QueryLogEntityManager(em, logCriteriaJpqlLevel);
+        }
+        return em;
+    }
+
+    @Override
+    public EntityManager createEntityManager(final SynchronizationType synchronizationType,
final Map map) {
+        EntityManager em;
+        try {
+            em = delegate.createEntityManager(synchronizationType, map);
+        } catch (final LinkageError le) {
+            em = delegate.createEntityManager(synchronizationType, map);
+        }
+
+        if (logCriteriaJpql) {
+            return new QueryLogEntityManager(em, logCriteriaJpqlLevel);
+        }
+        return em;
+    }
+
+    @Override
+    public <T> T unwrap(final Class<T> cls) {
+        if (cls.isAssignableFrom(getClass())) {
+            return cls.cast(this);
+        }
+        return delegate.unwrap(cls);
+    }
+
+    @Override
+    public void addNamedQuery(final String name, final Query query) {
+        delegate.addNamedQuery(name, query);
+    }
+
+    @Override
+    public <T> void addNamedEntityGraph(final String graphName, final EntityGraph<T>
entityGraph) {
+        delegate.addNamedEntityGraph(graphName, entityGraph);
+    }
+
+    @Override
     public CriteriaBuilder getCriteriaBuilder() {
         return delegate.getCriteriaBuilder();
     }

http://git-wip-us.apache.org/repos/asf/tomee/blob/f3f3c7b9/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 1dfb8b8..e5bfced 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
@@ -24,21 +24,26 @@ import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
 import org.apache.openejb.util.reflection.Reflections;
 
+import javax.persistence.EntityGraph;
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.EntityTransaction;
 import javax.persistence.FlushModeType;
 import javax.persistence.LockModeType;
 import javax.persistence.Query;
+import javax.persistence.StoredProcedureQuery;
 import javax.persistence.TransactionRequiredException;
 import javax.persistence.TypedQuery;
 import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaDelete;
 import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.CriteriaUpdate;
 import javax.persistence.metamodel.Metamodel;
 import java.io.ObjectStreamException;
 import java.io.Serializable;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.util.List;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
@@ -647,7 +652,9 @@ public class JtaEntityManager implements EntityManager, Serializable {
     }
 
     private static enum Op {
-        clear, close, contains, createNamedQuery, createNativeQuery, createQuery, find, flush,
getFlushMode, getReference, getTransaction, lock, merge, refresh, remove, setFlushMode, persist,
detach, getLockMode, unwrap, setProperty, getCriteriaBuilder, getProperties, getMetamodel,
joinTransaction, getDelegate;
+        clear, close, contains, createNamedQuery, createNativeQuery, createQuery, find, flush,
getFlushMode, getReference, getTransaction, lock, merge, refresh, remove, setFlushMode, persist,
detach, getLockMode, unwrap, setProperty, getCriteriaBuilder, getProperties, getMetamodel,
joinTransaction, getDelegate,
+        // JPA 2.1
+        createNamedStoredProcedureQuery, createStoredProcedureQuery, createEntityGraph, getEntityGraph,
getEntityGraphs, isJoinedToTransaction;
 
         public Timer start(final JtaEntityManager em) {
             return new Timer(this, em);
@@ -658,4 +665,116 @@ public class JtaEntityManager implements EntityManager, Serializable
{
     protected Object writeReplace() throws ObjectStreamException {
         return new IntraVmArtifact(this, true);
     }
+
+    // TODO: JPA 2.1 methods doesn't have yet proxying
+
+    @Override
+    public StoredProcedureQuery createNamedStoredProcedureQuery(final String name) {
+        final Timer timer = Op.createNamedStoredProcedureQuery.start(this);
+        try {
+            return getEntityManager().createNamedStoredProcedureQuery(name);
+        } finally {
+            timer.stop();
+        }
+    }
+
+    @Override
+    public StoredProcedureQuery createStoredProcedureQuery(final String procedureName) {
+        final Timer timer = Op.createNamedStoredProcedureQuery.start(this);
+        try {
+            return getEntityManager().createStoredProcedureQuery(procedureName);
+        } finally {
+            timer.stop();
+        }
+    }
+
+    @Override
+    public StoredProcedureQuery createStoredProcedureQuery(final String procedureName, final
Class... resultClasses) {
+        final Timer timer = Op.createStoredProcedureQuery.start(this);
+        try {
+            return getEntityManager().createStoredProcedureQuery(procedureName, resultClasses);
+        } finally {
+            timer.stop();
+        }
+    }
+
+    @Override
+    public StoredProcedureQuery createStoredProcedureQuery(final String procedureName, final
String... resultSetMappings) {
+        final Timer timer = Op.createStoredProcedureQuery.start(this);
+        try {
+            return getEntityManager().createStoredProcedureQuery(procedureName, resultSetMappings);
+        } finally {
+            timer.stop();
+        }
+    }
+
+    @Override
+    public Query createQuery(final CriteriaUpdate updateQuery) {
+        final Timer timer = Op.createQuery.start(this);
+        try {
+            return getEntityManager().createQuery(updateQuery);
+        } finally {
+            timer.stop();
+        }
+    }
+
+    @Override
+    public Query createQuery(final CriteriaDelete deleteQuery) {
+        final Timer timer = Op.createQuery.start(this);
+        try {
+            return getEntityManager().createQuery(deleteQuery);
+        } finally {
+            timer.stop();
+        }
+    }
+
+    @Override
+    public <T> EntityGraph<T> createEntityGraph(final Class<T> rootType)
{
+        final Timer timer = Op.createEntityGraph.start(this);
+        try {
+            return getEntityManager().createEntityGraph(rootType);
+        } finally {
+            timer.stop();
+        }
+    }
+
+    @Override
+    public EntityGraph<?> createEntityGraph(final String graphName) {
+        final Timer timer = Op.createEntityGraph.start(this);
+        try {
+            return getEntityManager().createEntityGraph(graphName);
+        } finally {
+            timer.stop();
+        }
+    }
+
+    @Override
+    public EntityGraph<?> getEntityGraph(final String graphName) {
+        final Timer timer = Op.getEntityGraph.start(this);
+        try {
+            return getEntityManager().getEntityGraph(graphName);
+        } finally {
+            timer.stop();
+        }
+    }
+
+    @Override
+    public <T> List<EntityGraph<? super T>> getEntityGraphs(final Class<T>
entityClass) {
+        final Timer timer = Op.getEntityGraphs.start(this);
+        try {
+            return getEntityManager().getEntityGraphs(entityClass);
+        } finally {
+            timer.stop();
+        }
+    }
+
+    @Override
+    public boolean isJoinedToTransaction() {
+        final Timer timer = Op.isJoinedToTransaction.start(this);
+        try {
+            return getEntityManager().isJoinedToTransaction();
+        } finally {
+            timer.stop();
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/tomee/blob/f3f3c7b9/container/openejb-core/src/main/java/org/apache/openejb/persistence/QueryLogEntityManager.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/persistence/QueryLogEntityManager.java
b/container/openejb-core/src/main/java/org/apache/openejb/persistence/QueryLogEntityManager.java
index 75548b0..798121a 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/persistence/QueryLogEntityManager.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/persistence/QueryLogEntityManager.java
@@ -17,16 +17,21 @@
 
 package org.apache.openejb.persistence;
 
+import javax.persistence.EntityGraph;
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.EntityTransaction;
 import javax.persistence.FlushModeType;
 import javax.persistence.LockModeType;
 import javax.persistence.Query;
+import javax.persistence.StoredProcedureQuery;
 import javax.persistence.TypedQuery;
 import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaDelete;
 import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.CriteriaUpdate;
 import javax.persistence.metamodel.Metamodel;
+import java.util.List;
 import java.util.Map;
 
 public class QueryLogEntityManager implements EntityManager {
@@ -164,6 +169,16 @@ public class QueryLogEntityManager implements EntityManager {
     }
 
     @Override
+    public Query createQuery(final CriteriaUpdate updateQuery) {
+        return delegate.createQuery(updateQuery);
+    }
+
+    @Override
+    public Query createQuery(final CriteriaDelete deleteQuery) {
+        return delegate.createQuery(deleteQuery);
+    }
+
+    @Override
     public <T> TypedQuery<T> createQuery(final String qlString, final Class<T>
resultClass) {
         return delegate.createQuery(qlString, resultClass);
     }
@@ -194,11 +209,36 @@ public class QueryLogEntityManager implements EntityManager {
     }
 
     @Override
+    public StoredProcedureQuery createNamedStoredProcedureQuery(final String name) {
+        return delegate.createNamedStoredProcedureQuery(name);
+    }
+
+    @Override
+    public StoredProcedureQuery createStoredProcedureQuery(final String procedureName) {
+        return delegate.createStoredProcedureQuery(procedureName);
+    }
+
+    @Override
+    public StoredProcedureQuery createStoredProcedureQuery(final String procedureName, final
Class... resultClasses) {
+        return delegate.createStoredProcedureQuery(procedureName, resultClasses);
+    }
+
+    @Override
+    public StoredProcedureQuery createStoredProcedureQuery(final String procedureName, final
String... resultSetMappings) {
+        return delegate.createStoredProcedureQuery(procedureName, resultSetMappings);
+    }
+
+    @Override
     public void joinTransaction() {
         delegate.joinTransaction();
     }
 
     @Override
+    public boolean isJoinedToTransaction() {
+        return delegate.isJoinedToTransaction();
+    }
+
+    @Override
     public <T> T unwrap(final Class<T> cls) {
         return delegate.unwrap(cls);
     }
@@ -237,4 +277,24 @@ public class QueryLogEntityManager implements EntityManager {
     public Metamodel getMetamodel() {
         return delegate.getMetamodel();
     }
+
+    @Override
+    public <T> EntityGraph<T> createEntityGraph(final Class<T> rootType)
{
+        return delegate.createEntityGraph(rootType);
+    }
+
+    @Override
+    public EntityGraph<?> createEntityGraph(final String graphName) {
+        return delegate.createEntityGraph(graphName);
+    }
+
+    @Override
+    public EntityGraph<?> getEntityGraph(final String graphName) {
+        return delegate.getEntityGraph(graphName);
+    }
+
+    @Override
+    public <T> List<EntityGraph<? super T>> getEntityGraphs(final Class<T>
entityClass) {
+        return delegate.getEntityGraphs(entityClass);
+    }
 }

http://git-wip-us.apache.org/repos/asf/tomee/blob/f3f3c7b9/container/openejb-jee/src/main/java/org/apache/openejb/jee/JaxbJavaee.java
----------------------------------------------------------------------
diff --git a/container/openejb-jee/src/main/java/org/apache/openejb/jee/JaxbJavaee.java b/container/openejb-jee/src/main/java/org/apache/openejb/jee/JaxbJavaee.java
index ff1e2db..a3e2412 100644
--- a/container/openejb-jee/src/main/java/org/apache/openejb/jee/JaxbJavaee.java
+++ b/container/openejb-jee/src/main/java/org/apache/openejb/jee/JaxbJavaee.java
@@ -318,13 +318,13 @@ public class JaxbJavaee {
     }
 
     public static class NoSourceFilter extends XMLFilterImpl {
-        private static final InputSource EMPTY_INPUT_SOURCE = new InputSource(new ByteArrayInputStream(new
byte[0]));
+        protected static final InputSource EMPTY_INPUT_SOURCE = new InputSource(new ByteArrayInputStream(new
byte[0]));
 
         public NoSourceFilter(final XMLReader xmlReader) {
             super(xmlReader);
         }
 
-        private static String eeUri(final String uri) {
+        protected String eeUri(final String uri) {
             // if ee 7 then switch back on ee 6 to not break compatibility - to rework surely
when we'll be fully ee 7
             return "http://xmlns.jcp.org/xml/ns/javaee".equals(uri) ? "http://java.sun.com/xml/ns/javaee":
uri;
         }

http://git-wip-us.apache.org/repos/asf/tomee/blob/f3f3c7b9/container/openejb-jee/src/main/java/org/apache/openejb/jee/Persistence.java
----------------------------------------------------------------------
diff --git a/container/openejb-jee/src/main/java/org/apache/openejb/jee/Persistence.java b/container/openejb-jee/src/main/java/org/apache/openejb/jee/Persistence.java
index 77dbace..06efd4a 100644
--- a/container/openejb-jee/src/main/java/org/apache/openejb/jee/Persistence.java
+++ b/container/openejb-jee/src/main/java/org/apache/openejb/jee/Persistence.java
@@ -135,7 +135,7 @@ public class Persistence {
      */
     public java.lang.String getVersion() {
         if (version == null) {
-            return "2.0";
+            return "2.1";
         } else {
             return version;
         }

http://git-wip-us.apache.org/repos/asf/tomee/blob/f3f3c7b9/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/unit/JaxbPersistenceFactory.java
----------------------------------------------------------------------
diff --git a/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/unit/JaxbPersistenceFactory.java
b/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/unit/JaxbPersistenceFactory.java
index 43e7e7c..aff0f32 100644
--- a/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/unit/JaxbPersistenceFactory.java
+++ b/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/unit/JaxbPersistenceFactory.java
@@ -17,22 +17,21 @@
  */
 package org.apache.openejb.jee.jpa.unit;
 
+import org.apache.openejb.jee.JAXBContextFactory;
+import org.apache.openejb.jee.JaxbJavaee;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.XMLFilterImpl;
-import org.apache.openejb.jee.JAXBContextFactory;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.Unmarshaller;
 import javax.xml.bind.UnmarshallerHandler;
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
 import javax.xml.transform.sax.SAXSource;
-import java.io.InputStream;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.net.URL;
 
 /**
  * @version $Revision$ $Date$
@@ -41,7 +40,8 @@ public class JaxbPersistenceFactory {
     public static final String PERSISTENCE_SCHEMA = "http://java.sun.com/xml/ns/persistence";
 
     public static <T> T getPersistence(final Class<T> clazz, final InputStream
persistenceDescriptor) throws Exception {
-        final JAXBContext jc = JAXBContextFactory.newInstance(clazz);
+        final JAXBContext jc = clazz.getClassLoader() == JaxbPersistenceFactory.class.getClassLoader()
?
+                JaxbJavaee.getContext(clazz) : JAXBContextFactory.newInstance(clazz);
         final Unmarshaller u = jc.createUnmarshaller();
         final UnmarshallerHandler uh = u.getUnmarshallerHandler();
 
@@ -56,8 +56,7 @@ public class JaxbPersistenceFactory {
         // Create a filter to intercept events
         final PersistenceFilter xmlFilter = new PersistenceFilter(xmlReader);
 
-        // Be sure the filter has the JAXB content handler set (or it wont
-        // work)
+        // Be sure the filter has the JAXB content handler set (or it wont work)
         xmlFilter.setContentHandler(uh);
         final SAXSource source = new SAXSource(xmlFilter, new InputSource(persistenceDescriptor));
 
@@ -78,13 +77,17 @@ public class JaxbPersistenceFactory {
     }
 
     // Inject the proper namespace
-    public static class PersistenceFilter extends XMLFilterImpl {
-        private static final InputSource EMPTY_INPUT_SOURCE = new InputSource(new ByteArrayInputStream(new
byte[0]));
-
+    public static class PersistenceFilter extends JaxbJavaee.NoSourceFilter {
         public PersistenceFilter(final XMLReader xmlReader) {
             super(xmlReader);
         }
 
+        @Override
+        protected String eeUri(final String uri) {
+            return "http://xmlns.jcp.org/xml/ns/persistence".equals(uri) ? "http://java.sun.com/xml/ns/persistence":
uri;
+        }
+
+        @Override
         public InputSource resolveEntity(final String publicId, final String systemId) throws
SAXException, IOException {
             return EMPTY_INPUT_SOURCE;
         }


Mime
View raw message