Author: kstam
Date: Wed Sep 14 19:22:03 2011
New Revision: 1170786

URL: http://svn.apache.org/viewvc?rev=1170786&view=rev
Log:
JUDDI-517 adding support for overriding the persistence.xml settings in the 
juddi.properties.

Modified:
    juddi/trunk/juddi-core/src/main/java/org/apache/juddi/config/AppConfig.java
    
juddi/trunk/juddi-core/src/main/java/org/apache/juddi/config/PersistenceManager.java
    juddi/trunk/juddi-core/src/main/java/org/apache/juddi/config/Property.java

Modified: 
juddi/trunk/juddi-core/src/main/java/org/apache/juddi/config/AppConfig.java
URL: 
http://svn.apache.org/viewvc/juddi/trunk/juddi-core/src/main/java/org/apache/juddi/config/AppConfig.java?rev=1170786&r1=1170785&r2=1170786&view=diff
==============================================================================
--- juddi/trunk/juddi-core/src/main/java/org/apache/juddi/config/AppConfig.java 
(original)
+++ juddi/trunk/juddi-core/src/main/java/org/apache/juddi/config/AppConfig.java 
Wed Sep 14 19:22:03 2011
@@ -91,8 +91,21 @@ public class AppConfig 
                propConfig.setReloadingStrategy(fileChangedReloadingStrategy);
                compositeConfig.addConfiguration(propConfig);
                
-               // Properties from the persistence layer (must first initialize 
the entityManagerFactory). 
-               
PersistenceManager.initializeEntityManagerFactory(propConfig.getString(Property.JUDDI_PERSISTENCEUNIT_NAME));
+               
+               Properties properties = new Properties();
+               if 
("Hibernate".equals(propConfig.getString(Property.PERSISTENCE_PROVIDER))) {
+                       if (propConfig.containsKey(Property.DATASOURCE)) 
+                               
properties.put("hibernate.connection.datasource",propConfig.getString(Property.DATASOURCE));
+                       if (propConfig.containsKey(Property.HBM_DDL_AUTO))
+                               
properties.put("hibernate.hbm2ddl.auto",propConfig.getString(Property.HBM_DDL_AUTO));
+                       if (propConfig.containsKey(Property.DEFAULT_SCHEMA))
+                               
properties.put("hibernate.default_schema",propConfig.getString(Property.DEFAULT_SCHEMA));
+                       if (propConfig.containsKey(Property.HIBERNATE_DIALECT))
+                               
properties.put("hibernate.dialect",propConfig.getString(Property.HIBERNATE_DIALECT));
+               }
+               // initialize the entityManagerFactory.
+               
PersistenceManager.initializeEntityManagerFactory(propConfig.getString(Property.JUDDI_PERSISTENCEUNIT_NAME),
 properties);
+               // Properties from the persistence layer 
                MapConfiguration persistentConfig = new 
MapConfiguration(getPersistentConfiguration(compositeConfig));
                
                compositeConfig.addConfiguration(persistentConfig);

Modified: 
juddi/trunk/juddi-core/src/main/java/org/apache/juddi/config/PersistenceManager.java
URL: 
http://svn.apache.org/viewvc/juddi/trunk/juddi-core/src/main/java/org/apache/juddi/config/PersistenceManager.java?rev=1170786&r1=1170785&r2=1170786&view=diff
==============================================================================
--- 
juddi/trunk/juddi-core/src/main/java/org/apache/juddi/config/PersistenceManager.java
 (original)
+++ 
juddi/trunk/juddi-core/src/main/java/org/apache/juddi/config/PersistenceManager.java
 Wed Sep 14 19:22:03 2011
@@ -17,6 +17,8 @@
 
 package org.apache.juddi.config;
 
+import java.util.Properties;
+
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.Persistence;
 import javax.persistence.EntityManager;
@@ -51,10 +53,14 @@ public class PersistenceManager {
                        emf.close();
        }
        
-       protected static void initializeEntityManagerFactory(String 
persistenceUnitName) {
+       protected static void initializeEntityManagerFactory(String 
persistenceUnitName, Properties properties) {
                try {
                        if (emf == null)
-                               emf = 
Persistence.createEntityManagerFactory(persistenceUnitName);
+                               if (properties==null || properties.size()==0) {
+                                       emf = 
Persistence.createEntityManagerFactory(persistenceUnitName);
+                               } else {
+                                       emf = 
Persistence.createEntityManagerFactory(persistenceUnitName, properties);
+                               }
                }
                catch (Throwable t) {
                        log.error("entityManagerFactory creation failed", t);
@@ -62,4 +68,5 @@ public class PersistenceManager {
                }
                
        }
+       
 }

Modified: 
juddi/trunk/juddi-core/src/main/java/org/apache/juddi/config/Property.java
URL: 
http://svn.apache.org/viewvc/juddi/trunk/juddi-core/src/main/java/org/apache/juddi/config/Property.java?rev=1170786&r1=1170785&r2=1170786&view=diff
==============================================================================
--- juddi/trunk/juddi-core/src/main/java/org/apache/juddi/config/Property.java 
(original)
+++ juddi/trunk/juddi-core/src/main/java/org/apache/juddi/config/Property.java 
Wed Sep 14 19:22:03 2011
@@ -52,5 +52,10 @@ public interface Property 
        public final static boolean DEFAULT_LOAD_INSTALL_DATA        =true;
        public final static String DEFAULT_BASE_URL                  
="http://localhost:8080/juddiv3";;
        
-       
+       /* Allowing the the user to override jpa persistence properties in the 
juddi.properties file */
+       public final static String PERSISTENCE_PROVIDER               
="persistenceProvider";
+    public final static String DATASOURCE                         
="hibernate.connection.datasource";
+    public final static String HBM_DDL_AUTO                       
="hibernate.hbm2ddl.auto";
+    public final static String DEFAULT_SCHEMA                     
="hibernate.default_schema";
+    public final static String HIBERNATE_DIALECT                  
="hibernate.dialect"; 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to