Author: max.andersen(a)jboss.com
Date: 2007-01-23 12:12:25 -0500 (Tue, 23 Jan 2007)
New Revision: 11082
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/HibernateConfigurationExporter.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Hbm2CfgTest.java
Log:
HBX-859 cfg.xml generation should ignore "magic" properties
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/HibernateConfigurationExporter.java
===================================================================
---
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/HibernateConfigurationExporter.java 2007-01-23
16:31:13 UTC (rev 11081)
+++
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/HibernateConfigurationExporter.java 2007-01-23
17:12:25 UTC (rev 11082)
@@ -9,6 +9,7 @@
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
@@ -89,13 +90,24 @@
String sfname = (String) props.get(Environment.SESSION_FACTORY_NAME);
pw.println(" <session-factory" +
(sfname==null?"":" name=\"" + sfname + "\"") +
">");
+
+ Map ignoredProperties = new HashMap();
+ ignoredProperties.put(Environment.SESSION_FACTORY_NAME, null);
+ ignoredProperties.put(Environment.HBM2DDL_AUTO, "false" );
+ ignoredProperties.put("hibernate.temp.use_jdbc_metadata_defaults", null
);
Set set = props.entrySet();
Iterator iterator = set.iterator();
while (iterator.hasNext() ) {
Map.Entry element = (Map.Entry) iterator.next();
String key = (String) element.getKey();
- if(!key.equals(Environment.SESSION_FACTORY_NAME) &&
key.startsWith("hibernate.") ) { // if not starting with hibernate. not relevant
for cfg.xml
+ if(ignoredProperties.containsKey( key )) {
+ Object ignoredValue = ignoredProperties.get( key );
+ if(ignoredValue == null || element.getValue().equals(ignoredValue)) {
+ continue;
+ }
+ }
+ if(key.startsWith("hibernate.") ) { // if not starting with
hibernate. not relevant for cfg.xml
pw.println(" <property name=\"" + key +
"\">" + element.getValue() + "</property>");
}
}
Modified:
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Hbm2CfgTest.java
===================================================================
---
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Hbm2CfgTest.java 2007-01-23
16:31:13 UTC (rev 11081)
+++
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Hbm2CfgTest.java 2007-01-23
17:12:25 UTC (rev 11082)
@@ -6,6 +6,8 @@
import java.io.File;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
import org.hibernate.tool.NonReflectiveTestCase;
/**
@@ -28,6 +30,32 @@
}
+ public void testMagicPropertyHandling() {
+ Configuration srcCfg = new Configuration();
+
+ srcCfg.setProperty( "hibernate.basic", "aValue" );
+ srcCfg.setProperty( Environment.SESSION_FACTORY_NAME, "shouldNotShowUp");
+ srcCfg.setProperty( Environment.HBM2DDL_AUTO, "false");
+ srcCfg.setProperty( "hibernate.temp.use_jdbc_metadata_defaults",
"false");
+
+ new HibernateConfigurationExporter(srcCfg, getOutputDir()).start();
+
+ File file = new File(getOutputDir(), "hibernate.cfg.xml");
+ assertNull(findFirstString( Environment.SESSION_FACTORY_NAME, file ));
+ assertNotNull(findFirstString( "hibernate.basic\">aValue<", file
));
+ assertNull(findFirstString( Environment.HBM2DDL_AUTO, file ));
+ assertNull(findFirstString( "hibernate.temp.use_jdbc_metadata_defaults",
file ));
+
+ srcCfg = new Configuration();
+
+ srcCfg.setProperty( Environment.HBM2DDL_AUTO, "validator");
+
+ new HibernateConfigurationExporter(srcCfg, getOutputDir()).start();
+
+ assertNotNull(findFirstString( Environment.HBM2DDL_AUTO, file ));
+
+ }
+
public void testFileExistence() {
assertFileAndExists(new File(getOutputDir(), "hibernate.cfg.xml") );
Show replies by date