From e0c03c5fc9bfb988d40b47e5477e30f83307fc2b Mon Sep 17 00:00:00 2001 From: Mark Struberg Date: Wed, 5 Oct 2016 17:20:39 +0000 Subject: [PATCH] OPENJPA-2670 improve support for createEnittyManager with SynchronizationType Currently we support the 'old' SynchronizationType.SYNCHRONIZED behaviour at least. UNSYNCHRONIZED still needs to be implemented. git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1763471 13f79535-47bb-0310-9956-ffa450edef68 --- .../persistence/EntityManagerFactoryImpl.java | 37 ++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryImpl.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryImpl.java index 1f1ba2f50..a0d1e4fea 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryImpl.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerFactoryImpl.java @@ -152,6 +152,17 @@ public class EntityManagerFactoryImpl return createEntityManager((Map) null); } + @Override + public OpenJPAEntityManagerSPI createEntityManager(SynchronizationType synchronizationType) { + return createEntityManager(synchronizationType, null); + } + + @Override + public OpenJPAEntityManagerSPI createEntityManager(Map props) { + return createEntityManager(SynchronizationType.SYNCHRONIZED, props); + } + + /** * Creates and configures a entity manager with the given properties. * @@ -159,11 +170,21 @@ public class EntityManagerFactoryImpl * * @return list of exceptions raised or empty list. */ - public OpenJPAEntityManagerSPI createEntityManager(Map props) { - if (props == null) + public OpenJPAEntityManagerSPI createEntityManager(SynchronizationType synchronizationType, Map props) { + if (synchronizationType == null) { + throw new NullPointerException("SynchronizationType must not be null"); + } + if (SynchronizationType.UNSYNCHRONIZED.equals(synchronizationType)) { + throw new UnsupportedOperationException("TODO - implement JPA 2.1 feature"); + } + + if (props == null) { props = Collections.EMPTY_MAP; - else if (!props.isEmpty()) + } + else if (!props.isEmpty()) { props = new HashMap(props); + } + OpenJPAConfiguration conf = getConfiguration(); Log log = conf.getLog(OpenJPAConfiguration.LOG_RUNTIME); @@ -242,16 +263,6 @@ public class EntityManagerFactoryImpl return em; } - @Override - public EntityManager createEntityManager(SynchronizationType synchronizationType) { - throw new UnsupportedOperationException("JPA 2.1"); - } - - @Override - public EntityManager createEntityManager(SynchronizationType synchronizationType, Map map) { - throw new UnsupportedOperationException("JPA 2.1"); - } - /** * Create a new entity manager around the given broker. */