From 9ec74937d13663419b6faf278bb566b81d3b5338 Mon Sep 17 00:00:00 2001 From: Alejandro Revilla Date: Thu, 27 Feb 2020 20:38:27 -0300 Subject: [PATCH] Honor hibernate.cfg.xml when provided closes #135 --- .../src/main/java/org/jpos/ee/DB.java | 46 ++++++++++--------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/modules/dbsupport/src/main/java/org/jpos/ee/DB.java b/modules/dbsupport/src/main/java/org/jpos/ee/DB.java index 6fa902513e..37b30c45d9 100644 --- a/modules/dbsupport/src/main/java/org/jpos/ee/DB.java +++ b/modules/dbsupport/src/main/java/org/jpos/ee/DB.java @@ -100,7 +100,7 @@ public DB() { * META-INF/org/jpos/ee/modules/v1-* instead of just * META-INF/org/jpos/ee/modules/ * - *
  • finally, if the modifier ends with .hbm.xml (case insensitive), then all configuration + *
  • finally, if the modifier ends with .cfg.xml (case insensitive), then all configuration * is picked from that config file.
  • * * @@ -520,9 +520,10 @@ private Metadata getMetadata() throws IOException, ConfigurationException, Docum String propFile; String dbPropertiesPrefix = ""; String metadataPrefix = ""; + boolean standardHibernateConfig = cm.endsWith(".cfg.xml"); String hibCfg = null; - if (cm.endsWith(".cfg.xml")) { + if (standardHibernateConfig) { hibCfg = cm; } else if (configModifier != null) { String[] ss = configModifier.split(":"); @@ -539,26 +540,28 @@ private Metadata getMetadata() throws IOException, ConfigurationException, Docum hibCfg = System.getProperty("HIBERNATE_CFG","/hibernate.cfg.xml"); ssrb.configure(hibCfg); - propFile = System.getProperty(dbPropertiesPrefix + "DB_PROPERTIES", "cfg/" + dbPropertiesPrefix + "db.properties"); - Properties dbProps = loadProperties(propFile); - for (Map.Entry entry : dbProps.entrySet()) { - String k = (String) entry.getKey(); - String v = Environment.get((String) entry.getValue()); - ssrb.applySetting(k,v); - dbProps.setProperty(k,v); - } - - // if DBInstantiator has put db user name and/or password in Space, set Hibernate config accordingly - Space sp = SpaceFactory.getSpace("tspace:dbconfig"); - String user = (String) sp.inp(dbPropertiesPrefix +"connection.username"); - String pass = (String) sp.inp(dbPropertiesPrefix +"connection.password"); - if (user != null) - ssrb.applySetting("hibernate.connection.username", user); - if (pass != null) - ssrb.applySetting("hibernate.connection.password", pass); - + Properties dbProps = null; + if (!standardHibernateConfig) { + propFile = System.getProperty(dbPropertiesPrefix + "DB_PROPERTIES", "cfg/" + dbPropertiesPrefix + "db.properties"); + dbProps = loadProperties(propFile); + for (Map.Entry entry : dbProps.entrySet()) { + String k = (String) entry.getKey(); + String v = Environment.get((String) entry.getValue()); + ssrb.applySetting(k,v); + dbProps.setProperty(k,v); + } + // if DBInstantiator has put db user name and/or password in Space, set Hibernate config accordingly + Space sp = SpaceFactory.getSpace("tspace:dbconfig"); + String user = (String) sp.inp(dbPropertiesPrefix +"connection.username"); + String pass = (String) sp.inp(dbPropertiesPrefix +"connection.password"); + if (user != null) + ssrb.applySetting("hibernate.connection.username", user); + if (pass != null) + ssrb.applySetting("hibernate.connection.password", pass); + } MetadataSources mds = new MetadataSources(ssrb.build()); + List moduleConfigs = ModuleUtils.getModuleEntries(MODULES_CONFIG_PATH); for (String moduleConfig : moduleConfigs) { if (metadataPrefix.length() == 0 || moduleConfig.substring(MODULES_CONFIG_PATH.length()).startsWith(metadataPrefix)) { @@ -570,7 +573,8 @@ private Metadata getMetadata() throws IOException, ConfigurationException, Docum } md = mds.buildMetadata(); metadatas.put(cm, md); - properties.put(cm, dbProps); + if (dbProps != null) + properties.put(cm, dbProps); } } finally { mdSem.release();