You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2015/04/29 16:29:25 UTC

tomee git commit: TOMEE-1567 backporting support of overriding of PU properties from application.properties

Repository: tomee
Updated Branches:
  refs/heads/tomee-1.7.x 65639b43a -> 2b7db9713


TOMEE-1567 backporting support of overriding of PU properties from application.properties


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

Branch: refs/heads/tomee-1.7.x
Commit: 2b7db971334cd138f2f317193ffa8d774a5637da
Parents: 65639b4
Author: Romain Manni-Bucau <rm...@apache.org>
Authored: Wed Apr 29 16:29:16 2015 +0200
Committer: Romain Manni-Bucau <rm...@apache.org>
Committed: Wed Apr 29 16:29:16 2015 +0200

----------------------------------------------------------------------
 .../apache/openejb/config/AppInfoBuilder.java   | 41 +++++++++++++-------
 1 file changed, 26 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/2b7db971/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java b/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java
index ca7c552..c2517cd 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java
@@ -669,7 +669,7 @@ class AppInfoBuilder {
                 // Handle Properties
                 info.properties.putAll(persistenceUnit.getProperties());
 
-                PersistenceProviderProperties.apply(appModule.getClassLoader(), info);
+                PersistenceProviderProperties.apply(appModule, info);
 
 
                 // Persistence Unit Root Url
@@ -736,10 +736,11 @@ class AppInfoBuilder {
         }
 
         /**
-         * @param classLoader the temp classloader, take care to only use getResource here
+         * @param appModule the app module with its config and its temp classloader, take care to only use getResource here
          * @param info        the persistence unit info
          */
-        private static void apply(final ClassLoader classLoader, final PersistenceUnitInfo info) {
+        private static void apply(final AppModule appModule, final PersistenceUnitInfo info) {
+            final ClassLoader classLoader = appModule.getClassLoader();
             overrideFromSystemProp(info);
 
             // The result is that OpenEJB-specific configuration can be avoided when
@@ -755,7 +756,7 @@ class AppInfoBuilder {
             if ("org.hibernate.ejb.HibernatePersistence".equals(info.provider) || "org.hibernate.jpa.HibernatePersistenceProvider".equals(info.provider)) {
 
                 // Apply the overrides that apply to all persistence units of this provider
-                override(info, "hibernate");
+                override(appModule.getProperties(), info, "hibernate");
 
                 String className = info.properties.getProperty(HIBERNATE_JTA_PLATFORM);
                 if (className == null) {
@@ -801,7 +802,7 @@ class AppInfoBuilder {
                 "oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider".equals(info.provider)) {
 
                 // Apply the overrides that apply to all persistence units of this provider
-                override(info, "toplink");
+                override(appModule.getProperties(), info, "toplink");
 
                 final String lookupProperty = "toplink.target-server";
                 final String openejbLookupClass = MakeTxLookup.TOPLINK_FACTORY;
@@ -820,7 +821,7 @@ class AppInfoBuilder {
             } else if ("org.eclipse.persistence.jpa.PersistenceProvider".equals(info.provider) || "org.eclipse.persistence.jpa.osgi.PersistenceProvider".equals(info.provider)) {
 
                 // Apply the overrides that apply to all persistence units of this provider
-                override(info, "eclipselink");
+                override(appModule.getProperties(), info, "eclipselink");
 
                 final String className = info.properties.getProperty(ECLIPSELINK_TARGET_SERVER);
 
@@ -847,7 +848,7 @@ class AppInfoBuilder {
             } else if (info.provider == null || "org.apache.openjpa.persistence.PersistenceProviderImpl".equals(info.provider)) {
 
                 // Apply the overrides that apply to all persistence units of this provider
-                override(info, "openjpa");
+                override(appModule.getProperties(), info, "openjpa");
 
                 final String existing = info.properties.getProperty(OPENJPA_RUNTIME_UNENHANCED_CLASSES);
 
@@ -893,7 +894,7 @@ class AppInfoBuilder {
             }
 
             // Apply the overrides that apply to just this persistence unit
-            override(info);
+            override(appModule.getProperties(), info);
         }
 
         private static void overrideFromSystemProp(final PersistenceUnitInfo info) {
@@ -914,20 +915,30 @@ class AppInfoBuilder {
             }
         }
 
-        private static void override(final PersistenceUnitInfo info) {
-            override(info, info.name);
+        private static void override(final Properties appProperties, final PersistenceUnitInfo info) {
+            override(appProperties, info, info.name);
         }
 
-        private static void override(final PersistenceUnitInfo info, final String prefix) {
+        private static void override(final Properties appProperties, final PersistenceUnitInfo info, final String prefix) {
 
-            final Properties overrides = ConfigurationFactory.getSystemProperties(prefix, "PersistenceUnit");
+            final Properties propertiesToCheckForOverridings = new Properties(System.getProperties());
+            propertiesToCheckForOverridings.putAll(SystemInstance.get().getProperties());
+            propertiesToCheckForOverridings.putAll(appProperties);
+            final Properties overrides = ConfigurationFactory.getOverrides(propertiesToCheckForOverridings, prefix, "PersistenceUnit");
 
             for (final Map.Entry<Object, Object> entry : overrides.entrySet()) {
                 final String property = (String) (prefix.equalsIgnoreCase(info.name) ? entry.getKey() : prefix + "." + entry.getKey());
-                final String value = (String) entry.getValue();
+                String value = (String) entry.getValue();
 
-                if ("openjpa.Log".equals(property) && info.properties.containsKey("openjpa.Log")) { // we set a default
-                    continue;
+                if ("openjpa.Log".equals(property) && "org.apache.openejb.openjpa.JULOpenJPALogFactory".equals(value)) { // we set a default
+                    if (info.properties.containsKey("openjpa.Log")) {
+                        continue;
+                    }
+                    if (appProperties.containsKey("openjpa.Log")) {
+                        value = appProperties.getProperty(property, value);
+                    } else {
+                        continue;
+                    }
                 }
 
                 if (info.properties.containsKey(property)) {