This is an automated email from the ASF dual-hosted git repository. rmannibucau pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/openjpa.git
The following commit(s) were added to refs/heads/master by this push: new bd015d0 [OPENJPA-2834] cache EMF#properties bd015d0 is described below commit bd015d02e95bd3d7c39f3b0a9bdf2cb448bedc75 Author: Romain Manni-Bucau <rmannibu...@gmail.com> AuthorDate: Wed Sep 30 12:14:35 2020 +0200 [OPENJPA-2834] cache EMF#properties --- .../persistence/EntityManagerFactoryImpl.java | 27 ++++++++++++++++++---- .../openjpa/persistence/EntityManagerImpl.java | 8 +++++++ 2 files changed, 31 insertions(+), 4 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 4dd9728..0c8ff9a 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 @@ -75,6 +75,8 @@ public class EntityManagerFactoryImpl private transient StoreCache _cache = null; private transient QueryResultCache _queryCache = null; private transient MetamodelImpl _metaModel; + private transient Map<String, Object> properties; + private transient Map<String, Object> emEmptyPropsProperties; /** * Default constructor provided for auto-instantiation. @@ -111,10 +113,19 @@ public class EntityManagerFactoryImpl @Override public Map<String,Object> getProperties() { - Map<String,Object> props = _factory.getProperties(); - // convert to user readable values - props.putAll(createEntityManager().getProperties()); - return props; + if (properties == null) { + Map<String,Object> props = _factory.getProperties(); + // convert to user readable values + if (emEmptyPropsProperties != null) { + props.putAll(emEmptyPropsProperties); + } else { + props.putAll(createEntityManager().getProperties()); + } + // no need to sync or volatile, worse case concurrent threads create 2 instances + // we just want to avoid to do it after some "init" phase + this.properties = props; + } + return properties; } @Override @@ -201,6 +212,7 @@ public class EntityManagerFactoryImpl props = new HashMap(props); } + boolean canCacheGetProperties = props.isEmpty(); // nominal case OpenJPAConfiguration conf = getConfiguration(); Log log = conf.getLog(OpenJPAConfiguration.LOG_RUNTIME); @@ -273,6 +285,13 @@ public class EntityManagerFactoryImpl for (Map.Entry entry : entrySet) { em.setProperty(entry.getKey().toString(), entry.getValue()); } + if (canCacheGetProperties) { + if (emEmptyPropsProperties == null) { + emEmptyPropsProperties = em.getProperties(); + } else if (EntityManagerImpl.class.isInstance(em)) { + EntityManagerImpl.class.cast(em).setProperties(emEmptyPropsProperties); + } + } if (log != null && log.isTraceEnabled()) { log.trace(this + " created EntityManager " + em + "."); } diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java index 35606f0..9782412 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/EntityManagerImpl.java @@ -122,6 +122,7 @@ public class EntityManagerImpl protected RuntimeExceptionTranslator _ret = PersistenceExceptions.getRollbackTranslator(this); private boolean _convertPositionalParams = false; private boolean _isJoinedToTransaction; + private Map<String, Object> properties; public EntityManagerImpl() { // for Externalizable @@ -1792,6 +1793,10 @@ public class EntityManagerImpl } } + public void setProperties(final Map<String, Object> emEmptyPropsProperties) { + this.properties = emEmptyPropsProperties; + } + private static class BrokerBytesInputStream extends ObjectInputStream { private OpenJPAConfiguration conf; @@ -1935,6 +1940,9 @@ public class EntityManagerImpl */ @Override public Map<String, Object> getProperties() { + if (properties != null) { + return properties; + } Map<String,Object> props = _broker.getProperties(); for (String s : _broker.getSupportedProperties()) { String kernelKey = getBeanPropertyName(s);