Author: max.andersen(a)jboss.com
Date: 2006-09-21 02:48:20 -0400 (Thu, 21 Sep 2006)
New Revision: 10505
Added:
trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/UnionSubclass.hbm.xml
Modified:
trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/DocExporter.java
trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/StringUtils.java
trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/doc/DocFileManager.java
trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/doc/DocHelper.java
trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/DocExporterTest.java
Log:
HBX-723 hbm2doc shows abstract classes as tables
Modified: trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/DocExporter.java
===================================================================
--- trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/DocExporter.java 2006-09-21
06:30:46 UTC (rev 10504)
+++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/DocExporter.java 2006-09-21
06:48:20 UTC (rev 10505)
@@ -263,14 +263,15 @@
Table table = (Table) tables.next();
DocFile docFile = docFileManager.getTableDocFile(table);
+ if(docFile!=null) {
+ File file = docFile.getFile();
- File file = docFile.getFile();
+ Map parameters = new HashMap();
+ parameters.put("docFile", docFile);
+ parameters.put("table", table);
- Map parameters = new HashMap();
- parameters.put("docFile", docFile);
- parameters.put("table", table);
-
- processTemplate(parameters, VM_TABLES_TABLE, file);
+ processTemplate(parameters, VM_TABLES_TABLE, file);
+ }
}
}
Modified: trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/StringUtils.java
===================================================================
--- trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/StringUtils.java 2006-09-21
06:30:46 UTC (rev 10504)
+++ trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/StringUtils.java 2006-09-21
06:48:20 UTC (rev 10505)
@@ -1557,4 +1557,24 @@
return true;
}
+
+ /**
+ * Strip any of the supplied string from the start of a string but
+ * do not strip more than maxStrip characters.
+ * <p>
+ * If maxStrip value is zero then no restriction is imposed.
+ * <p>
+ * @param str the string to remove characters from
+ * @param strip the string to remove
+ * @param max characters to strip
+ * @return the stripped string
+ */
+ public static String stripStart(String str, String strip, int maxStrip) {
+ if (str == null) return null;
+
+ if (maxStrip > 0 && str.length() > maxStrip)
+ return stripStart(str.substring(0,maxStrip), strip) + str.substring(maxStrip);
+ else
+ return stripStart(str, strip);
+ }
}
Modified:
trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/doc/DocFileManager.java
===================================================================
---
trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/doc/DocFileManager.java 2006-09-21
06:30:46 UTC (rev 10504)
+++
trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/doc/DocFileManager.java 2006-09-21
06:48:20 UTC (rev 10505)
@@ -227,12 +227,13 @@
while (tables.hasNext() ) {
Table table = (Table) tables.next();
+ if(table.isPhysicalTable()) {
+ String tableFileName = table.getName() + ".html";
- String tableFileName = table.getName() + ".html";
+ DocFile tableDocFile = new DocFile(tableFileName, schemaFolder);
- DocFile tableDocFile = new DocFile(tableFileName, schemaFolder);
-
- tableDocFiles.put(table, tableDocFile);
+ tableDocFiles.put(table, tableDocFile);
+ }
}
}
}
@@ -373,7 +374,8 @@
* @return the DocFile.
*/
public DocFile getTableDocFile(Table table) {
- return (DocFile) tableDocFiles.get(table);
+ DocFile docFile = (DocFile) tableDocFiles.get(table);
+ return docFile;
}
Modified: trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/doc/DocHelper.java
===================================================================
---
trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/doc/DocHelper.java 2006-09-21
06:30:46 UTC (rev 10504)
+++
trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/doc/DocHelper.java 2006-09-21
06:48:20 UTC (rev 10505)
@@ -3,9 +3,11 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.hibernate.HibernateException;
import org.hibernate.cfg.Configuration;
@@ -130,7 +132,11 @@
Iterator tablesIter = cfg.getTableMappings();
while (tablesIter.hasNext() ) {
- Table table = (Table) tablesIter.next();
+ Table table = (Table) tablesIter.next();
+
+ if(!table.isPhysicalTable()) {
+ continue;
+ }
tables.add(table);
StringBuffer sb = new StringBuffer();
@@ -294,7 +300,8 @@
*/
public List getTables(String schema) {
- return (List) tablesBySchema.get(schema);
+ List list = (List) tablesBySchema.get(schema);
+ return list;
}
/**
Modified: trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/DocExporterTest.java
===================================================================
---
trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/DocExporterTest.java 2006-09-21
06:30:46 UTC (rev 10504)
+++
trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/DocExporterTest.java 2006-09-21
06:48:20 UTC (rev 10505)
@@ -17,7 +17,8 @@
"Order.hbm.xml",
"LineItem.hbm.xml",
"Product.hbm.xml",
- "HelloWorld.hbm.xml"
+ "HelloWorld.hbm.xml",
+ "UnionSubclass.hbm.xml"
};
}
@@ -40,8 +41,13 @@
assertFileAndExists(new File(getOutputDir(), "tables/PUBLIC/summary.html")
);
assertFileAndExists(new File(getOutputDir(),
"tables/PUBLIC/Customer.html") );
+ assertFalse(new File(getOutputDir(),
"tables/PUBLIC/UPerson.html").exists() );
+ assertFileAndExists(new File(getOutputDir(),
"tables/PUBLIC/CROWN_USERS.html") );
assertFileAndExists(new File(getOutputDir(),
"entities/org/hibernate/tool/hbm2x/Customer.html") );
+ assertTrue(new File(getOutputDir(),
"entities/org/hibernate/tool/hbm2x/UPerson.html").exists() );
+ assertFileAndExists(new File(getOutputDir(),
"entities/org/hibernate/tool/hbm2x/UUser.html") );
+
}
Added: trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/UnionSubclass.hbm.xml
===================================================================
---
trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/UnionSubclass.hbm.xml 2006-09-21
06:30:46 UTC (rev 10504)
+++
trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/UnionSubclass.hbm.xml 2006-09-21
06:48:20 UTC (rev 10505)
@@ -0,0 +1,40 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<!--
+
+ This mapping is a test mapping for hbm2java
+
+-->
+
+<hibernate-mapping package="org.hibernate.tool.hbm2x">
+ <class name="UPerson" abstract="true">
+ <cache usage="read-write" />
+ <id name="id" type="long">
+ <column name="PERSON_ID">
+ <comment>the primary key for hibernate</comment>
+ </column>
+ <generator class="sequence">
+ <param name="sequence">PERSON_SEQ</param>
+ </generator>
+ </id>
+
+ <property name="firstName" type="string">
+ <column name="FIRST_NAME" length="50"
not-null="true">
+ <comment>the first name</comment>
+ </column>
+ </property>
+
+ <union-subclass name="UUser" table="CROWN_USERS"
lazy="false">
+ <comment>Table of crown users</comment>
+ <property name="userName" type="string">
+ <column name="USER_NAME" length="15"
not-null="true" unique="true">
+ <comment>the unique user id</comment>
+ </column>
+ </property>
+ </union-subclass>
+ </class>
+</hibernate-mapping>
+