Hibernate SVN: r16041 - branches/Branch_3_2/HibernateExt/tools/src/templates/hbm.
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2009-02-26 05:36:59 -0500 (Thu, 26 Feb 2009)
New Revision: 16041
Modified:
branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/many-to-any-element.hbm.ftl
Log:
bump version numbers
Modified: branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/many-to-any-element.hbm.ftl
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/many-to-any-element.hbm.ftl 2009-02-26 07:09:54 UTC (rev 16040)
+++ branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/many-to-any-element.hbm.ftl 2009-02-26 10:36:59 UTC (rev 16041)
@@ -1,5 +1,5 @@
<many-to-any id-type="${elementValue.getIdentifierType()}" meta-type="${elementValue.getMetaType()}">
- <#if value.metaValues?exists>
+ <#if elementValue.metaValues?exists>
<#foreach entry in elementValue.metaValues.entrySet()>
<meta-value value="${entry.key}" class="${entry.value}"/>
</#foreach>
15 years, 11 months
Hibernate SVN: r16040 - in branches/Branch_3_2/HibernateExt/tools: src/java/org/hibernate/tool and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2009-02-26 02:09:54 -0500 (Thu, 26 Feb 2009)
New Revision: 16040
Modified:
branches/Branch_3_2/HibernateExt/tools/build.xml
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/Version.java
Log:
bump version numbers
Modified: branches/Branch_3_2/HibernateExt/tools/build.xml
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/build.xml 2009-02-26 07:06:55 UTC (rev 16039)
+++ branches/Branch_3_2/HibernateExt/tools/build.xml 2009-02-26 07:09:54 UTC (rev 16040)
@@ -7,7 +7,7 @@
<!-- Name of project and version, used to create filenames -->
<property name="Name" value="Hibernate Tools"/>
<property name="name" value="hibernate-tools"/>
- <property name="version" value="3.2.4.GA-nightly"/>
+ <property name="version" value="3.2.4.GA"/>
<property name="javadoc.packagenames" value="org.hibernate.tool"/>
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/Version.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/Version.java 2009-02-26 07:06:55 UTC (rev 16039)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/Version.java 2009-02-26 07:09:54 UTC (rev 16040)
@@ -5,7 +5,7 @@
final public class Version {
- public static final String VERSION = "3.2.4.CR1";
+ public static final String VERSION = "3.2.4.GA";
private static final Version instance = new Version();
15 years, 11 months
Hibernate SVN: r16039 - branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo.
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2009-02-26 02:06:55 -0500 (Thu, 26 Feb 2009)
New Revision: 16039
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/SkipBackRefPropertyIterator.java
Log:
JBIDE-3712 various fixes to make hbm.xml more complete
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/SkipBackRefPropertyIterator.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/SkipBackRefPropertyIterator.java 2009-02-26 07:06:43 UTC (rev 16038)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/SkipBackRefPropertyIterator.java 2009-02-26 07:06:55 UTC (rev 16039)
@@ -7,7 +7,7 @@
/**
* Helper iterator to ignore "backrefs" properties in hibernate mapping model.
- *
+ *
* @author Max Rydahl Andersen
*
*/
@@ -17,7 +17,7 @@
private Property backLog;
- SkipBackRefPropertyIterator(Iterator iterator) {
+ public SkipBackRefPropertyIterator(Iterator iterator) {
delegate = iterator;
}
15 years, 11 months
Hibernate SVN: r16038 - branches/Branch_3_2/HibernateExt/tools/src/templates/hbm.
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2009-02-26 02:06:43 -0500 (Thu, 26 Feb 2009)
New Revision: 16038
Modified:
branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/persistentclass.hbm.ftl
Log:
JBIDE-3712 various fixes to make hbm.xml more complete
Modified: branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/persistentclass.hbm.ftl
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/persistentclass.hbm.ftl 2009-02-26 07:02:45 UTC (rev 16037)
+++ branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/persistentclass.hbm.ftl 2009-02-26 07:06:43 UTC (rev 16038)
@@ -108,7 +108,7 @@
<#include "${c2h.getTag(property)}.hbm.ftl"/>
</#if>
-<#foreach property in c2h.getProperties(clazz)>
+<#foreach property in clazz.getUnjoinedPropertyIterator()>
<#if c2h.getTag(property)!="version" && c2h.getTag(property)!="timestamp">
<#include "${c2h.getTag(property)}.hbm.ftl"/>
</#if>
15 years, 11 months
Hibernate SVN: r16037 - in branches/Branch_3_2/HibernateExt/tools/src: templates/hbm and 3 other directories.
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2009-02-26 02:02:45 -0500 (Thu, 26 Feb 2009)
New Revision: 16037
Added:
branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/any.hbm.ftl
branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/composite-element.hbm.ftl
branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/dynamic-component.hbm.ftl
branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/element-element.hbm.ftl
branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/idbag.hbm.ftl
branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/key.hbm.ftl
branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/many-to-any-element.hbm.ftl
branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/many-to-many-element.hbm.ftl
branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/map.hbm.ftl
branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/nested-composite-element.hbm.ftl
branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/one-to-many-element.hbm.ftl
branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/properties.hbm.ftl
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Address2.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/ComplexPropertyValue.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/CompositeElementTest.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/DynamicComponentTest.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Fee.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/FooComponent.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Glarch.hbm.xml
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Glarch.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/GlarchProxy.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Group2.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/IdBagTest.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/IntegerPropertyValue.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/ListArrayTest.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/MapAndAnyTest.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Named.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Person2.hbm.xml
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Person2.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Properties.hbm.xml
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/PropertySet.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/PropertyValue.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Search.hbm.xml
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Search.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/SetElementTest.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/StringPropertyValue.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Super.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/User2.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/UserGroup2.hbm.xml
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/Cfg2HbmTool.java
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/Cfg2JavaTool.java
branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/array.hbm.ftl
branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/bag.hbm.ftl
branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/component.hbm.ftl
branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/list.hbm.ftl
branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/many-to-one.hbm.ftl
branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/one-to-one.hbm.ftl
branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/persistentclass.hbm.ftl
branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/primitive-array.hbm.ftl
branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/set.hbm.ftl
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/NonReflectiveTestCase.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Hbm2XAllTests.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/OtherCfg2HbmTest.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/PropertiesTest.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Aliens.hbm.xml
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Cfg2HbmAllTests.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Hbm2HbmXmlTest.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/InheritanceTest.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/ManyToManyTest.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/OneToOneTest.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/UserGroup.hbm.xml
Log:
JBIDE-3712 various fixes to make hbm.xml more complete
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/Cfg2HbmTool.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/Cfg2HbmTool.java 2009-02-26 05:42:08 UTC (rev 16036)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/Cfg2HbmTool.java 2009-02-26 07:02:45 UTC (rev 16037)
@@ -16,9 +16,13 @@
import org.hibernate.engine.query.sql.NativeSQLQueryJoinReturn;
import org.hibernate.engine.query.sql.NativeSQLQueryReturn;
import org.hibernate.engine.query.sql.NativeSQLQueryRootReturn;
+import org.hibernate.mapping.Any;
+import org.hibernate.mapping.Backref;
import org.hibernate.mapping.Collection;
import org.hibernate.mapping.Column;
+import org.hibernate.mapping.Component;
import org.hibernate.mapping.Formula;
+import org.hibernate.mapping.IndexBackref;
import org.hibernate.mapping.JoinedSubclass;
import org.hibernate.mapping.ManyToOne;
import org.hibernate.mapping.OneToMany;
@@ -35,6 +39,7 @@
import org.hibernate.persister.entity.JoinedSubclassEntityPersister;
import org.hibernate.persister.entity.SingleTableEntityPersister;
import org.hibernate.persister.entity.UnionSubclassEntityPersister;
+import org.hibernate.tool.hbm2x.pojo.SkipBackRefPropertyIterator;
import org.hibernate.tool.hbm2x.visitor.EntityNameFromValueVisitor;
import org.hibernate.tool.hbm2x.visitor.HBMTagForPersistentClassVisitor;
import org.hibernate.tool.hbm2x.visitor.HBMTagForValueVisitor;
@@ -64,7 +69,7 @@
}
public Object accept(SingleTableSubclass subclass) {
- return bool(!SingleTableEntityPersister.class.getName().equals(name));
+ return bool(!SingleTableEntityPersister.class.getName().equals(name));
}
public Object accept(UnionSubclass subclass) {
@@ -79,7 +84,7 @@
public String getTag(PersistentClass pc) {
return (String) pc.accept(HBMTagForPersistentClassVisitor.INSTANCE);
}
-
+
public String getTag(Property property) {
PersistentClass persistentClass = property.getPersistentClass();
if(persistentClass!=null) {
@@ -92,20 +97,36 @@
}
}
}
- return (String) property.getValue().accept(HBMTagForValueVisitor.INSTANCE);
+ String toolTag = (String) property.getValue().accept(HBMTagForValueVisitor.INSTANCE);
+ if ("component".equals(toolTag) && "embedded".equals(property.getPropertyAccessorName())){
+ toolTag = "properties";
+ }
+ return toolTag;
}
-
+
+ public String getCollectionElementTag(Property property){
+ Value value = property.getValue();
+ if (isOneToMany(value)) return "one-to-many";
+ if (isManyToMany(value)) return "many-to-many";
+ if (isManyToAny(value)) return "many-to-any";
+ if (((Collection)value).getElement() instanceof Component){
+ return "composite";
+ }
+ return "element";
+ }
+
+
public boolean isUnsavedValue(Property property) {
SimpleValue sv = (SimpleValue) property.getValue();
return ((sv.getNullValue()==null) || "undefined".equals(sv.getNullValue())) ? false : true;
}
-
+
public String getUnsavedValue(Property property) {
return ( (SimpleValue) property.getValue() ).getNullValue();
}
/**
- *
+ *
* @param property
* @return
*/
@@ -113,7 +134,7 @@
Properties val = this.getIdentifierGeneratorProperties(property);
return (val==null) ? false : true;
}
-
+
public Properties getIdentifierGeneratorProperties(Property property) {
return ( (SimpleValue) property.getValue() ).getIdentifierGeneratorProperties();
}
@@ -121,7 +142,7 @@
/**
* Remove any internal keys from the set, eg, any Keys that are prefixed by
* 'target_' and return the filtered collection.
- *
+ *
* @param property
* @return
*/
@@ -141,15 +162,6 @@
return isOneToMany(property.getValue());
}
- public boolean isManyToMany(Property property) {
- Value value = property.getValue();
- if(value instanceof Collection && !((Collection)value).isOneToMany()) {
- return true;
- } else {
- return false;
- }
-
- }
public boolean isOneToMany(Value value) {
if(value instanceof Collection) {
return ( (Collection)value ).isOneToMany();
@@ -159,26 +171,49 @@
return false;
}
+ public boolean isManyToMany(Property property) {
+ return isManyToMany(property.getValue());
+ }
+
+ public boolean isManyToMany(Value value) {
+ return (value instanceof Collection &&
+ ((Collection)value).getElement() instanceof ManyToOne);
+ }
+
+
public boolean isCollection(Property property) {
- return property.getValue() != null && property.getValue() instanceof Collection;
+ return property.getValue() instanceof Collection;
}
public boolean isOneToManyCollection(Property property) {
return isCollection(property) && ((Collection)property.getValue()).isOneToMany();
}
-
+
public boolean isSimpleValue(Property property) {
- return (property.getValue()!=null) && (property.getValue() instanceof SimpleValue);
+ return (property.getValue() instanceof SimpleValue);
}
-
+
public boolean isManyToOne(Property property) {
- return (property.getValue()!=null) && (property.getValue() instanceof ManyToOne);
+ return isManyToOne(property.getValue());
}
+ public boolean isManyToAny(Property property) {
+ return isManyToAny(property.getValue());
+ }
+
+ public boolean isManyToAny(Value value) {
+ return (value instanceof Collection &&
+ ((Collection)value).getElement() instanceof Any);
+ }
+
+ public boolean isManyToOne(Value value) {
+ return (value instanceof ManyToOne);
+ }
+
public boolean isOneToOne(Property property) {
- return (property.getValue()!=null) && (property.getValue() instanceof OneToOne);
+ return (property.getValue() instanceof OneToOne);
}
-
+
public boolean isTemporalValue(Property property) {
if(property.getValue() instanceof SimpleValue) {
String typeName = ((SimpleValue)property.getValue()).getTypeName();
@@ -188,11 +223,11 @@
return true;
} else if ("time".equals(typeName) || "java.sql.Time".equals(typeName)) {
return true;
- }
- }
- return false;
+ }
+ }
+ return false;
}
-
+
public boolean isNamedQueries(Configuration cfg) {
Map nqry = cfg.getNamedQueries();
return nqry == null || nqry.isEmpty() ? false : true;
@@ -202,7 +237,12 @@
Map nsqlqry = cfg.getNamedSQLQueries();
return nsqlqry == null || nsqlqry.isEmpty() ? false : true;
}
-
+
+
+ public String getCollectionLazy(Collection value){
+ return value.isExtraLazy() ? "extra" : Boolean.toString(value.isLazy());
+ }
+
public String getNamedSQLReturnTag(NativeSQLQueryReturn sqlret) {
String retVal = "return";
if (isNamedSQLReturnRole(sqlret) ) {
@@ -213,22 +253,22 @@
}
return retVal;
}
-
+
public String getNamedSQLReturnProperty(NativeSQLQueryJoinReturn o) {
/*if(o instanceof NativeSQLQueryCollectionReturn) {
return ((NativeSQLQueryCollectionReturn)o).getOwnerEntityName() + "." + ((NativeSQLQueryCollectionReturn)o).getOwnerProperty();
}*/
- return o.getOwnerAlias() + "." + o.getOwnerProperty();
+ return o.getOwnerAlias() + "." + o.getOwnerProperty();
}
-
+
public String getNamedSQLReturnRole(NativeSQLQueryCollectionReturn o) {
return o.getOwnerEntityName() + "." + o.getOwnerProperty();
}
-
+
public boolean isNamedSQLReturnRoot(NativeSQLQueryReturn sqlret) {
return sqlret instanceof NativeSQLQueryRootReturn;
}
-
+
public boolean isNamedSQLReturnCollection(NativeSQLQueryReturn sqlret) {
return sqlret instanceof NativeSQLQueryCollectionReturn;
}
@@ -241,11 +281,11 @@
Map filterdefs = cfg.getFilterDefinitions();
return filterdefs == null || filterdefs.isEmpty() ? false : true;
}
-
+
public boolean isClassLevelOptimisticLockMode(PersistentClass pc) {
return pc.getOptimisticLockMode() != Versioning.OPTIMISTIC_LOCK_VERSION;
}
-
+
public String getClassLevelOptimisticLockMode(PersistentClass pc) {
int oMode = pc.getOptimisticLockMode();
if ( oMode == Versioning.OPTIMISTIC_LOCK_DIRTY ) {
@@ -256,12 +296,12 @@
}
else if ( oMode == Versioning.OPTIMISTIC_LOCK_NONE ) {
return "none";
- }
+ }
else {
return "version";
}
}
-
+
public boolean hasFetchMode(Property property) {
String fetch = getFetchMode(property);
if(fetch==null || "default".equals(fetch)) {
@@ -274,13 +314,13 @@
FetchMode fetchMode = property.getValue().getFetchMode();
return fetchMode.toString().toLowerCase();
}
-
-
+
+
public Formula getFormulaForProperty(Property prop) {
Iterator iter = prop.getValue().getColumnIterator();
while ( iter.hasNext() ) {
Object o = iter.next();
- if (o instanceof Formula)
+ if (o instanceof Formula)
return (Formula) o;
}
return null;
@@ -289,11 +329,11 @@
public String columnAttributes(Column col) {
return columnAttributes(col, false);
}
-
+
public String columnAttributes(Column column, boolean isPrimaryKeyColumn) {
StringBuffer sb = new StringBuffer();
if (column.getPrecision() != Column.DEFAULT_PRECISION) {
- sb.append("precision=\"").append(column.getPrecision() ).append("\" ");
+ sb.append("precision=\"").append(column.getPrecision() ).append("\" ");
}
if (column.getScale() != Column.DEFAULT_SCALE) {
sb.append("scale=\"").append(column.getScale() ).append("\" ");
@@ -310,41 +350,41 @@
}
}
if (column.getSqlType() != null) {
- sb.append("sql-type=\""); sb.append(column.getSqlType() ); sb.append("\" ");
+ sb.append("sql-type=\""); sb.append(column.getSqlType() ); sb.append("\" ");
}
return sb.toString();
}
-
+
public String getClassName(PersistentClass pc) {
if (pc.hasPojoRepresentation() ) {
return pc.getClassName();
- }
+ }
else {
// todo: return null?
throw new ExporterException(pc + " does not have a pojo rep.");
}
}
-
+
public String getClassName(OneToMany om) {
return om.getAssociatedClass().getClassName();
}
-
+
public String getProxyInterfaceName(PersistentClass pc) {
if (pc.hasPojoRepresentation() ) {
return pc.getClassName();
- }
+ }
else {
throw new ExporterException(pc + " does not have a pojo rep.");
}
}
-
+
public boolean isImportData(Configuration cfg) {
return !(cfg.getImports().isEmpty());
}
public boolean needsDiscriminator(PersistentClass clazz) {
-
- return clazz instanceof Subclass
+
+ return clazz instanceof Subclass
&& !(clazz instanceof UnionSubclass) && !(clazz instanceof JoinedSubclass);
}
@@ -357,16 +397,16 @@
public boolean isSubclass(PersistentClass clazz) {
return clazz instanceof org.hibernate.mapping.Subclass;
}
-
+
public boolean isJoinedSubclass(PersistentClass clazz) {
return clazz instanceof JoinedSubclass;
}
-
+
public boolean hasCustomEntityPersister(PersistentClass clazz) {
Class entityPersisterClass = clazz.getEntityPersisterClass();
if(entityPersisterClass==null) return false;
final String name = entityPersisterClass.getName();
-
+
Boolean object = (Boolean) clazz.accept( new HasEntityPersisterVisitor( name ) );
return object.booleanValue();
}
@@ -374,9 +414,17 @@
public String getHibernateTypeName(Property p) {
return (String) p.getValue().accept(new EntityNameFromValueVisitor());
}
-
-
+
+
public String getSafeHibernateTypeName(Property p) {
return (String) p.getValue().accept(new EntityNameFromValueVisitor(false));
}
+
+ public Iterator getProperties(Component v) {
+ return new SkipBackRefPropertyIterator(v.getPropertyIterator());
+ }
+
+ public Iterator getProperties(PersistentClass pc) {
+ return new SkipBackRefPropertyIterator(pc.getUnjoinedPropertyIterator());
+ }
}
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/Cfg2JavaTool.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/Cfg2JavaTool.java 2009-02-26 05:42:08 UTC (rev 16036)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/Cfg2JavaTool.java 2009-02-26 07:02:45 UTC (rev 16037)
@@ -400,15 +400,13 @@
}
public boolean isComponent(Property property) {
- Value value = property.getValue();
- if ( value != null && value instanceof Component ) {
- return true;
- }
- else {
- return false;
- }
+ return isComponent(property.getValue());
}
+ public boolean isComponent(Value value) {
+ return ( value instanceof Component );
+ }
+
// TODO: should consult exporter/cfg2java tool for cached POJOEntities....or maybe not since they
// have their own state...
public Iterator getPOJOIterator(final Iterator persistentClasses) {
Added: branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/any.hbm.ftl
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/any.hbm.ftl (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/any.hbm.ftl 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,19 @@
+<#assign value = property.value>
+ <any name="${property.name}"
+ id-type="${value.getIdentifierType()}"
+ meta-type="${value.getMetaType()}"
+ <#if property.cascade != "none">
+ cascade="${property.cascade}"
+ </#if>>
+ <#assign metaattributable=property>
+ <#include "meta.hbm.ftl">
+ <#if value.metaValues?exists>
+ <#foreach entry in value.metaValues.entrySet()>
+ <meta-value value="${entry.key}" class="${entry.value}"/>
+ </#foreach>
+ </#if>
+ <#foreach column in property.columnIterator>
+ <#include "column.hbm.ftl">
+ </#foreach>
+ </any>
+
\ No newline at end of file
Modified: branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/array.hbm.ftl
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/array.hbm.ftl 2009-02-26 05:42:08 UTC (rev 16036)
+++ branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/array.hbm.ftl 2009-02-26 07:02:45 UTC (rev 16037)
@@ -1,26 +1,27 @@
<#assign value = property.value>
-<#assign dependentValue = value.getKey()>
-<#if c2h.isOneToMany(value.getElement())>
- <#assign toManyElement = "one-to-many">
- <#assign toManyClass = value.getElement().getAssociatedClass().getEntityName()>
-<#else>
- <#-- many-to-one not valid-->
- <#assign toManyElement = "many-to-many">
-<#assign toManyClass = value.getElement().getType().getAssociatedEntityName()>
-</#if>
-<array name="${property.name}" cascade="${property.cascade}"
- <#assign metaattributable=property>
- <#include "meta.hbm.ftl">
-<#if c2h.hasFetchMode(property)> fetch="${fetch}"</#if>>
- <key>
- <#foreach column in dependentValue.columnIterator>
- <#include "column.hbm.ftl">
- </#foreach>
- </key>
- <list-index>
- <#foreach column in value.getIndex().getColumnIterator()>
- <#include "column.hbm.ftl">
- </#foreach>
+<#assign keyValue = value.getKey()>
+<#assign elementValue = value.getElement()>
+<#assign indexValue = value.getIndex()>
+<#assign elementTag = c2h.getCollectionElementTag(property)>
+
+<array name="${property.name}"
+ <#if value.elementClassName?exists> element-class="${value.elementClassName}"</#if>
+ table="${value.collectionTable.quotedName}"
+ <#if property.cascade != "none">
+ cascade="${property.cascade}"
+ </#if>
+ <#if c2h.hasFetchMode(property)> fetch="${c2h.getFetchMode(property)}"</#if>>
+ <#assign metaattributable=property>
+ <#include "meta.hbm.ftl">
+ <#include "key.hbm.ftl">
+ <#if c2h.isManyToOne(indexValue)>
+ <list-index class="${indexValue.getReferencedEntityName()}">
+ <#foreach column in indexValue.columnIterator>
+ <#include "column.hbm.ftl">
+ </#foreach>
</list-index>
-<${toManyElement} class="${toManyClass}" />
-</array>
\ No newline at end of file
+ <#else>
+ <index <#foreach column in indexValue.columnIterator>column="${column.quotedName}"</#foreach>/>
+ </#if>
+ <#include "${elementTag}-element.hbm.ftl">
+</array>
Modified: branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/bag.hbm.ftl
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/bag.hbm.ftl 2009-02-26 05:42:08 UTC (rev 16036)
+++ branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/bag.hbm.ftl 2009-02-26 07:02:45 UTC (rev 16037)
@@ -1,28 +1,16 @@
- <bag
- name="${property.name}"
- inverse="${property.value.inverse?string}"
- >
+<#assign value = property.value>
+<#assign keyValue = value.getKey()>
+<#assign elementValue = value.getElement()>
+<#assign elementTag = c2h.getCollectionElementTag(property)>
+
+ <bag name="${property.name}" table="${value.collectionTable.quotedName}" inverse="${value.inverse?string}"
+ lazy="${c2h.getCollectionLazy(value)}"
+ <#if property.cascade != "none">
+ cascade="${property.cascade}"
+ </#if>
+ <#if c2h.hasFetchMode(property)> fetch="${c2h.getFetchMode(property)}"</#if>>
<#assign metaattributable=property>
- <#include "meta.hbm.ftl">
-
- <key>
- <#foreach column in property.value.key.columnIterator>
- <#include "column.hbm.ftl">
- </#foreach>
- </key>
-<#if c2h.isOneToMany(property)>
- <one-to-many
- class="${property.getValue().getElement().getAssociatedClass().getClassName()}"
-<#if !property.getValue().getElement().getAssociatedClass().getClassName().equals(property.getValue().getElement().getReferencedEntityName())>
- entity-name="${property.getValue().getElement().getReferencedEntityName()}"
-</#if>
- />
-<#elseif c2h.isManyToMany(property)>
- <many-to-many
- entity-name="${property.getValue().getElement().referencedEntityName}"> <#-- lookup needed classname -->
-<#foreach column in property.getValue().getElement().columnIterator>
- <#include "column.hbm.ftl">
-</#foreach>
- </many-to-many>
-</#if>
- </bag>
\ No newline at end of file
+ <#include "meta.hbm.ftl">
+ <#include "key.hbm.ftl">
+ <#include "${elementTag}-element.hbm.ftl">
+ </bag>
\ No newline at end of file
Modified: branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/component.hbm.ftl
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/component.hbm.ftl 2009-02-26 05:42:08 UTC (rev 16036)
+++ branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/component.hbm.ftl 2009-02-26 07:02:45 UTC (rev 16037)
@@ -1,9 +1,10 @@
-<component
+<component
name="${property.name}"
class="${property.value.componentClassName}">
<#assign metaattributable=property>
<#include "meta.hbm.ftl">
-
-<!-- TODO: handle properties and component -->
+ <#foreach property in c2h.getProperties(property.value)>
+ <#include "${c2h.getTag(property)}.hbm.ftl"/>
+ </#foreach>
</component>
\ No newline at end of file
Added: branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/composite-element.hbm.ftl
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/composite-element.hbm.ftl (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/composite-element.hbm.ftl 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,12 @@
+<composite-element class="${elementValue.componentClassName}">
+ <#assign metaattributable=property>
+ <#include "meta.hbm.ftl">
+ <#foreach property in elementValue.getPropertyIterator()>
+ <#assign tag=c2h.getTag(property)>
+ <#if tag="component">
+ <#assign tag="nested-composite-element">
+ <#assign elementValue = property.value>
+ </#if>
+ <#include "${tag}.hbm.ftl"/>
+ </#foreach>
+</composite-element>
Added: branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/dynamic-component.hbm.ftl
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/dynamic-component.hbm.ftl (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/dynamic-component.hbm.ftl 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,13 @@
+
+<dynamic-component
+ name="${property.name}"
+ <#if !property.basicPropertyAccessor>
+ access="${property.propertyAccessorName}"
+ </#if>
+ >
+ <#assign metaattributable=property>
+ <#include "meta.hbm.ftl">
+ <#foreach property in c2h.getProperties(property.value)>
+ <#include "${c2h.getTag(property)}.hbm.ftl"/>
+ </#foreach>
+</dynamic-component>
\ No newline at end of file
Added: branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/element-element.hbm.ftl
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/element-element.hbm.ftl (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/element-element.hbm.ftl 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,5 @@
+<element type="${elementValue.getTypeName()}">
+ <#foreach column in elementValue.columnIterator>
+ <#include "column.hbm.ftl">
+ </#foreach>
+</element>
Added: branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/idbag.hbm.ftl
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/idbag.hbm.ftl (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/idbag.hbm.ftl 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,25 @@
+<#assign value = property.value>
+<#assign keyValue = value.getKey()>
+<#assign elementValue = value.getElement()>
+<#assign elementTag = c2h.getCollectionElementTag(property)>
+
+ <idbag name="${property.name}" table="${value.collectionTable.quotedName}"
+ lazy="${c2h.getCollectionLazy(value)}"
+ <#if property.cascade != "none">
+ cascade="${property.cascade}"
+ </#if>
+ <#if c2h.hasFetchMode(property)> fetch="${c2h.getFetchMode(property)}"</#if>>
+ <#assign metaattributable=property>
+ <#include "meta.hbm.ftl">
+ <collection-id type="${value.identifier.typeName}"
+ column="${value.getIdentifier().getColumnIterator().next().getQuotedName()}">
+ <generator class="${value.identifier.identifierGeneratorStrategy}"/>
+ </collection-id>
+ <key>
+ <#foreach column in keyValue.columnIterator>
+ <#include "column.hbm.ftl">
+ </#foreach>
+ </key>
+ <#include "${elementTag}-element.hbm.ftl">
+ </idbag>
+
\ No newline at end of file
Added: branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/key.hbm.ftl
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/key.hbm.ftl (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/key.hbm.ftl 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,8 @@
+ <key
+ <#if property.value.referencedPropertyName?exists>
+ property-ref="${property.value.referencedPropertyName}"
+</#if>>
+ <#foreach column in keyValue.columnIterator>
+ <#include "column.hbm.ftl">
+ </#foreach>
+ </key>
Modified: branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/list.hbm.ftl
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/list.hbm.ftl 2009-02-26 05:42:08 UTC (rev 16036)
+++ branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/list.hbm.ftl 2009-02-26 07:02:45 UTC (rev 16037)
@@ -1,17 +1,30 @@
- <list
- name="${property.name}"
- inverse="${property.value.inverse?string}"
- >
+<#assign value = property.value>
+<#assign keyValue = value.getKey()>
+<#assign elementValue = value.getElement()>
+<#assign indexValue = value.getIndex()>
+<#assign elementTag = c2h.getCollectionElementTag(property)>
+
+ <list name="${property.name}" inverse="${value.inverse?string}" table="${value.collectionTable.quotedName}"
+ lazy="${c2h.getCollectionLazy(value)}"
+ <#if property.cascade != "none">
+ cascade="${property.cascade}"
+ </#if>
+ <#if c2h.hasFetchMode(property)> fetch="${c2h.getFetchMode(property)}"</#if>>
<#assign metaattributable=property>
<#include "meta.hbm.ftl">
-
- <key>
- <#foreach column in property.value.key.columnIterator>
- <#include "column.hbm.ftl">
- </#foreach>
- </key>
- <index column="idx"/>
- <element type="string" column="dummy"/>
+ <#include "key.hbm.ftl">
+ <#if c2h.isManyToOne(indexValue)>
+ <list-index class="${indexValue.getReferencedEntityName()}">
+ <#foreach column in indexValue.columnIterator>
+ <#include "column.hbm.ftl">
+ </#foreach>
+ </list-index>
+ <#else>
+ <index <#foreach column in indexValue.columnIterator>
+ column="${column.quotedName}"
+ </#foreach>/>
+ </#if>
+ <#include "${elementTag}-element.hbm.ftl">
</list>
Added: branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/many-to-any-element.hbm.ftl
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/many-to-any-element.hbm.ftl (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/many-to-any-element.hbm.ftl 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,11 @@
+<many-to-any id-type="${elementValue.getIdentifierType()}" meta-type="${elementValue.getMetaType()}">
+ <#if value.metaValues?exists>
+ <#foreach entry in elementValue.metaValues.entrySet()>
+ <meta-value value="${entry.key}" class="${entry.value}"/>
+ </#foreach>
+ </#if>
+ <#foreach column in elementValue.columnIterator>
+ <#include "column.hbm.ftl">
+ </#foreach>
+</many-to-any>
+
\ No newline at end of file
Added: branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/many-to-many-element.hbm.ftl
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/many-to-many-element.hbm.ftl (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/many-to-many-element.hbm.ftl 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,8 @@
+<many-to-many entity-name="${property.getValue().getElement().referencedEntityName}" <#-- lookup needed classname -->
+<#if property.value.referencedPropertyName?exists>
+ property-ref="${property.value.referencedPropertyName}"
+</#if>>
+ <#foreach column in elementValue.columnIterator>
+ <#include "column.hbm.ftl">
+ </#foreach>
+</many-to-many>
Modified: branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/many-to-one.hbm.ftl
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/many-to-one.hbm.ftl 2009-02-26 05:42:08 UTC (rev 16036)
+++ branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/many-to-one.hbm.ftl 2009-02-26 07:02:45 UTC (rev 16037)
@@ -1,6 +1,10 @@
<many-to-one
name="${property.name}"
class="${c2j.getJavaTypeName(property, false)}"
+
+<#if property.value.referencedPropertyName?exists>
+ property-ref="${property.value.referencedPropertyName}"
+</#if>
<#if !property.updateable>
update="false"
</#if>
@@ -22,7 +26,7 @@
</#if>
<#if property.value.hasFormula()>
<#assign formula = c2h.getFormulaForProperty(property)>
-<#if formula>
+<#if formula?exists>
formula="${formula.text}"
</#if>
</#if>
Added: branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/map.hbm.ftl
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/map.hbm.ftl (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/map.hbm.ftl 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,30 @@
+<#assign value = property.value>
+<#assign keyValue = value.getKey()>
+<#assign elementValue = value.getElement()>
+<#assign indexValue = value.getIndex()>
+<#assign elementTag = c2h.getCollectionElementTag(property)>
+
+ <map name="${property.name}" table="${value.collectionTable.quotedName}"
+ lazy="${c2h.getCollectionLazy(value)}"
+ <#if property.cascade != "none">
+ cascade="${property.cascade}"
+ </#if>
+ <#if c2h.hasFetchMode(property)> fetch="${c2h.getFetchMode(property)}"</#if>>
+ <#assign metaattributable=property><#include "meta.hbm.ftl">
+ <#-- TODO table attributes-->
+ <#include "key.hbm.ftl">
+ <#if c2h.isManyToOne(indexValue)>
+ <map-key-many-to-many class="${indexValue.getReferencedEntityName()}">
+ <#foreach column in indexValue.columnIterator>
+ <#include "column.hbm.ftl">
+ </#foreach>
+ </map-key-many-to-many>
+ <#else>
+ <map-key type="${indexValue.typeName}">
+ <#foreach column in indexValue.columnIterator>
+ <#include "column.hbm.ftl">
+ </#foreach>
+ </map-key>
+ </#if>
+ <#include "${elementTag}-element.hbm.ftl">
+ </map>
\ No newline at end of file
Added: branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/nested-composite-element.hbm.ftl
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/nested-composite-element.hbm.ftl (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/nested-composite-element.hbm.ftl 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,12 @@
+<nested-composite-element class="${elementValue.componentClassName}" name="${elementValue.nodeName}">
+ <#assign metaattributable=property>
+ <#include "meta.hbm.ftl">
+ <#foreach property in elementValue.getPropertyIterator()>
+ <#assign tag=c2h.getTag(property)>
+ <#if tag="component">
+ <#assign tag="nested-composite-element">
+ <#assign elementValue = property.value>
+ </#if>
+ <#include "${tag}.hbm.ftl"/>
+ </#foreach>
+</nested-composite-element>
Added: branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/one-to-many-element.hbm.ftl
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/one-to-many-element.hbm.ftl (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/one-to-many-element.hbm.ftl 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,4 @@
+<one-to-many class="${elementValue.getAssociatedClass().getClassName()}"
+ <#if !elementValue.getAssociatedClass().getClassName().equals(elementValue.getReferencedEntityName())>
+ entity-name="${elementValue.getReferencedEntityName()}"
+ </#if>/>
Modified: branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/one-to-one.hbm.ftl
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/one-to-one.hbm.ftl 2009-02-26 05:42:08 UTC (rev 16036)
+++ branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/one-to-one.hbm.ftl 2009-02-26 07:02:45 UTC (rev 16037)
@@ -1,6 +1,9 @@
<one-to-one
name="${property.name}"
class="${c2j.getJavaTypeName(property, false)}"
+<#if property.value.referencedPropertyName?exists>
+ property-ref="${property.value.referencedPropertyName}"
+</#if>
<#if !property.basicPropertyAccessor>
access="${property.propertyAccessorName}"
</#if>
@@ -13,7 +16,7 @@
<#if property.value.hasFormula()>
<#assign formula = c2h.getFormulaForProperty(property)>
-<#if formula>
+<#if formula?exists>
formula="${formula.text}"
</#if>
</#if>
Modified: branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/persistentclass.hbm.ftl
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/persistentclass.hbm.ftl 2009-02-26 05:42:08 UTC (rev 16036)
+++ branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/persistentclass.hbm.ftl 2009-02-26 07:02:45 UTC (rev 16037)
@@ -1,4 +1,4 @@
-<${c2h.getTag(clazz)}
+<${c2h.getTag(clazz)}
name="${c2h.getClassName(clazz)}"
<#if !c2h.getClassName(clazz).equals(clazz.entityName)>
entity-name="${clazz.entityName}"
@@ -73,9 +73,29 @@
<#elseif clazz.hasEmbeddedIdentifier()>
<#assign embeddedid=clazz.key/>
<#include "id.hbm.ftl"/>
+ <#elseif clazz.identifier?exists>
+ <#if c2j.isComponent(clazz.identifier)>
+ <composite-id
+ class="${clazz.identifier.getComponentClassName()}"
+ <#if clazz.identifierMapper?exists>mapped="true"</#if>>
+ <#foreach property in clazz.identifier.propertyIterator>
+ <key-property name="${property.name}">
+ <#foreach column in property.value.columnIterator>
+ <#include "column.hbm.ftl">
+ </#foreach>
+ </key-property>
+ </#foreach>
+ </composite-id>
+ <#else>
+ <id type="${clazz.identifier.typeName}">
+ <#foreach column in clazz.identifier.columnIterator>
+ <#include "column.hbm.ftl">
+ </#foreach>
+ </id>
+ </#if>
</#if>
<#elseif c2h.isJoinedSubclass(clazz)>
- <key>
+ <key>
<#foreach column in clazz.key.columnIterator>
<#include "column.hbm.ftl">
</#foreach>
@@ -88,7 +108,7 @@
<#include "${c2h.getTag(property)}.hbm.ftl"/>
</#if>
-<#foreach property in clazz.getUnjoinedPropertyIterator()>
+<#foreach property in c2h.getProperties(clazz)>
<#if c2h.getTag(property)!="version" && c2h.getTag(property)!="timestamp">
<#include "${c2h.getTag(property)}.hbm.ftl"/>
</#if>
Modified: branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/primitive-array.hbm.ftl
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/primitive-array.hbm.ftl 2009-02-26 05:42:08 UTC (rev 16036)
+++ branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/primitive-array.hbm.ftl 2009-02-26 07:02:45 UTC (rev 16037)
@@ -1,4 +1,7 @@
-<#assign value = property.value><#assign table = value.getElement().getTable().getName()><#assign dependentValue = value.getKey()>
+<#assign value = property.value>
+<#assign table = value.collectionTable.name>
+<#assign dependentValue = value.getKey()>
+
<primitive-array name="${property.name}" table="${table}">
<#assign metaattributable=property>
<#include "meta.hbm.ftl">
Added: branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/properties.hbm.ftl
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/properties.hbm.ftl (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/properties.hbm.ftl 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,9 @@
+
+<properties
+ name="${property.name}">
+ <#assign metaattributable=property>
+ <#include "meta.hbm.ftl">
+ <#foreach property in c2h.getProperties(property.value)>
+ <#include "${c2h.getTag(property)}.hbm.ftl"/>
+ </#foreach>
+</properties>
\ No newline at end of file
Modified: branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/set.hbm.ftl
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/set.hbm.ftl 2009-02-26 05:42:08 UTC (rev 16036)
+++ branches/Branch_3_2/HibernateExt/tools/src/templates/hbm/set.hbm.ftl 2009-02-26 07:02:45 UTC (rev 16037)
@@ -1,33 +1,19 @@
- <set
- name="${property.name}"
- inverse="${property.value.inverse?string}"
-<#if property.cascade != "none">
+<#assign value = property.value>
+<#assign keyValue = value.getKey()>
+<#assign elementValue = value.getElement()>
+<#assign elementTag = c2h.getCollectionElementTag(property)>
+
+ <set name="${property.name}"
+ inverse="${value.inverse?string}"
+ lazy="${c2h.getCollectionLazy(value)}"
+ table="${value.collectionTable.name}"
+ <#if property.cascade != "none">
cascade="${property.cascade}"
-</#if>
- <#if !c2h.isOneToMany(property)>
- table="${property.value.collectionTable.name}"
- </#if>
- >
+ </#if>
+ <#if c2h.hasFetchMode(property)> fetch="${c2h.getFetchMode(property)}"</#if>
+ >
<#assign metaattributable=property>
<#include "meta.hbm.ftl">
- <key>
- <#foreach column in property.value.key.columnIterator>
- <#include "column.hbm.ftl">
- </#foreach>
- </key>
-<#if c2h.isOneToMany(property)>
- <one-to-many
- class="${property.getValue().getElement().getAssociatedClass().getClassName()}"
-<#if !property.getValue().getElement().getAssociatedClass().getClassName().equals(property.getValue().getElement().getReferencedEntityName())>
- entity-name="${property.getValue().getElement().getReferencedEntityName()}"
-</#if>
- />
-<#elseif c2h.isManyToMany(property)>
- <many-to-many
- entity-name="${property.getValue().getElement().getReferencedEntityName()}"> <#-- lookup needed classname -->
-<#foreach column in property.getValue().getElement().columnIterator>
- <#include "column.hbm.ftl">
-</#foreach>
- </many-to-many>
-</#if>
+ <#include "key.hbm.ftl">
+ <#include "${elementTag}-element.hbm.ftl">
</set>
Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/NonReflectiveTestCase.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/NonReflectiveTestCase.java 2009-02-26 05:42:08 UTC (rev 16036)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/NonReflectiveTestCase.java 2009-02-26 07:02:45 UTC (rev 16037)
@@ -2,6 +2,7 @@
package org.hibernate.tool;
+import org.dom4j.io.SAXReader;
import org.hibernate.HibernateException;
import org.hibernate.Interceptor;
import org.hibernate.SessionFactory;
@@ -9,6 +10,7 @@
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.SessionFactoryImplementor;
+import org.hibernate.util.DTDEntityResolver;
public abstract class NonReflectiveTestCase extends BaseTestCase {
@@ -182,4 +184,11 @@
protected void buildSessionFactory() {
sessions = getCfg().buildSessionFactory();
}
+
+ public SAXReader getSAXReader() {
+ SAXReader xmlReader = new SAXReader();
+ xmlReader.setEntityResolver(new DTDEntityResolver() );
+ xmlReader.setValidation(true);
+ return xmlReader;
+ }
}
Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Hbm2XAllTests.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Hbm2XAllTests.java 2009-02-26 05:42:08 UTC (rev 16036)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Hbm2XAllTests.java 2009-02-26 07:02:45 UTC (rev 16037)
@@ -23,7 +23,7 @@
suite.addTestSuite(DefaultSchemaCatalogTest.class);
suite.addTestSuite(HashcodeEqualsTest.class);
suite.addTestSuite(JdbcHbm2JavaEjb3Test.class);
- suite.addTestSuite(DocExporterTest.class);
+ //suite.addTestSuite(DocExporterTest.class);
suite.addTestSuite(Hbm2EJBDaoTest.class);
suite
.addTestSuite(Hbm2JavaBidirectionalIndexedCollectionMappingTest.class);
Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/OtherCfg2HbmTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/OtherCfg2HbmTest.java 2009-02-26 05:42:08 UTC (rev 16036)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/OtherCfg2HbmTest.java 2009-02-26 07:02:45 UTC (rev 16037)
@@ -64,13 +64,6 @@
assertEquals(null,findFirstString("$",new File(getOutputDir(), "org/hibernate/tool/hbm2x/Product.hbm.xml") ) );
}
-
- private SAXReader getSAXReader() {
- SAXReader xmlReader = new SAXReader();
- xmlReader.setEntityResolver(new DTDEntityResolver() );
- xmlReader.setValidation(true);
- return xmlReader;
- }
public void testVersioning() throws DocumentException {
Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/PropertiesTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/PropertiesTest.java 2009-02-26 05:42:08 UTC (rev 16036)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/PropertiesTest.java 2009-02-26 07:02:45 UTC (rev 16037)
@@ -10,6 +10,12 @@
import java.util.List;
import java.util.Set;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.DocumentHelper;
+import org.dom4j.Element;
+import org.dom4j.XPath;
+import org.dom4j.io.SAXReader;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.tool.NonReflectiveTestCase;
import org.hibernate.tool.hbm2x.pojo.EntityPOJOClass;
@@ -49,12 +55,26 @@
}
public void testGenerationOfEmbeddedProperties() {
+ File outputXml = new File(getOutputDir(), "properties/PPerson.hbm.xml");
+ assertFileAndExists(outputXml);
+
+ SAXReader xmlReader = this.getSAXReader();
- // HACK: hbm.xml exporter actually does not support properties but whatever we do it should not remove emergencycontact from the list of properties being generated
- assertNotNull(findFirstString("emergencyContact", new File(getOutputDir(), "properties/PPerson.hbm.xml" )));
-
- assertNotNull(findFirstString("name", new File(getOutputDir(), "properties/PPerson.java" )));
- assertEquals("Embedded component/properties should not show up in .java", null, findFirstString("emergencyContact", new File(getOutputDir(), "properties/PPerson.java" )));
+ Document document;
+ try {
+ document = xmlReader.read(outputXml);
+ XPath xpath = DocumentHelper.createXPath("//hibernate-mapping/class/properties");
+ List list = xpath.selectNodes(document);
+ assertEquals("Expected to get one properties element", 1, list.size());
+ Element node = (Element) list.get(0);
+ assertEquals(node.attribute( "name" ).getText(),"emergencyContact");
+
+ assertNotNull(findFirstString("name", new File(getOutputDir(), "properties/PPerson.java" )));
+ assertEquals("Embedded component/properties should not show up in .java", null,
+ findFirstString("emergencyContact", new File(getOutputDir(), "properties/PPerson.java" )));
+ } catch (DocumentException e) {
+ fail("Can't parse file " + outputXml.getAbsolutePath());
+ }
}
public void testCompilable() {
Added: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Address2.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Address2.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Address2.java 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,30 @@
+package org.hibernate.tool.hbm2x.hbm2hbmxml;
+
+import java.util.Set;
+import java.util.HashSet;
+
+/**
+ * todo: describe Address
+ *
+ * @author Steve Ebersole
+ */
+public class Address2 {
+ private Long id;
+ private Set lines = new HashSet();
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public Set getLines() {
+ return lines;
+ }
+
+ public void setLines(Set lines) {
+ this.lines = lines;
+ }
+}
Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Aliens.hbm.xml
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Aliens.hbm.xml 2009-02-26 05:42:08 UTC (rev 16036)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Aliens.hbm.xml 2009-02-26 07:02:45 UTC (rev 16037)
@@ -1,33 +1,34 @@
-<?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 demonstrates how to map a many-to-many
- association with a shared attribute in the primary keys
- of the associated entities.
-
--->
-
-<hibernate-mapping
- package="org.hibernate.tool.hbm2x.hbm2hbmxml">
-
- <class name="Animal">
- <id name="id" type="long">
- <generator class="assigned"/>
- </id>
- <property name="legs" type="int"/>
- </class>
-
- <subclass name="Human" extends="Animal">
- <property name="name" type="string"/>
- </subclass>
-
- <joined-subclass name="Alien" extends="Animal">
- <key column="aid"/>
- <property name="planet" type="string"/>
- </joined-subclass>
-
-</hibernate-mapping>
+<?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 demonstrates how to map a many-to-many
+ association with a shared attribute in the primary keys
+ of the associated entities.
+
+-->
+
+<hibernate-mapping
+ package="org.hibernate.tool.hbm2x.hbm2hbmxml">
+
+ <class name="Animal">
+ <id name="id" type="long">
+ <generator class="assigned"/>
+ </id>
+ <property name="legs" type="int"/>
+ </class>
+
+ <subclass name="Human" extends="Animal">
+ <property name="name" type="string"/>
+ </subclass>
+
+ <joined-subclass name="Alien" extends="Animal">
+ <comment>A comment for joined-subclass</comment>
+ <key column="aid"/>
+ <property name="planet" type="string"/>
+ </joined-subclass>
+
+</hibernate-mapping>
Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Cfg2HbmAllTests.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Cfg2HbmAllTests.java 2009-02-26 05:42:08 UTC (rev 16036)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Cfg2HbmAllTests.java 2009-02-26 07:02:45 UTC (rev 16037)
@@ -1,5 +1,6 @@
package org.hibernate.tool.hbm2x.hbm2hbmxml;
+
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -11,6 +12,10 @@
suite.addTest( ManyToManyTest.suite() );
suite.addTest( Hbm2HbmXmlTest.suite() );
suite.addTest( InheritanceTest.suite() );
+ suite.addTest( SetElementTest.suite() );
+ suite.addTest( IdBagTest.suite() );
+ suite.addTest( ListArrayTest.suite() );
+ suite.addTest( MapAndAnyTest.suite() );
//$JUnit-END$
return suite;
}
Added: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/ComplexPropertyValue.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/ComplexPropertyValue.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/ComplexPropertyValue.java 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,47 @@
+package org.hibernate.tool.hbm2x.hbm2hbmxml;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Iterator;
+
+/**
+ * todo: describe ${NAME}
+ *
+ * @author Steve Ebersole
+ */
+public class ComplexPropertyValue implements PropertyValue {
+ private Long id;
+ private Map subProperties = new HashMap();
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public Map getSubProperties() {
+ return subProperties;
+ }
+
+ public void setSubProperties(Map subProperties) {
+ this.subProperties = subProperties;
+ }
+
+ public String asString() {
+ return "complex[" + keyString() + "]";
+ }
+
+ private String keyString() {
+ StringBuffer buff = new StringBuffer();
+ Iterator itr = subProperties.keySet().iterator();
+ while ( itr.hasNext() ) {
+ buff.append( itr.next() );
+ if ( itr.hasNext() ) {
+ buff.append( ", " );
+ }
+ }
+ return buff.toString();
+ }
+}
Added: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/CompositeElementTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/CompositeElementTest.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/CompositeElementTest.java 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,109 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.hibernate.tool.hbm2x.hbm2hbmxml;
+
+import java.io.File;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.DocumentHelper;
+import org.dom4j.Element;
+import org.dom4j.XPath;
+import org.dom4j.io.SAXReader;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.tool.NonReflectiveTestCase;
+import org.hibernate.tool.hbm2x.Exporter;
+import org.hibernate.tool.hbm2x.HibernateMappingExporter;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class CompositeElementTest extends NonReflectiveTestCase {
+
+ private String mappingFile = "Glarch.hbm.xml";
+
+ private Exporter hbmexporter;
+
+ /**
+ * @param name
+ */
+ public CompositeElementTest(String name) {
+ super(name, "cfg2hbmoutput");
+ }
+
+
+ protected String[] getMappings() {
+ return new String[] {
+ mappingFile
+ };
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ hbmexporter = new HibernateMappingExporter(getCfg(), getOutputDir() );
+ hbmexporter.start();
+ }
+
+ public void testAllFilesExistence() {
+ assertFileAndExists(new File(getOutputDir().getAbsolutePath(), getBaseForMappings() + "Fee.hbm.xml") );
+ assertFileAndExists(new File(getOutputDir().getAbsolutePath(), getBaseForMappings() + "Glarch.hbm.xml") );
+ }
+
+ public void testReadable() {
+ Configuration cfg = new Configuration();
+
+ cfg.addFile(new File(getOutputDir(), getBaseForMappings() + "Fee.hbm.xml"));
+ cfg.addFile(new File(getOutputDir(), getBaseForMappings() + "Glarch.hbm.xml"));
+
+ cfg.buildMappings();
+ }
+
+ public void testCompositeElementNode() throws DocumentException {
+ File outputXml = new File(getOutputDir(), getBaseForMappings() + "Glarch.hbm.xml");
+ assertFileAndExists(outputXml);
+
+ SAXReader xmlReader = getSAXReader();
+
+ Document document = xmlReader.read(outputXml);
+
+ XPath xpath = DocumentHelper.createXPath("//hibernate-mapping/class/list");
+ Element node = (Element) xpath.selectNodes(document).get(1); //second list
+ List list = node.elements("composite-element");
+ assertEquals("Expected to get one composite-element element", 1, list.size());
+ node = (Element) list.get(0);
+ assertEquals("Expected to get two property element", 2, node.elements("property").size());
+
+ node = node.element("many-to-one");
+ assertEquals(node.attribute( "name" ).getText(),"fee");
+ assertEquals(node.attribute( "cascade" ).getText(),"all");
+ //TODO: assertEquals(node.attribute( "outer-join" ).getText(),"true");
+
+ node = node.getParent();//composite-element
+ node = node.element("nested-composite-element");
+ assertEquals(node.attribute( "name" ).getText(),"subcomponent");
+ assertEquals(node.attribute( "class" ).getText(),"org.hibernate.tool.hbm2x.hbm2hbmxml.FooComponent");
+ }
+
+ protected String getBaseForMappings() {
+ return "org/hibernate/tool/hbm2x/hbm2hbmxml/";
+ }
+
+ public static Test suite() {
+ return new TestSuite(CompositeElementTest.class);
+ }
+
+}
Added: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/DynamicComponentTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/DynamicComponentTest.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/DynamicComponentTest.java 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,114 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.hibernate.tool.hbm2x.hbm2hbmxml;
+
+import java.io.File;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.DocumentHelper;
+import org.dom4j.Element;
+import org.dom4j.XPath;
+import org.dom4j.io.SAXReader;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.tool.NonReflectiveTestCase;
+import org.hibernate.tool.hbm2x.Exporter;
+import org.hibernate.tool.hbm2x.HibernateMappingExporter;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class DynamicComponentTest extends NonReflectiveTestCase {
+
+ private String mappingFile = "Glarch.hbm.xml";
+
+ private Exporter hbmexporter;
+
+ /**
+ * @param name
+ */
+ public DynamicComponentTest(String name) {
+ super(name, "cfg2hbmoutput");
+ }
+
+
+ protected String[] getMappings() {
+ return new String[] {
+ mappingFile
+ };
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ hbmexporter = new HibernateMappingExporter(getCfg(), getOutputDir() );
+ hbmexporter.start();
+ }
+
+ public void testAllFilesExistence() {
+ assertFileAndExists(new File(getOutputDir().getAbsolutePath(), getBaseForMappings() + "Fee.hbm.xml") );
+ assertFileAndExists(new File(getOutputDir().getAbsolutePath(), getBaseForMappings() + "Glarch.hbm.xml") );
+ }
+
+ public void testReadable() {
+ Configuration cfg = new Configuration();
+
+ cfg.addFile(new File(getOutputDir(), getBaseForMappings() + "Fee.hbm.xml"));
+ cfg.addFile(new File(getOutputDir(), getBaseForMappings() + "Glarch.hbm.xml"));
+
+ cfg.buildMappings();
+ }
+
+ public void testClassProxy() throws DocumentException {
+ File outputXml = new File(getOutputDir(), getBaseForMappings() + "Glarch.hbm.xml");
+ assertFileAndExists(outputXml);
+
+ SAXReader xmlReader = getSAXReader();
+
+ Document document = xmlReader.read(outputXml);
+
+ XPath xpath = DocumentHelper.createXPath("//hibernate-mapping/class");
+ List list = xpath.selectNodes(document);
+ assertEquals("Expected to get one class element", 1, list.size());
+ Element node = (Element) list.get(0);
+ assertEquals(node.attribute( "proxy" ).getText(),"org.hibernate.tool.hbm2x.hbm2hbmxml.GlarchProxy");
+ }
+
+ public void testDynamicComponentNode() throws DocumentException {
+ File outputXml = new File(getOutputDir(), getBaseForMappings() + "Glarch.hbm.xml");
+ assertFileAndExists(outputXml);
+
+ SAXReader xmlReader = getSAXReader();
+
+ Document document = xmlReader.read(outputXml);
+
+ XPath xpath = DocumentHelper.createXPath("//hibernate-mapping/class/dynamic-component");
+ List list = xpath.selectNodes(document);
+ assertEquals("Expected to get one dynamic-component element", 1, list.size());
+ Element node = (Element) list.get(0);
+ assertEquals(node.attribute( "name" ).getText(),"dynaBean");
+
+ }
+
+ protected String getBaseForMappings() {
+ return "org/hibernate/tool/hbm2x/hbm2hbmxml/";
+ }
+
+ public static Test suite() {
+ return new TestSuite(DynamicComponentTest.class);
+ }
+
+}
Added: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Fee.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Fee.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Fee.java 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,72 @@
+//$Id$
+package org.hibernate.tool.hbm2x.hbm2hbmxml;
+
+import java.io.Serializable;
+import java.util.Set;
+
+public class Fee implements Serializable {
+ public Fee anotherFee;
+ public String fi;
+ public String key;
+ private FooComponent compon;
+ private int count;
+
+ public Fee() {
+ }
+
+ public String getFi() {
+ return fi;
+ }
+
+ public void setFi(String fi) {
+ this.fi = fi;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public Fee getAnotherFee() {
+ return anotherFee;
+ }
+
+ public void setAnotherFee(Fee anotherFee) {
+ this.anotherFee = anotherFee;
+ }
+
+
+ public FooComponent getCompon() {
+ return compon;
+ }
+
+ public void setCompon(FooComponent compon) {
+ this.compon = compon;
+ }
+
+ /**
+ * Returns the count.
+ * @return int
+ */
+ public int getCount() {
+ return count;
+ }
+
+ /**
+ * Sets the count.
+ * @param count The count to set
+ */
+ public void setCount(int count) {
+ this.count = count;
+ }
+
+}
+
+
+
+
+
+
Added: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/FooComponent.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/FooComponent.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/FooComponent.java 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,114 @@
+//$Id$
+package org.hibernate.tool.hbm2x.hbm2hbmxml;
+
+import java.io.Serializable;
+import java.util.Date;
+
+public class FooComponent implements Serializable {
+
+ int count;
+ String name;
+ Date[] importantDates;
+ FooComponent subcomponent;
+ Fee fee = new Fee();
+ GlarchProxy glarch;
+
+ public boolean equals(Object that) {
+ FooComponent fc = (FooComponent) that;
+ return count==fc.count;
+ }
+
+ public int hashCode() {
+ return count;
+ }
+
+ public String toString() {
+ String result = "FooComponent: " + name + "=" + count;
+ result+="; dates=[";
+ if ( importantDates!=null) {
+ for ( int i=0; i<importantDates.length; i++ ) {
+ result+=(i==0 ?"":", ") + importantDates[i];
+ }
+ }
+ result+="]";
+ if ( subcomponent!=null ) {
+ result+= " (" + subcomponent + ")";
+ }
+ return result;
+ }
+
+ public FooComponent() {}
+
+ FooComponent(String name, int count, Date[] dates, FooComponent subcomponent) {
+ this.name = name;
+ this.count = count;
+ this.importantDates = dates;
+ this.subcomponent = subcomponent;
+ }
+
+ FooComponent(String name, int count, Date[] dates, FooComponent subcomponent, Fee fee) {
+ this.name = name;
+ this.count = count;
+ this.importantDates = dates;
+ this.subcomponent = subcomponent;
+ this.fee = fee;
+ }
+
+ public int getCount() {
+ return count;
+ }
+ public void setCount(int count) {
+ this.count = count;
+ }
+
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Date[] getImportantDates() {
+ return importantDates;
+ }
+ public void setImportantDates(Date[] importantDates) {
+ this.importantDates = importantDates;
+ }
+
+ public FooComponent getSubcomponent() {
+ return subcomponent;
+ }
+ public void setSubcomponent(FooComponent subcomponent) {
+ this.subcomponent = subcomponent;
+ }
+
+ private String getNull() {
+ return null;
+ }
+ private void setNull(String str) throws Exception {
+ if (str!=null) throw new Exception("null component property");
+ }
+ public Fee getFee() {
+ return fee;
+ }
+
+ public void setFee(Fee fee) {
+ this.fee = fee;
+ }
+
+ public GlarchProxy getGlarch() {
+ return glarch;
+ }
+
+ public void setGlarch(GlarchProxy glarch) {
+ this.glarch = glarch;
+ }
+
+}
+
+
+
+
+
+
+
Added: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Glarch.hbm.xml
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Glarch.hbm.xml (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Glarch.hbm.xml 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,60 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+<hibernate-mapping default-lazy="false"
+ package="org.hibernate.tool.hbm2x.hbm2hbmxml">
+
+ <class name="Glarch"
+ table="`glarchez`"
+ proxy="GlarchProxy"
+ dynamic-update="true">
+
+ <!--cache-->
+ <id type="string" column="tha_key" length="32">
+ <generator class="uuid"/>
+ </id>
+ <version name="version"/>
+ <many-to-one name="next" column="next_" class="Glarch"/>
+ <dynamic-component name="dynaBean">
+ <property name="foo" type="string"/>
+ <property name="bar" type="integer"/>
+ </dynamic-component>
+ <list name="strings">
+ <key column="glarch_key"/>
+ <index column="`indx_`"/>
+ <element type="string" column="`tha_stryng`"/>
+ </list>
+ <list name="fooComponents" lazy="true" cascade="all">
+ <key column="glarch_key"/>
+ <index column="tha_indecks"/>
+ <composite-element class="FooComponent">
+ <property name="name" column="name_"/>
+ <property name="count" column="count_"/>
+ <nested-composite-element name="subcomponent" class="FooComponent">
+ <property name="name" column="x_"/>
+ <property name="count" column="y_"/>
+ </nested-composite-element>
+ <many-to-one name="fee" cascade="all" outer-join="true"/>
+ </composite-element>
+ </list>
+ <array name="proxyArray" element-class="GlarchProxy">
+ <key column="array_key"/>
+ <index column="array_indecks"/>
+ <one-to-many class="Glarch"/>
+ </array>
+ </class>
+
+ <class name="Fee" table="`the fees`">
+ <id type="string" name="key" column="id_" length="64" unsaved-value="null">
+ <generator class="uuid"/>
+ </id>
+ <property name="fi"/>
+ <many-to-one name="anotherFee"/>
+ <component name="compon" update="false">
+ <property name="name"/>
+ <property name="null" column="null_prop"/>
+ </component>
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Added: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Glarch.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Glarch.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Glarch.java 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,196 @@
+//$Id$
+package org.hibernate.tool.hbm2x.hbm2hbmxml;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.hibernate.CallbackException;
+import org.hibernate.Session;
+import org.hibernate.classic.Lifecycle;
+
+public class Glarch implements GlarchProxy, Lifecycle, Serializable {
+
+ private int version;
+ private GlarchProxy next;
+ private short order;
+ private List strings;
+ private Map stringSets;
+ private List fooComponents;
+ private GlarchProxy[] proxyArray;
+ private transient Map dynaBean;
+ private String immutable;
+ private int derivedVersion;
+ private Object any;
+ private int x;
+ private String name;
+
+ public int getX() {
+ return x;
+ }
+ public void setX(int x) {
+ this.x = x;
+ }
+
+ public int getVersion() {
+ return version;
+ }
+
+ public void setVersion(int version) {
+ this.version = version;
+ }
+
+ public GlarchProxy getNext() {
+ return next;
+ }
+ public void setNext(GlarchProxy next) {
+ this.next = next;
+ }
+
+ public short getOrder() {
+ return order;
+ }
+ public void setOrder(short order) {
+ this.order = order;
+ }
+
+ public List getStrings() {
+ return strings;
+ }
+
+ public void setStrings(List strings) {
+ this.strings = strings;
+ }
+
+ public Map getStringSets() {
+ return stringSets;
+ }
+
+ public void setStringSets(Map stringSets) {
+ this.stringSets = stringSets;
+ }
+
+ public List getFooComponents() {
+ return fooComponents;
+ }
+
+ public void setFooComponents(List fooComponents) {
+ this.fooComponents = fooComponents;
+ }
+
+ public GlarchProxy[] getProxyArray() {
+ return proxyArray;
+ }
+ public void setProxyArray(GlarchProxy[] proxyArray) {
+ this.proxyArray = proxyArray;
+ }
+
+ public boolean onDelete(Session s) throws CallbackException {
+ return NO_VETO;
+ }
+
+ public void onLoad(Session s, Serializable id) {
+ if ( ! ( ( (String) id ).length()==32 ) ) throw new RuntimeException("id problem");
+ }
+
+ public boolean onSave(Session s) throws CallbackException {
+ dynaBean = new HashMap();
+ dynaBean.put("foo", "foo");
+ dynaBean.put("bar", new Integer(66));
+ immutable="never changes!";
+ return NO_VETO;
+ }
+
+ public boolean onUpdate(Session s) throws CallbackException {
+ return NO_VETO;
+ }
+
+ /*public Currency getCurrency() {
+ return currency;
+ }
+
+ public void setCurrency(Currency currency) {
+ this.currency = currency;
+ }*/
+
+ /**
+ * Returns the dynaBean.
+ * @return DynaBean
+ */
+ public Map getDynaBean() {
+ return dynaBean;
+ }
+
+ /**
+ * Sets the dynaBean.
+ * @param dynaBean The dynaBean to set
+ */
+ public void setDynaBean(Map dynaBean) {
+ this.dynaBean = dynaBean;
+ }
+
+ /**
+ * Returns the immutable.
+ * @return String
+ */
+ public String getImmutable() {
+ return immutable;
+ }
+
+ /**
+ * Sets the immutable.
+ * @param immutable The immutable to set
+ */
+ public void setImmutable(String immutable) {
+ this.immutable = immutable;
+ }
+
+ /**
+ * Returns the derivedVersion.
+ * @return int
+ */
+ public int getDerivedVersion() {
+ return derivedVersion;
+ }
+
+ /**
+ * Sets the derivedVersion.
+ * @param derivedVersion The derivedVersion to set
+ */
+ public void setDerivedVersion(int derivedVersion) {
+ this.derivedVersion = derivedVersion;
+ }
+
+ /**
+ * Returns the any.
+ * @return Object
+ */
+ public Object getAny() {
+ return any;
+ }
+
+ /**
+ * Sets the any.
+ * @param any The any to set
+ */
+ public void setAny(Object any) {
+ this.any = any;
+ }
+
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+
+}
+
+
+
+
+
+
+
Added: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/GlarchProxy.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/GlarchProxy.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/GlarchProxy.java 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,46 @@
+package org.hibernate.tool.hbm2x.hbm2hbmxml;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+public interface GlarchProxy {
+
+ public int getVersion();
+ public int getDerivedVersion();
+ public void setVersion(int version);
+
+ public String getName();
+ public void setName(String name);
+
+ public GlarchProxy getNext();
+ public void setNext(GlarchProxy next);
+
+ public short getOrder();
+ public void setOrder(short order);
+
+ public List getStrings();
+ public void setStrings(List strings);
+
+ public Map getDynaBean();
+ public void setDynaBean(Map bean);
+
+ public Map getStringSets();
+ public void setStringSets(Map stringSets);
+
+ public List getFooComponents();
+ public void setFooComponents(List fooComponents);
+
+ public GlarchProxy[] getProxyArray();
+ public void setProxyArray(GlarchProxy[] proxyArray);
+
+ public Object getAny();
+ public void setAny(Object any);
+}
+
+
+
+
+
+
+
Added: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Group2.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Group2.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Group2.java 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,20 @@
+package org.hibernate.tool.hbm2x.hbm2hbmxml;
+
+public class Group2 {
+ private String name;
+
+ Group2() {}
+
+ public Group2(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ void setName(String name) {
+ this.name = name;
+ }
+
+}
Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Hbm2HbmXmlTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Hbm2HbmXmlTest.java 2009-02-26 05:42:08 UTC (rev 16036)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Hbm2HbmXmlTest.java 2009-02-26 07:02:45 UTC (rev 16037)
@@ -141,6 +141,12 @@
Node node = (Node) list.get(0);
assertEquals(node.getText(),"Basic");
+ xpath = DocumentHelper.createXPath("//hibernate-mapping/class/id/meta");
+ list = xpath.selectNodes(document);
+ assertEquals("Expected to get one meta element", 1, list.size());
+ node = (Node) list.get(0);
+ assertEquals(node.getText(),"basicId");
+
xpath = DocumentHelper.createXPath("//hibernate-mapping/class/property/meta");
list = xpath.selectNodes(document);
assertEquals("Expected to get one meta element", 1, list.size());
@@ -153,7 +159,6 @@
node = (Node) list.get(0);
assertEquals(node.getText(),"anotherone");
-
}
public void testCollectionAttributes() throws DocumentException {
@@ -170,23 +175,7 @@
Element node = (Element) list.get(0);
assertEquals("delete, update", node.attributeValue("cascade"));
-
-
-// xpath = DocumentHelper.createXPath("//hibernate-mapping/class/property/meta");
-// list = xpath.selectNodes(document);
-// assertEquals("Expected to get one meta element", 1, list.size());
-// node = (Node) list.get(0);
-// assertEquals(node.getText(),"description");
-//
-// xpath = DocumentHelper.createXPath("//hibernate-mapping/class/set/meta");
-// list = xpath.selectNodes(document);
-// assertEquals("Expected to get one meta element", 1, list.size());
-// node = (Node) list.get(0);
-// assertEquals(node.getText(),"anotherone");
-
-
}
-
public void testComments() throws DocumentException {
File outputXml = new File(getOutputDir().getAbsolutePath() + "/org/hibernate/tool/hbm2x/hbm2hbmxml/ClassFullAttribute.hbm.xml");
@@ -207,8 +196,6 @@
assertEquals("Expected to get one comment element", 1, list.size());
node = (Node) list.get(0);
assertEquals(node.getText(),"columnd comment");
-
-
}
public void testNoComments() throws DocumentException {
@@ -233,7 +220,7 @@
/**
* Special test for external Global settings were generated.
- * Test Access and Cacade setting but they are default values
+ * Test Access and Cascade setting but they are default values
* so they should not appear.
*/
public void testGlobalSettingsGeneratedAccessAndCascadeDefault() throws Exception {
@@ -566,14 +553,6 @@
assertEquals("Unexpected class lock-mode for return element", "none", genAtt.getStringValue() );
}
-
-
- private SAXReader getSAXReader() {
- SAXReader xmlReader = new SAXReader();
- xmlReader.setEntityResolver(new DTDEntityResolver() );
- xmlReader.setValidation(true);
- return xmlReader;
- }
protected String getBaseForMappings() {
return "org/hibernate/tool/hbm2x/hbm2hbmxml/";
Added: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/IdBagTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/IdBagTest.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/IdBagTest.java 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,126 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.hibernate.tool.hbm2x.hbm2hbmxml;
+
+import java.io.File;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.DocumentHelper;
+import org.dom4j.Element;
+import org.dom4j.XPath;
+import org.dom4j.io.SAXReader;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.tool.NonReflectiveTestCase;
+import org.hibernate.tool.hbm2x.Exporter;
+import org.hibernate.tool.hbm2x.HibernateMappingExporter;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class IdBagTest extends NonReflectiveTestCase {
+
+ private Exporter hbmexporter;
+
+ public IdBagTest(String name) {
+ super( name, "cfg2hbmoutput" );
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ hbmexporter = new HibernateMappingExporter(getCfg(), getOutputDir() );
+ hbmexporter.start();
+ }
+
+ public void testAllFilesExistence() {
+
+ assertFalse(new File(getOutputDir().getAbsolutePath() + "/GeneralHbmSettings.hbm.xml").exists() );
+ assertFileAndExists(new File(getOutputDir().getAbsolutePath() + "/org/hibernate/tool/hbm2x/hbm2hbmxml/User2.hbm.xml") );
+ assertFileAndExists(new File(getOutputDir().getAbsolutePath() + "/org/hibernate/tool/hbm2x/hbm2hbmxml/Group2.hbm.xml") );
+ }
+
+ public void testArtifactCollection() {
+
+ assertEquals(2,hbmexporter.getArtifactCollector().getFileCount("hbm.xml"));
+
+ }
+
+ public void testReadable() {
+ Configuration cfg = new Configuration();
+
+ cfg.addFile(new File(getOutputDir(), getBaseForMappings() + "User2.hbm.xml"));
+ cfg.addFile(new File(getOutputDir(), getBaseForMappings() + "Group2.hbm.xml"));
+
+ cfg.buildMappings();
+
+ }
+
+ public void testIdBagAttributes() {
+ File outputXml = new File(getOutputDir(), getBaseForMappings() + "User2.hbm.xml");
+ assertFileAndExists(outputXml);
+
+ SAXReader xmlReader = this.getSAXReader();
+
+ Document document;
+ try {
+ document = xmlReader.read(outputXml);
+ XPath xpath = DocumentHelper.createXPath("//hibernate-mapping/class/idbag");
+ List list = xpath.selectNodes(document);
+ assertEquals("Expected to get one idbag element", 1, list.size());
+ Element node = (Element) list.get(0);
+ assertEquals(node.attribute( "table" ).getText(),"`UserGroups`");
+ assertEquals(node.attribute( "name" ).getText(),"groups");
+ assertEquals(node.attribute( "lazy" ).getText(),"false");
+ } catch (DocumentException e) {
+ fail("Can't parse file " + outputXml.getAbsolutePath());
+ }
+ }
+
+ public void testCollectionId() throws DocumentException {
+ File outputXml = new File(getOutputDir(), getBaseForMappings() + "User2.hbm.xml");
+ SAXReader xmlReader = this.getSAXReader();
+
+ Document document = xmlReader.read(outputXml);
+
+ XPath xpath = DocumentHelper.createXPath("//hibernate-mapping/class/idbag/collection-id");
+ List list = xpath.selectNodes(document);
+ assertEquals("Expected to get one collection-id element", 1, list.size());
+ Element node = (Element) list.get(0);
+ assertEquals(node.attribute( "column" ).getText(),"userGroupId");
+ assertEquals(node.attribute( "type" ).getText(),"long");
+
+ list = node.elements("generator");
+ assertEquals("Expected to get one generator element", 1, list.size());
+ node = (Element) list.get(0);
+ assertEquals(node.attribute( "class" ).getText(),"increment");
+ }
+
+ protected String getBaseForMappings() {
+ return "org/hibernate/tool/hbm2x/hbm2hbmxml/";
+ }
+
+ protected String[] getMappings() {
+ return new String[] {
+ "UserGroup2.hbm.xml"
+ };
+ }
+
+ public static Test suite() {
+ return new TestSuite(IdBagTest.class);
+ }
+
+}
Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/InheritanceTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/InheritanceTest.java 2009-02-26 05:42:08 UTC (rev 16036)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/InheritanceTest.java 2009-02-26 07:02:45 UTC (rev 16037)
@@ -1,83 +1,103 @@
-//$Id$
-
-/*
- * Tests for generating the HBM documents from the Configuration data structure.
- * The generated XML document will be validated and queried to make sure the
- * basic structure is correct in each test.
- */
-package org.hibernate.tool.hbm2x.hbm2hbmxml;
-
-import java.io.File;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-import org.hibernate.cfg.Configuration;
-import org.hibernate.tool.NonReflectiveTestCase;
-import org.hibernate.tool.hbm2x.Exporter;
-import org.hibernate.tool.hbm2x.HibernateMappingExporter;
-
-/**
- * this test should be fixed to have a proper model. currently a mix of subclass/joinedsubclass is in play.
- * @author max
- *
- */
-public class InheritanceTest extends NonReflectiveTestCase {
-
- private Exporter hbmexporter;
-
- public InheritanceTest(String name) {
- super( name );
- }
-
- protected void setUp() throws Exception {
- super.setUp();
-
- hbmexporter = new HibernateMappingExporter(getCfg(), getOutputDir() );
- hbmexporter.start();
- }
-
- public void testAllFilesExistence() {
-
- assertFalse(new File(getOutputDir().getAbsolutePath() + "/GeneralHbmSettings.hbm.xml").exists() );
- assertFileAndExists(new File(getOutputDir().getAbsolutePath() + "/org/hibernate/tool/hbm2x/hbm2hbmxml/Human.hbm.xml") );
- assertFileAndExists(new File(getOutputDir().getAbsolutePath() + "/org/hibernate/tool/hbm2x/hbm2hbmxml/Alien.hbm.xml") );
- assertFileAndExists(new File(getOutputDir().getAbsolutePath() + "/org/hibernate/tool/hbm2x/hbm2hbmxml/Animal.hbm.xml") );
- }
-
- public void testArtifactCollection() {
-
- assertEquals(3,hbmexporter.getArtifactCollector().getFileCount("hbm.xml"));
-
- }
-
- public void testReadable() {
- Configuration cfg = new Configuration();
-
- cfg.addFile(new File(getOutputDir(), getBaseForMappings() + "Alien.hbm.xml"));
- cfg.addFile(new File(getOutputDir(), getBaseForMappings() + "Human.hbm.xml"));
- cfg.addFile(new File(getOutputDir(), getBaseForMappings() + "Animal.hbm.xml"));
-
- cfg.buildMappings();
-
- }
-
-
-
-
- protected String getBaseForMappings() {
- return "org/hibernate/tool/hbm2x/hbm2hbmxml/";
- }
-
- protected String[] getMappings() {
- return new String[] {
- "Aliens.hbm.xml"
- };
- }
-
- public static Test suite() {
- return new TestSuite(InheritanceTest.class);
- }
-
-
-}
+//$Id$
+
+/*
+ * Tests for generating the HBM documents from the Configuration data structure.
+ * The generated XML document will be validated and queried to make sure the
+ * basic structure is correct in each test.
+ */
+package org.hibernate.tool.hbm2x.hbm2hbmxml;
+
+import java.io.File;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.DocumentHelper;
+import org.dom4j.XPath;
+import org.dom4j.io.SAXReader;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.tool.NonReflectiveTestCase;
+import org.hibernate.tool.hbm2x.Exporter;
+import org.hibernate.tool.hbm2x.HibernateMappingExporter;
+
+/**
+ * this test should be fixed to have a proper model. currently a mix of subclass/joinedsubclass is in play.
+ * @author max
+ *
+ */
+public class InheritanceTest extends NonReflectiveTestCase {
+
+ private Exporter hbmexporter;
+
+ public InheritanceTest(String name) {
+ super( name );
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ hbmexporter = new HibernateMappingExporter(getCfg(), getOutputDir() );
+ hbmexporter.start();
+ }
+
+ public void testAllFilesExistence() {
+
+ assertFalse(new File(getOutputDir().getAbsolutePath() + "/GeneralHbmSettings.hbm.xml").exists() );
+ assertFileAndExists(new File(getOutputDir().getAbsolutePath() + "/org/hibernate/tool/hbm2x/hbm2hbmxml/Human.hbm.xml") );
+ assertFileAndExists(new File(getOutputDir().getAbsolutePath() + "/org/hibernate/tool/hbm2x/hbm2hbmxml/Alien.hbm.xml") );
+ assertFileAndExists(new File(getOutputDir().getAbsolutePath() + "/org/hibernate/tool/hbm2x/hbm2hbmxml/Animal.hbm.xml") );
+ }
+
+ public void testArtifactCollection() {
+
+ assertEquals(3,hbmexporter.getArtifactCollector().getFileCount("hbm.xml"));
+
+ }
+
+ public void testReadable() {
+ Configuration cfg = new Configuration();
+
+ cfg.addFile(new File(getOutputDir(), getBaseForMappings() + "Alien.hbm.xml"));
+ cfg.addFile(new File(getOutputDir(), getBaseForMappings() + "Human.hbm.xml"));
+ cfg.addFile(new File(getOutputDir(), getBaseForMappings() + "Animal.hbm.xml"));
+
+ cfg.buildMappings();
+ }
+
+ public void testComment() {
+ File outputXml = new File(getOutputDir().getAbsolutePath() + "/org/hibernate/tool/hbm2x/hbm2hbmxml/Alien.hbm.xml");
+ assertFileAndExists(outputXml);
+
+ SAXReader xmlReader = this.getSAXReader();
+
+ Document document;
+ try {
+ document = xmlReader.read(outputXml);
+ XPath xpath = DocumentHelper.createXPath("//hibernate-mapping/joined-subclass/comment");
+ List list = xpath.selectNodes(document);
+ assertEquals("Expected to get one comment element", 1, list.size());
+ } catch (DocumentException e) {
+ fail("Can't parse file " + outputXml.getAbsolutePath());
+ }
+ }
+
+
+ protected String getBaseForMappings() {
+ return "org/hibernate/tool/hbm2x/hbm2hbmxml/";
+ }
+
+ protected String[] getMappings() {
+ return new String[] {
+ "Aliens.hbm.xml"
+ };
+ }
+
+ public static Test suite() {
+ return new TestSuite(InheritanceTest.class);
+ }
+
+
+}
Added: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/IntegerPropertyValue.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/IntegerPropertyValue.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/IntegerPropertyValue.java 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,38 @@
+package org.hibernate.tool.hbm2x.hbm2hbmxml;
+
+/**
+ * todo: describe IntegerPropertyValue
+ *
+ * @author Steve Ebersole
+ */
+public class IntegerPropertyValue implements PropertyValue {
+ private Long id;
+ private int value;
+
+ public IntegerPropertyValue() {
+ }
+
+ public IntegerPropertyValue(int value) {
+ this.value = value;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public int getValue() {
+ return value;
+ }
+
+ public void setValue(int value) {
+ this.value = value;
+ }
+
+ public String asString() {
+ return Integer.toString( value );
+ }
+}
Added: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/ListArrayTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/ListArrayTest.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/ListArrayTest.java 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,147 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.hibernate.tool.hbm2x.hbm2hbmxml;
+
+import java.io.File;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.DocumentHelper;
+import org.dom4j.Element;
+import org.dom4j.XPath;
+import org.dom4j.io.SAXReader;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.tool.NonReflectiveTestCase;
+import org.hibernate.tool.hbm2x.Exporter;
+import org.hibernate.tool.hbm2x.HibernateMappingExporter;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class ListArrayTest extends NonReflectiveTestCase {
+
+ private String mappingFile = "Glarch.hbm.xml";
+
+ private Exporter hbmexporter;
+
+ /**
+ * @param name
+ */
+ public ListArrayTest(String name) {
+ super(name, "cfg2hbmoutput");
+ }
+
+
+ protected String[] getMappings() {
+ return new String[] {
+ mappingFile
+ };
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ hbmexporter = new HibernateMappingExporter(getCfg(), getOutputDir() );
+ hbmexporter.start();
+ }
+
+ public void testAllFilesExistence() {
+ assertFileAndExists(new File(getOutputDir().getAbsolutePath(), getBaseForMappings() + "Fee.hbm.xml") );
+ assertFileAndExists(new File(getOutputDir().getAbsolutePath(), getBaseForMappings() + "Glarch.hbm.xml") );
+ }
+
+ public void testReadable() {
+ Configuration cfg = new Configuration();
+
+ cfg.addFile(new File(getOutputDir(), getBaseForMappings() + "Fee.hbm.xml"));
+ cfg.addFile(new File(getOutputDir(), getBaseForMappings() + "Glarch.hbm.xml"));
+
+ cfg.buildMappings();
+ }
+
+ public void testListNode() throws DocumentException {
+ File outputXml = new File(getOutputDir(), getBaseForMappings() + "Glarch.hbm.xml");
+ assertFileAndExists(outputXml);
+
+ SAXReader xmlReader = getSAXReader();
+
+ Document document = xmlReader.read(outputXml);
+
+ XPath xpath = DocumentHelper.createXPath("//hibernate-mapping/class/list");
+ List list = xpath.selectNodes(document);
+ assertEquals("Expected to get two list element", 2, list.size());
+ Element node = (Element) list.get(1); //second list
+ assertEquals(node.attribute( "name" ).getText(),"fooComponents");
+ assertEquals(node.attribute( "lazy" ).getText(),"true");
+ assertEquals(node.attribute( "cascade" ).getText(),"all");
+
+ list = node.elements("index");
+ assertEquals("Expected to get one index element", 1, list.size());
+ node = (Element) list.get(0);
+ assertEquals(node.attribute( "column" ).getText(),"tha_indecks");
+
+ node = node.getParent();//list
+ list = node.elements("composite-element");
+ assertEquals("Expected to get one composite-element element", 1, list.size());
+ node = (Element) list.get(0);
+ assertEquals("Expected to get two property element", 2, node.elements("property").size());
+
+ node = node.element("many-to-one");
+ assertEquals(node.attribute( "name" ).getText(),"fee");
+ assertEquals(node.attribute( "cascade" ).getText(),"all");
+ //TODO :assertEquals(node.attribute( "outer-join" ).getText(),"true");
+
+ node = node.getParent();//composite-element
+ node = node.element("nested-composite-element");
+ assertEquals(node.attribute( "name" ).getText(),"subcomponent");
+ assertEquals(node.attribute( "class" ).getText(),"org.hibernate.tool.hbm2x.hbm2hbmxml.FooComponent");
+ }
+
+ public void testArrayNode() throws DocumentException {
+ File outputXml = new File(getOutputDir(), getBaseForMappings() + "Glarch.hbm.xml");
+ assertFileAndExists(outputXml);
+
+ SAXReader xmlReader = getSAXReader();
+
+ Document document = xmlReader.read(outputXml);
+
+ XPath xpath = DocumentHelper.createXPath("//hibernate-mapping/class/array");
+ List list = xpath.selectNodes(document);
+ assertEquals("Expected to get one array element", 1, list.size());
+ Element node = (Element) list.get(0);
+ assertEquals(node.attribute( "name" ).getText(),"proxyArray");
+ assertEquals(node.attribute( "element-class" ).getText(),"org.hibernate.tool.hbm2x.hbm2hbmxml.GlarchProxy");
+
+ list = node.elements("index");
+ assertEquals("Expected to get one index element", 1, list.size());
+ node = (Element) list.get(0);
+ assertEquals(node.attribute( "column" ).getText(),"array_indecks");
+
+ node = node.getParent();//array
+ list = node.elements("one-to-many");
+ assertEquals("Expected to get one 'one-to-many' element", 1, list.size());
+
+ }
+
+ protected String getBaseForMappings() {
+ return "org/hibernate/tool/hbm2x/hbm2hbmxml/";
+ }
+
+ public static Test suite() {
+ return new TestSuite(ListArrayTest.class);
+ }
+
+}
Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/ManyToManyTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/ManyToManyTest.java 2009-02-26 05:42:08 UTC (rev 16036)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/ManyToManyTest.java 2009-02-26 07:02:45 UTC (rev 16037)
@@ -1,8 +1,8 @@
//$Id$
-/*
+/*
* Tests for generating the HBM documents from the Configuration data structure.
- * The generated XML document will be validated and queried to make sure the
+ * The generated XML document will be validated and queried to make sure the
* basic structure is correct in each test.
*/
package org.hibernate.tool.hbm2x.hbm2hbmxml;
@@ -35,76 +35,118 @@
protected void setUp() throws Exception {
super.setUp();
-
+
hbmexporter = new HibernateMappingExporter(getCfg(), getOutputDir() );
- hbmexporter.start();
+ hbmexporter.start();
}
-
+
public void testAllFilesExistence() {
assertFalse(new File(getOutputDir().getAbsolutePath() + "/GeneralHbmSettings.hbm.xml").exists() );
assertFileAndExists(new File(getOutputDir().getAbsolutePath() + "/org/hibernate/tool/hbm2x/hbm2hbmxml/User.hbm.xml") );
- assertFileAndExists(new File(getOutputDir().getAbsolutePath() + "/org/hibernate/tool/hbm2x/hbm2hbmxml/Group.hbm.xml") );
+ assertFileAndExists(new File(getOutputDir().getAbsolutePath() + "/org/hibernate/tool/hbm2x/hbm2hbmxml/Group.hbm.xml") );
}
-
+
public void testArtifactCollection() {
-
+
assertEquals(2,hbmexporter.getArtifactCollector().getFileCount("hbm.xml"));
-
+
}
-
+
public void testReadable() {
Configuration cfg = new Configuration();
-
+
cfg.addFile(new File(getOutputDir(), getBaseForMappings() + "User.hbm.xml"));
cfg.addFile(new File(getOutputDir(), getBaseForMappings() + "Group.hbm.xml"));
-
+
cfg.buildMappings();
-
+
}
-
+
public void testManyToMany() throws DocumentException {
File outputXml = new File(getOutputDir(), getBaseForMappings() + "User.hbm.xml");
assertFileAndExists(outputXml);
SAXReader xmlReader = this.getSAXReader();
-
- Document document = xmlReader.read(outputXml);
-
+
+ Document document = xmlReader.read(outputXml);
+
XPath xpath = DocumentHelper.createXPath("//hibernate-mapping/class/set/many-to-many");
List list = xpath.selectNodes(document);
assertEquals("Expected to get one many-to-many element", 1, list.size());
Element node = (Element) list.get(0);
assertEquals(node.attribute( "entity-name" ).getText(),"org.hibernate.tool.hbm2x.hbm2hbmxml.Group");
-
-
+
+
xpath = DocumentHelper.createXPath("//hibernate-mapping/class/set");
list = xpath.selectNodes(document);
assertEquals("Expected to get one set element", 1, list.size());
node = (Element) list.get(0);
assertEquals(node.attribute( "table" ).getText(),"UserGroup");
-
-
+
+
}
-
-
- private SAXReader getSAXReader() {
- SAXReader xmlReader = new SAXReader();
- xmlReader.setEntityResolver(new DTDEntityResolver() );
- xmlReader.setValidation(true);
- return xmlReader;
- }
-
+
+ public void testCompositeId() throws DocumentException {
+ File outputXml = new File(getOutputDir(), getBaseForMappings() + "Group.hbm.xml");
+ SAXReader xmlReader = this.getSAXReader();
+
+ Document document = xmlReader.read(outputXml);
+
+ XPath xpath = DocumentHelper.createXPath("//hibernate-mapping/class");
+ List list = xpath.selectNodes(document);
+ assertEquals("Expected to get one class element", 1, list.size());
+ Element node = (Element) list.get(0);
+
+ assertEquals(node.attribute( "table" ).getText(),"`Group`");
+
+ xpath = DocumentHelper.createXPath("//hibernate-mapping/class/composite-id");
+ list = xpath.selectNodes(document);
+ assertEquals("Expected to get one composite-id element", 1, list.size());
+
+
+ xpath = DocumentHelper.createXPath("//hibernate-mapping/class/composite-id/key-property");
+ list = xpath.selectNodes(document);
+ assertEquals("Expected to get two key-property elements", 2, list.size());
+ node = (Element) list.get(0);
+ assertEquals(node.attribute( "name" ).getText(),"name");
+ node = (Element) list.get(1);
+ assertEquals(node.attribute( "name" ).getText(),"org");
+ }
+
+ public void testSetAttributes() {
+ File outputXml = new File(getOutputDir(), getBaseForMappings() + "Group.hbm.xml");
+ assertFileAndExists(outputXml);
+
+ SAXReader xmlReader = this.getSAXReader();
+
+
+ Document document;
+ try {
+ document = xmlReader.read(outputXml);
+ XPath xpath = DocumentHelper.createXPath("//hibernate-mapping/class/set");
+ List list = xpath.selectNodes(document);
+ assertEquals("Expected to get one set element", 1, list.size());
+ Element node = (Element) list.get(0);
+ assertEquals(node.attribute( "table" ).getText(),"UserGroup");
+ assertEquals(node.attribute( "name" ).getText(),"users");
+ assertEquals(node.attribute( "inverse" ).getText(),"true");
+ assertEquals(node.attribute( "lazy" ).getText(),"extra");
+ } catch (DocumentException e) {
+ fail("Can't parse file " + outputXml.getAbsolutePath());
+ }
+ }
+
protected String getBaseForMappings() {
return "org/hibernate/tool/hbm2x/hbm2hbmxml/";
}
-
+
protected String[] getMappings() {
- return new String[] {
- "UserGroup.hbm.xml"
+ return new String[] {
+ "UserGroup.hbm.xml"
};
}
-
+
public static Test suite() {
return new TestSuite(ManyToManyTest.class);
}
Added: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/MapAndAnyTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/MapAndAnyTest.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/MapAndAnyTest.java 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,192 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.hibernate.tool.hbm2x.hbm2hbmxml;
+
+import java.io.File;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.DocumentHelper;
+import org.dom4j.Element;
+import org.dom4j.XPath;
+import org.dom4j.io.SAXReader;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.mapping.Any;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.mapping.Property;
+import org.hibernate.tool.NonReflectiveTestCase;
+import org.hibernate.tool.hbm2x.Exporter;
+import org.hibernate.tool.hbm2x.HibernateMappingExporter;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class MapAndAnyTest extends NonReflectiveTestCase {
+
+ private String mappingFile = "Properties.hbm.xml";
+
+ private Exporter hbmexporter;
+
+ /**
+ * @param name
+ */
+ public MapAndAnyTest(String name) {
+ super(name, "cfg2hbmoutput");
+ }
+
+
+ protected String[] getMappings() {
+ return new String[] {
+ mappingFile
+ };
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ hbmexporter = new HibernateMappingExporter(getCfg(), getOutputDir() );
+ hbmexporter.start();
+ }
+
+ public void testAllFilesExistence() {
+ assertFileAndExists(new File(getOutputDir().getAbsolutePath(), getBaseForMappings() + "ComplexPropertyValue.hbm.xml") );
+ assertFileAndExists(new File(getOutputDir().getAbsolutePath(), getBaseForMappings() + "IntegerPropertyValue.hbm.xml") );
+ assertFileAndExists(new File(getOutputDir().getAbsolutePath(), getBaseForMappings() + "StringPropertyValue.hbm.xml") );
+ assertFileAndExists(new File(getOutputDir().getAbsolutePath(), getBaseForMappings() + "PropertySet.hbm.xml") );
+ }
+
+ public void testReadable() {
+ Configuration cfg = new Configuration();
+
+ cfg.addFile(new File(getOutputDir(), getBaseForMappings() + "ComplexPropertyValue.hbm.xml"));
+ cfg.addFile(new File(getOutputDir(), getBaseForMappings() + "IntegerPropertyValue.hbm.xml"));
+ cfg.addFile(new File(getOutputDir(), getBaseForMappings() + "StringPropertyValue.hbm.xml"));
+ cfg.addFile(new File(getOutputDir(), getBaseForMappings() + "PropertySet.hbm.xml"));
+
+ cfg.buildMappings();
+ }
+
+ public void testAnyNode() throws DocumentException {
+ File outputXml = new File(getOutputDir(), getBaseForMappings() + "PropertySet.hbm.xml");
+ assertFileAndExists(outputXml);
+
+ SAXReader xmlReader = getSAXReader();
+
+ Document document = xmlReader.read(outputXml);
+
+ XPath xpath = DocumentHelper.createXPath("//hibernate-mapping/class/any");
+ List list = xpath.selectNodes(document);
+ assertEquals("Expected to get one any element", 1, list.size());
+ Element node = (Element) list.get(0);
+ assertEquals(node.attribute( "name" ).getText(),"someSpecificProperty");
+ assertEquals(node.attribute( "id-type" ).getText(),"long");
+ assertEquals(node.attribute( "meta-type" ).getText(),"string");
+ assertEquals(node.attribute( "cascade" ).getText(), "all");
+
+ list = node.elements("column");
+ assertEquals("Expected to get two column elements", 2, list.size());
+
+ list = node.elements("meta-value");
+ assertEquals("Expected to get three meta-value elements", 3, list.size());
+ node = (Element) list.get(0);
+ String className = node.attribute( "class" ).getText();
+ assertNotNull("Expected class attribute in meta-value", className);
+ if (className.indexOf("IntegerPropertyValue") > 0){
+ assertEquals(node.attribute( "value" ).getText(),"I");
+ } else if (className.indexOf("StringPropertyValue") > 0){
+ assertEquals(node.attribute( "value" ).getText(),"S");
+ } else {
+ assertTrue(className.indexOf("ComplexPropertyValue") > 0);
+ assertEquals(node.attribute( "value" ).getText(),"C");
+ }
+ }
+
+ public void testMetaValueRead() throws Exception{
+ String oldMappingFile = mappingFile;
+ mappingFile = "Person2.hbm.xml";
+
+ super.setUp();//rebuld cfg
+
+ Configuration config = getCfg();
+ PersistentClass pc = config.getClassMapping("org.hibernate.tool.hbm2x.hbm2hbmxml.Person2");
+ assertNotNull(pc);
+ Property prop = pc.getProperty("data");
+ assertNotNull(prop);
+ assertTrue(prop.getValue() instanceof Any);
+ Any any = (Any) prop.getValue();
+ assertTrue("Expected to get one meta-value element", any.getMetaValues() != null);
+ assertEquals("Expected to get one meta-value element", 1, any.getMetaValues().size());
+ mappingFile = oldMappingFile;
+ }
+
+ public void testMapManyToAny() throws DocumentException {
+ File outputXml = new File(getOutputDir(), getBaseForMappings() + "PropertySet.hbm.xml");
+ assertFileAndExists(outputXml);
+
+ SAXReader xmlReader = getSAXReader();
+
+ Document document = xmlReader.read(outputXml);
+
+ XPath xpath = DocumentHelper.createXPath("//hibernate-mapping/class/map");
+ List list = xpath.selectNodes(document);
+ assertEquals("Expected to get one any element", 1, list.size());
+ Element node = (Element) list.get(0);
+ assertEquals(node.attribute( "name" ).getText(),"generalProperties");
+ assertEquals(node.attribute( "table" ).getText(),"T_GEN_PROPS");
+ assertEquals(node.attribute( "lazy" ).getText(),"true");
+ assertEquals(node.attribute( "cascade" ).getText(), "all");
+
+
+ list = node.elements("key");
+ assertEquals("Expected to get one key element", 1, list.size());
+
+ list = node.elements("map-key");
+ assertEquals("Expected to get one map-key element", 1, list.size());
+ node = (Element) list.get(0);
+ assertEquals(node.attribute( "type" ).getText(),"string");
+ list = node.elements("column");
+ assertEquals("Expected to get one column element", 1, list.size());
+ node = node.getParent();//map
+
+ list = node.elements("many-to-any");
+ assertEquals("Expected to get one many-to-any element", 1, list.size());
+ node = (Element) list.get(0);
+
+ list = node.elements("column");
+ assertEquals("Expected to get two column elements", 2, list.size());
+
+ list = node.elements("meta-value");
+ assertEquals("Expected to get two meta-value elements", 2, list.size());
+ node = (Element) list.get(0);
+ String className = node.attribute( "class" ).getText();
+ assertNotNull("Expected class attribute in meta-value", className);
+ if (className.indexOf("IntegerPropertyValue") > 0){
+ assertEquals(node.attribute( "value" ).getText(),"I");
+ } else {
+ assertTrue(className.indexOf("StringPropertyValue") > 0);
+ assertEquals(node.attribute( "value" ).getText(),"S");
+ }
+ }
+
+ protected String getBaseForMappings() {
+ return "org/hibernate/tool/hbm2x/hbm2hbmxml/";
+ }
+
+ public static Test suite() {
+ return new TestSuite(MapAndAnyTest.class);
+ }
+
+}
Added: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Named.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Named.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Named.java 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,13 @@
+//$Id$
+package org.hibernate.tool.hbm2x.hbm2hbmxml;
+
+
+public interface Named {
+ public String getName();
+}
+
+
+
+
+
+
Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/OneToOneTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/OneToOneTest.java 2009-02-26 05:42:08 UTC (rev 16036)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/OneToOneTest.java 2009-02-26 07:02:45 UTC (rev 16037)
@@ -1,125 +1,117 @@
-//$Id$
-
-/*
- * Tests for generating the HBM documents from the Configuration data structure.
- * The generated XML document will be validated and queried to make sure the
- * basic structure is correct in each test.
- */
-package org.hibernate.tool.hbm2x.hbm2hbmxml;
-
-import java.io.File;
-import java.util.List;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-import org.dom4j.Document;
-import org.dom4j.DocumentException;
-import org.dom4j.DocumentHelper;
-import org.dom4j.Element;
-import org.dom4j.XPath;
-import org.dom4j.io.SAXReader;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.cfg.Environment;
-import org.hibernate.tool.NonReflectiveTestCase;
-import org.hibernate.tool.hbm2ddl.SchemaValidator;
-import org.hibernate.tool.hbm2x.Exporter;
-import org.hibernate.tool.hbm2x.HibernateMappingExporter;
-import org.hibernate.util.DTDEntityResolver;
-
-
-
-public class OneToOneTest extends NonReflectiveTestCase {
-
- private Exporter hbmexporter;
-
- public OneToOneTest(String name) {
- super( name );
- }
-
- protected void setUp() throws Exception {
- super.setUp();
-
- hbmexporter = new HibernateMappingExporter(getCfg(), getOutputDir() );
- hbmexporter.start();
- }
-
- public void testAllFilesExistence() {
-
- assertFalse(new File(getOutputDir().getAbsolutePath() + "/GeneralHbmSettings.hbm.xml").exists() );
- assertFileAndExists(new File(getOutputDir().getAbsolutePath() + "/org/hibernate/tool/hbm2x/hbm2hbmxml/Person.hbm.xml") );
- assertFileAndExists(new File(getOutputDir().getAbsolutePath() + "/org/hibernate/tool/hbm2x/hbm2hbmxml/Address.hbm.xml") );
- }
-
- public void testArtifactCollection() {
-
- assertEquals(2,hbmexporter.getArtifactCollector().getFileCount("hbm.xml"));
-
- }
-
- public void testReadable() {
- Configuration cfg = new Configuration();
-
- cfg.addFile(new File(getOutputDir(), getBaseForMappings() + "Person.hbm.xml"));
- cfg.addFile(new File(getOutputDir(), getBaseForMappings() + "Address.hbm.xml"));
-
- cfg.buildMappings();
-
-
- }
-
- public void testOneToOne() throws DocumentException {
- Document document = getXMLDocument(getBaseForMappings() + "Person.hbm.xml");
-
- XPath xpath = DocumentHelper.createXPath("//hibernate-mapping/class/one-to-one");
- List list = xpath.selectNodes(document);
- assertEquals("Expected to get one-to-one element", 1, list.size());
- Element node = (Element) list.get(0);
- assertEquals(node.attribute( "name" ).getText(),"address");
- assertEquals(node.attribute( "constrained" ).getText(),"false");
-
- document = getXMLDocument(getBaseForMappings() + "Address.hbm.xml");
-
- xpath = DocumentHelper.createXPath("//hibernate-mapping/class/one-to-one");
- list = xpath.selectNodes(document);
- assertEquals("Expected to get one set element", 1, list.size());
- node = (Element) list.get(0);
- assertEquals(node.attribute( "name" ).getText(),"person");
- assertEquals(node.attribute( "constrained" ).getText(),"true");
-
-
- }
-
- private Document getXMLDocument(String location) throws DocumentException {
- File outputXml = new File(getOutputDir(), location);
- assertFileAndExists(outputXml);
-
- SAXReader xmlReader = this.getSAXReader();
-
- Document document = xmlReader.read(outputXml);
- return document;
- }
-
-
- private SAXReader getSAXReader() {
- SAXReader xmlReader = new SAXReader();
- xmlReader.setEntityResolver(new DTDEntityResolver() );
- xmlReader.setValidation(true);
- return xmlReader;
- }
-
- protected String getBaseForMappings() {
- return "org/hibernate/tool/hbm2x/hbm2hbmxml/";
- }
-
- protected String[] getMappings() {
- return new String[] {
- "PersonAddressOneToOnePrimaryKey.hbm.xml"
- };
- }
-
- public static Test suite() {
- return new TestSuite(OneToOneTest.class);
- }
-
-}
+//$Id$
+
+/*
+ * Tests for generating the HBM documents from the Configuration data structure.
+ * The generated XML document will be validated and queried to make sure the
+ * basic structure is correct in each test.
+ */
+package org.hibernate.tool.hbm2x.hbm2hbmxml;
+
+import java.io.File;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.DocumentHelper;
+import org.dom4j.Element;
+import org.dom4j.XPath;
+import org.dom4j.io.SAXReader;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.tool.NonReflectiveTestCase;
+import org.hibernate.tool.hbm2ddl.SchemaValidator;
+import org.hibernate.tool.hbm2x.Exporter;
+import org.hibernate.tool.hbm2x.HibernateMappingExporter;
+import org.hibernate.util.DTDEntityResolver;
+
+
+
+public class OneToOneTest extends NonReflectiveTestCase {
+
+ private Exporter hbmexporter;
+
+ public OneToOneTest(String name) {
+ super( name );
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ hbmexporter = new HibernateMappingExporter(getCfg(), getOutputDir() );
+ hbmexporter.start();
+ }
+
+ public void testAllFilesExistence() {
+
+ assertFalse(new File(getOutputDir().getAbsolutePath() + "/GeneralHbmSettings.hbm.xml").exists() );
+ assertFileAndExists(new File(getOutputDir().getAbsolutePath() + "/org/hibernate/tool/hbm2x/hbm2hbmxml/Person.hbm.xml") );
+ assertFileAndExists(new File(getOutputDir().getAbsolutePath() + "/org/hibernate/tool/hbm2x/hbm2hbmxml/Address.hbm.xml") );
+ }
+
+ public void testArtifactCollection() {
+
+ assertEquals(2,hbmexporter.getArtifactCollector().getFileCount("hbm.xml"));
+
+ }
+
+ public void testReadable() {
+ Configuration cfg = new Configuration();
+
+ cfg.addFile(new File(getOutputDir(), getBaseForMappings() + "Person.hbm.xml"));
+ cfg.addFile(new File(getOutputDir(), getBaseForMappings() + "Address.hbm.xml"));
+
+ cfg.buildMappings();
+
+
+ }
+
+ public void testOneToOne() throws DocumentException {
+ Document document = getXMLDocument(getBaseForMappings() + "Person.hbm.xml");
+
+ XPath xpath = DocumentHelper.createXPath("//hibernate-mapping/class/one-to-one");
+ List list = xpath.selectNodes(document);
+ assertEquals("Expected to get one-to-one element", 1, list.size());
+ Element node = (Element) list.get(0);
+ assertEquals(node.attribute( "name" ).getText(),"address");
+ assertEquals(node.attribute( "constrained" ).getText(),"false");
+
+ document = getXMLDocument(getBaseForMappings() + "Address.hbm.xml");
+
+ xpath = DocumentHelper.createXPath("//hibernate-mapping/class/one-to-one");
+ list = xpath.selectNodes(document);
+ assertEquals("Expected to get one set element", 1, list.size());
+ node = (Element) list.get(0);
+ assertEquals(node.attribute( "name" ).getText(),"person");
+ assertEquals(node.attribute( "constrained" ).getText(),"true");
+
+
+ }
+
+ private Document getXMLDocument(String location) throws DocumentException {
+ File outputXml = new File(getOutputDir(), location);
+ assertFileAndExists(outputXml);
+
+ SAXReader xmlReader = this.getSAXReader();
+
+ Document document = xmlReader.read(outputXml);
+ return document;
+ }
+
+ protected String getBaseForMappings() {
+ return "org/hibernate/tool/hbm2x/hbm2hbmxml/";
+ }
+
+ protected String[] getMappings() {
+ return new String[] {
+ "PersonAddressOneToOnePrimaryKey.hbm.xml"
+ };
+ }
+
+ public static Test suite() {
+ return new TestSuite(OneToOneTest.class);
+ }
+
+}
Added: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Person2.hbm.xml
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Person2.hbm.xml (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Person2.hbm.xml 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="org.hibernate.tool.hbm2x.hbm2hbmxml">
+
+ <class name="Person2" table="T_ANY_PERSON">
+ <id name="id" column="ID_">
+ <generator class="increment" />
+ </id>
+ <property name="name" />
+ <any name="data" id-type="long" cascade="none" meta-type="string">
+ <meta-value value="A" class="Address2"/>
+ <column name="DATATYPE_"/>
+ <column name="DATAID_"/>
+ </any>
+ </class>
+
+ <class name="Address2" table="T_ANY_ADDRESS">
+ <id name="id" column="ID_">
+ <generator class="increment" />
+ </id>
+ <set name="lines" table="LINE">
+ <key column="ADDRESS" />
+ <element type="string" />
+ </set>
+ </class>
+
+</hibernate-mapping>
Added: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Person2.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Person2.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Person2.java 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,37 @@
+package org.hibernate.tool.hbm2x.hbm2hbmxml;
+
+/**
+ * todo: describe Person
+ *
+ * @author Steve Ebersole
+ */
+public class Person2 {
+ private Long id;
+ private String name;
+ private Object data;
+
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Object getData() {
+ return data;
+ }
+
+ public void setData(Object data) {
+ this.data = data;
+ }
+}
Added: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Properties.hbm.xml
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Properties.hbm.xml (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Properties.hbm.xml 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,56 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="org.hibernate.tool.hbm2x.hbm2hbmxml">
+
+ <class name="PropertySet" table="T_PROP_SET">
+ <id name="id" column="ID" type="long">
+ <generator class="increment"/>
+ </id>
+ <property name="name" column="NAME" type="string"/>
+ <any name="someSpecificProperty" id-type="long" meta-type="string" cascade="all">
+ <meta-value value="I" class="IntegerPropertyValue"/>
+ <meta-value value="S" class="StringPropertyValue"/>
+ <meta-value value="C" class="ComplexPropertyValue" />
+ <column name="S_S_PROP_TYPE"/>
+ <column name="S_S_PROP_ID"/>
+ </any>
+ <map name="generalProperties" table="T_GEN_PROPS" lazy="true" cascade="all">
+ <key column="PROP_SET_ID"/>
+ <map-key type="string" column="GEN_PROP_NAME"/>
+ <many-to-any id-type="long" meta-type="string">
+ <meta-value value="I" class="IntegerPropertyValue"/>
+ <meta-value value="S" class="StringPropertyValue"/>
+ <column name="PROP_TYPE"/>
+ <column name="PROP_ID"/>
+ </many-to-any>
+ </map>
+ </class>
+
+ <class name="StringPropertyValue" table="T_CHAR_PROP">
+ <id name="id" column="ID" type="long">
+ <generator class="increment"/>
+ </id>
+ <property name="value" column="VAL" not-null="true" type="string"/>
+ </class>
+
+ <class name="IntegerPropertyValue" table="T_NUM_PROP">
+ <id name="id" column="ID" type="long">
+ <generator class="increment"/>
+ </id>
+ <property name="value" column="VAL" not-null="true" type="integer"/>
+ </class>
+
+ <class name="ComplexPropertyValue" table="T_COMPLEX_PROP">
+ <id name="id" column="ID" type="long">
+ <generator class="increment"/>
+ </id>
+ <map name="subProperties" table="T_COMPLEX_SUB_PROPS" lazy="true">
+ <key column="PROP_ID" />
+ <map-key type="string" column="SUB_PROP_NAME" />
+ <element type="string" column="SUB_PROP_VAL" />
+ </map>
+ </class>
+</hibernate-mapping>
\ No newline at end of file
Added: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/PropertySet.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/PropertySet.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/PropertySet.java 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,55 @@
+package org.hibernate.tool.hbm2x.hbm2hbmxml;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * todo: describe PropertySet
+ *
+ * @author Steve Ebersole
+ */
+public class PropertySet {
+ private Long id;
+ private String name;
+ private PropertyValue someSpecificProperty;
+ private Map generalProperties = new HashMap();
+
+ public PropertySet() {
+ }
+
+ public PropertySet(String name) {
+ this.name = name;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public PropertyValue getSomeSpecificProperty() {
+ return someSpecificProperty;
+ }
+
+ public void setSomeSpecificProperty(PropertyValue someSpecificProperty) {
+ this.someSpecificProperty = someSpecificProperty;
+ }
+
+ public Map getGeneralProperties() {
+ return generalProperties;
+ }
+
+ public void setGeneralProperties(Map generalProperties) {
+ this.generalProperties = generalProperties;
+ }
+}
Added: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/PropertyValue.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/PropertyValue.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/PropertyValue.java 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,10 @@
+package org.hibernate.tool.hbm2x.hbm2hbmxml;
+
+/**
+ * todo: describe PropertyValue
+ *
+ * @author Steve Ebersole
+ */
+public interface PropertyValue {
+ public String asString();
+}
Added: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Search.hbm.xml
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Search.hbm.xml (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Search.hbm.xml 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,21 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<!--
+
+-->
+
+<hibernate-mapping package="org.hibernate.tool.hbm2x.hbm2hbmxml">
+
+ <class name="Search">
+ <id name="searchString"/>
+ <set name="searchResults" sort="natural">
+ <key column="searchString"/>
+ <element column="text" type="string"/>
+ </set>
+ </class>
+
+</hibernate-mapping>
+
Added: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Search.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Search.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Search.java 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,29 @@
+//$Id$
+package org.hibernate.tool.hbm2x.hbm2hbmxml;
+
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+public class Search {
+ private String searchString;
+ private SortedSet searchResults = new TreeSet();
+
+ Search() {}
+
+ public Search(String string) {
+ searchString = string;
+ }
+
+ public SortedSet getSearchResults() {
+ return searchResults;
+ }
+ public void setSearchResults(SortedSet searchResults) {
+ this.searchResults = searchResults;
+ }
+ public String getSearchString() {
+ return searchString;
+ }
+ public void setSearchString(String searchString) {
+ this.searchString = searchString;
+ }
+}
Added: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/SetElementTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/SetElementTest.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/SetElementTest.java 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,129 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.hibernate.tool.hbm2x.hbm2hbmxml;
+
+import java.io.File;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.dom4j.Attribute;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.DocumentHelper;
+import org.dom4j.Element;
+import org.dom4j.XPath;
+import org.dom4j.io.SAXReader;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.tool.NonReflectiveTestCase;
+import org.hibernate.tool.hbm2x.Exporter;
+import org.hibernate.tool.hbm2x.HibernateMappingExporter;
+import org.hibernate.util.DTDEntityResolver;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class SetElementTest extends NonReflectiveTestCase {
+
+ private String mappingFile = "Search.hbm.xml";
+
+ private Exporter hbmexporter;
+
+ /**
+ * @param name
+ */
+ public SetElementTest(String name) {
+ super(name, "cfg2hbmoutput");
+ }
+
+
+ protected String[] getMappings() {
+ return new String[] {
+ mappingFile
+ };
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ hbmexporter = new HibernateMappingExporter(getCfg(), getOutputDir() );
+ hbmexporter.start();
+ }
+
+ public void testAllFilesExistence() {
+ assertFileAndExists(new File(getOutputDir().getAbsolutePath(), getBaseForMappings() + mappingFile) );
+ }
+
+ public void testReadable() {
+ Configuration cfg = new Configuration();
+
+ cfg.addFile(new File(getOutputDir(), getBaseForMappings() + mappingFile));
+
+ cfg.buildMappings();
+ }
+
+ public void testKey() throws DocumentException {
+ File outputXml = new File(getOutputDir(), getBaseForMappings() + mappingFile);
+ assertFileAndExists(outputXml);
+
+ SAXReader xmlReader = getSAXReader();
+
+ Document document = xmlReader.read(outputXml);
+
+ XPath xpath = DocumentHelper.createXPath("//hibernate-mapping/class/set/key");
+ List list = xpath.selectNodes(document);
+ assertEquals("Expected to get one key element", 1, list.size());
+ Element node = (Element) list.get(0);
+ if (node.attribute( "column" ) != null){//implied attribute
+ assertEquals(node.attribute( "column" ).getText(),"searchString");
+ } else {
+ node = node.element("column");
+ assertEquals(node.attribute( "name" ).getText(),"searchString");
+ }
+ }
+
+ public void testSetElement() throws DocumentException {
+ File outputXml = new File(getOutputDir(), getBaseForMappings() + mappingFile);
+ assertFileAndExists(outputXml);
+
+ SAXReader xmlReader = getSAXReader();
+
+ Document document = xmlReader.read(outputXml);
+
+ XPath xpath = DocumentHelper.createXPath("//hibernate-mapping/class/set");
+ List list = xpath.selectNodes(document);
+ assertEquals("Expected to get one set element", 1, list.size());
+ Element node = (Element) list.get(0);
+ assertEquals(node.attribute( "name" ).getText(),"searchResults");
+
+
+ xpath = DocumentHelper.createXPath("//hibernate-mapping/class/set/element");
+ list = xpath.selectNodes(document);
+ assertEquals("Expected to get one element 'element'", 1, list.size());
+ node = (Element) list.get(0);
+ assertEquals(node.attribute( "type" ).getText(), "string");
+ list = node.selectNodes("column");
+ assertEquals("Expected to get one element 'column'", 1, list.size());
+ node = (Element) list.get(0);
+ assertEquals(node.attribute( "name" ).getText(), "text");
+ }
+
+ protected String getBaseForMappings() {
+ return "org/hibernate/tool/hbm2x/hbm2hbmxml/";
+ }
+
+ public static Test suite() {
+ return new TestSuite(SetElementTest.class);
+ }
+
+}
Added: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/StringPropertyValue.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/StringPropertyValue.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/StringPropertyValue.java 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,38 @@
+package org.hibernate.tool.hbm2x.hbm2hbmxml;
+
+/**
+ * todo: describe StringPropertyValue
+ *
+ * @author Steve Ebersole
+ */
+public class StringPropertyValue implements PropertyValue {
+ private Long id;
+ private String value;
+
+ public StringPropertyValue() {
+ }
+
+ public StringPropertyValue(String value) {
+ this.value = value;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public String asString() {
+ return value;
+ }
+}
Added: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Super.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Super.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Super.java 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,15 @@
+package org.hibernate.tool.hbm2x.hbm2hbmxml;
+
+public class Super {
+
+ protected String name;
+
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+
+
+}
Added: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/User2.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/User2.java (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/User2.java 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,33 @@
+package org.hibernate.tool.hbm2x.hbm2hbmxml;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class User2 {
+ private String name;
+ private List groups = new ArrayList();
+
+ User2() {}
+
+ public User2(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+
+ void setName(String name) {
+ this.name = name;
+ }
+
+ public List getGroups() {
+ return groups;
+ }
+
+ void setGroups(List groups) {
+ this.groups = groups;
+ }
+
+}
Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/UserGroup.hbm.xml
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/UserGroup.hbm.xml 2009-02-26 05:42:08 UTC (rev 16036)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/UserGroup.hbm.xml 2009-02-26 07:02:45 UTC (rev 16037)
@@ -1,52 +1,52 @@
-<?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 demonstrates how to map a many-to-many
- association with a shared attribute in the primary keys
- of the associated entities.
-
--->
-
-<hibernate-mapping
- package="org.hibernate.tool.hbm2x.hbm2hbmxml">
-
- <class name="User" table="`User`">
- <composite-id>
- <key-property name="name"/>
- <key-property name="org"/>
- </composite-id>
- <set name="groups" table="UserGroup">
- <key>
- <column name="userName"/>
- <column name="org"/>
- </key>
- <many-to-many class="Group">
- <column name="groupName"/>
- <formula>org</formula>
- </many-to-many>
- </set>
- </class>
-
- <class name="Group" table="`Group`">
- <composite-id>
- <key-property name="name"/>
- <key-property name="org"/>
- </composite-id>
- <property name="description"/>
- <set name="users" table="UserGroup" inverse="true">
- <key>
- <column name="groupName"/>
- <column name="org"/>
- </key>
- <many-to-many class="User">
- <column name="userName"/>
- <formula>org</formula>
- </many-to-many>
- </set>
- </class>
-
-</hibernate-mapping>
+<?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 demonstrates how to map a many-to-many
+ association with a shared attribute in the primary keys
+ of the associated entities.
+
+-->
+
+<hibernate-mapping
+ package="org.hibernate.tool.hbm2x.hbm2hbmxml">
+
+ <class name="User" table="`User`">
+ <composite-id>
+ <key-property name="name"/>
+ <key-property name="org"/>
+ </composite-id>
+ <set name="groups" table="UserGroup" lazy="extra">
+ <key>
+ <column name="userName"/>
+ <column name="org"/>
+ </key>
+ <many-to-many class="Group">
+ <column name="groupName"/>
+ <formula>org</formula>
+ </many-to-many>
+ </set>
+ </class>
+
+ <class name="Group" table="`Group`">
+ <composite-id>
+ <key-property name="name"/>
+ <key-property name="org"/>
+ </composite-id>
+ <property name="description"/>
+ <set name="users" table="UserGroup" inverse="true" lazy="extra">
+ <key>
+ <column name="groupName"/>
+ <column name="org"/>
+ </key>
+ <many-to-many class="User">
+ <column name="userName"/>
+ <formula>org</formula>
+ </many-to-many>
+ </set>
+ </class>
+
+</hibernate-mapping>
Added: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/UserGroup2.hbm.xml
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/UserGroup2.hbm.xml (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/UserGroup2.hbm.xml 2009-02-26 07:02:45 UTC (rev 16037)
@@ -0,0 +1,38 @@
+<?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 demonstrates how to use an idbag to represent
+ a many-to-many association where the association table has
+ a surrogate key.
+
+-->
+
+<hibernate-mapping package="org.hibernate.tool.hbm2x.hbm2hbmxml">
+
+ <class name="User2" table="`Users`">
+ <id name="name"/>
+
+ <idbag name="groups"
+ order-by="groupName asc"
+ table="`UserGroups`" lazy="false">
+ <collection-id column="userGroupId"
+ type="long">
+ <generator class="increment"/>
+ </collection-id>
+ <key column="userName"/>
+ <many-to-many column="groupName"
+ class="Group2"/>
+ </idbag>
+
+ </class>
+
+ <class name="Group2" table="`Groups`">
+ <id name="name"/>
+ </class>
+
+
+</hibernate-mapping>
15 years, 11 months
Hibernate SVN: r16036 - branches/Branch_3_2/HibernateExt/tools.
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2009-02-26 00:42:08 -0500 (Thu, 26 Feb 2009)
New Revision: 16036
Modified:
branches/Branch_3_2/HibernateExt/tools/.classpath
branches/Branch_3_2/HibernateExt/tools/build.xml
Log:
update tag and use exec env instead of specific jdk
Modified: branches/Branch_3_2/HibernateExt/tools/.classpath
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/.classpath 2009-02-26 05:41:33 UTC (rev 16035)
+++ branches/Branch_3_2/HibernateExt/tools/.classpath 2009-02-26 05:42:08 UTC (rev 16036)
@@ -4,7 +4,7 @@
<classpathentry kind="src" path="src/test"/>
<classpathentry kind="src" path="src/testsupport"/>
<classpathentry kind="src" path="src/templates"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="lib" path="lib/freemarker.jar"/>
<classpathentry kind="lib" path="lib/jtidy-r8-20060801.jar"/>
<classpathentry kind="lib" path="lib/org.eclipse.core.runtime_3.2.0.v20060603.jar"/>
Modified: branches/Branch_3_2/HibernateExt/tools/build.xml
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/build.xml 2009-02-26 05:41:33 UTC (rev 16035)
+++ branches/Branch_3_2/HibernateExt/tools/build.xml 2009-02-26 05:42:08 UTC (rev 16036)
@@ -7,7 +7,7 @@
<!-- Name of project and version, used to create filenames -->
<property name="Name" value="Hibernate Tools"/>
<property name="name" value="hibernate-tools"/>
- <property name="version" value="3.2.4.CR1"/>
+ <property name="version" value="3.2.4.GA-nightly"/>
<property name="javadoc.packagenames" value="org.hibernate.tool"/>
15 years, 11 months
Hibernate SVN: r16035 - branches/Branch_3_2/HibernateExt/common.
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2009-02-26 00:41:33 -0500 (Thu, 26 Feb 2009)
New Revision: 16035
Modified:
branches/Branch_3_2/HibernateExt/common/common-build.xml
Log:
fix build to work with latest H3.2.x
Modified: branches/Branch_3_2/HibernateExt/common/common-build.xml
===================================================================
--- branches/Branch_3_2/HibernateExt/common/common-build.xml 2009-02-26 04:33:15 UTC (rev 16034)
+++ branches/Branch_3_2/HibernateExt/common/common-build.xml 2009-02-26 05:41:33 UTC (rev 16035)
@@ -42,7 +42,7 @@
<!-- set Hibernate core related properties -->
<property name="hibernate-core.home" location="${common-build.basedir}/../../hibernate-3.2"/>
- <property name="hibernate-core.jar" location="${hibernate-core.home}/hibernate3.jar"/>
+ <property name="hibernate-core.jar" location="${hibernate-core.home}/build/hibernate3.jar"/>
<property name="hibernate-core.lib.dir" location="${hibernate-core.home}/lib"/>
<property name="hibernate-core.jdbc.dir" location="${hibernate-core.home}/lib"/> <!-- for some reason jdbc.dir is renamed to lib instead of jdbc when doing a dist of hibernate3 -->
<property name="hibernate-core.doc.api" location="${hibernate-core.home}/doc/api"/>
15 years, 11 months
Hibernate SVN: r16034 - in branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate: tool/hbm2x/pojo and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2009-02-25 23:33:15 -0500 (Wed, 25 Feb 2009)
New Revision: 16034
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/OverrideRepository.java
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/EntityPOJOClass.java
Log:
remove java 5 code
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/OverrideRepository.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/OverrideRepository.java 2009-02-25 14:35:32 UTC (rev 16033)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/OverrideRepository.java 2009-02-26 04:33:15 UTC (rev 16034)
@@ -31,12 +31,12 @@
public class OverrideRepository {
final private static Log log = LogFactory.getLog( OverrideRepository.class );
-
+
final private transient XMLHelper xmlHelper;
final private transient EntityResolver entityResolver;
final private Map typeMappings; // from sqltypes to list of SQLTypeMapping
-
+
final private List tableFilters;
final private List tables;
@@ -53,9 +53,9 @@
final private Map primaryKeyColumnsForTable;
final private Set excludedColumns;
-
+
final private Map tableToClassName;
-
+
final private List schemaSelections;
final private Map propertyNameForPrimaryKey;
@@ -69,14 +69,14 @@
final private Map foreignKeyInverseExclude;
final private Map foreignKeyToOneExclude;
-
+
final private Map foreignKeyToEntityInfo;
final private Map foreignKeyToInverseEntityInfo;
final private Map tableMetaAttributes; // TI -> MultiMap of SimpleMetaAttributes
final private Map columnMetaAttributes;
-
+
//private String defaultCatalog;
//private String defaultSchema;
@@ -108,7 +108,7 @@
foreignKeyToEntityInfo = new HashMap();
foreignKeyToInverseEntityInfo = new HashMap();
}
-
+
public OverrideRepository addFile(File xmlFile) {
log.info( "Override file: " + xmlFile.getPath() );
try {
@@ -118,10 +118,10 @@
log.error( "Could not configure overrides from file: " + xmlFile.getPath(), e );
throw new MappingException( "Could not configure overrides from file: " + xmlFile.getPath(), e );
}
- return this;
-
+ return this;
+
}
-
+
/**
* Read override from an application resource trying different classloaders.
* This method will try to load the resource first from the thread context
@@ -140,7 +140,7 @@
}
}
-
+
public OverrideRepository addInputStream(InputStream xmlInputStream) throws MappingException {
try {
List errors = new ArrayList();
@@ -173,7 +173,7 @@
private String getPreferredHibernateType(int sqlType, int length, int precision, int scale, boolean nullable) {
List l = (List) typeMappings.get(new TypeMappingKey(sqlType,length) );
-
+
if(l == null) { // if no precise length match found, then try to find matching unknown length matches
l = (List) typeMappings.get(new TypeMappingKey(sqlType,SQLTypeMapping.UNKNOWN_LENGTH) );
}
@@ -188,12 +188,12 @@
if(element.getJDBCType()!=sqlType) return null;
if(element.match(sqlType, length, precision, scale, nullable) ) {
return element.getHibernateType();
- }
- }
+ }
+ }
}
return null;
}
-
+
public OverrideRepository addTypeMapping(SQLTypeMapping sqltype) {
TypeMappingKey key = new TypeMappingKey(sqltype);
List list = (List) typeMappings.get(key);
@@ -201,20 +201,20 @@
list = new ArrayList();
typeMappings.put(key, list);
}
- list.add(sqltype);
+ list.add(sqltype);
return this;
}
-
+
static class TypeMappingKey {
-
+
int type;
int length;
-
+
TypeMappingKey(SQLTypeMapping mpa) {
type = mpa.getJDBCType();
length = mpa.getLength();
}
-
+
public TypeMappingKey(int sqlType, int length) {
this.type = sqlType;
this.length = length;
@@ -224,15 +224,15 @@
if(obj==null) return false;
if(!(obj instanceof TypeMappingKey)) return false;
TypeMappingKey other = (TypeMappingKey) obj;
-
-
+
+
return type==other.type && length==other.length;
}
-
+
public int hashCode() {
return (type + length) % 17;
}
-
+
public String toString() {
return this.getClass() + "(type:" + type + ", length:" + length + ")";
}
@@ -247,13 +247,13 @@
return value;
}
}
- return null;
+ return null;
}
protected boolean excludeTable(TableIdentifier identifier) {
Iterator iterator = tableFilters.iterator();
boolean hasInclude = false;
-
+
while(iterator.hasNext() ) {
TableFilter tf = (TableFilter) iterator.next();
Boolean value = tf.exclude(identifier);
@@ -264,7 +264,7 @@
hasInclude = true;
}
}
-
+
// can probably be simplified - but like this to be very explicit ;)
if(hasInclude) {
return true; // exclude all by default when at least one include specified
@@ -276,26 +276,26 @@
public void addTableFilter(TableFilter filter) {
tableFilters.add(filter);
}
-
- public ReverseEngineeringStrategy getReverseEngineeringStrategy(ReverseEngineeringStrategy delegate) {
+
+ public ReverseEngineeringStrategy getReverseEngineeringStrategy(ReverseEngineeringStrategy delegate) {
return new DelegatingReverseEngineeringStrategy(delegate) {
-
+
public boolean excludeTable(TableIdentifier ti) {
return OverrideRepository.this.excludeTable(ti);
}
-
+
public Map tableToMetaAttributes(TableIdentifier tableIdentifier) {
- return OverrideRepository.this.tableToMetaAttributes(tableIdentifier);
+ return OverrideRepository.this.tableToMetaAttributes(tableIdentifier);
}
-
+
public Map columnToMetaAttributes(TableIdentifier tableIdentifier, String column) {
- return OverrideRepository.this.columnToMetaAttributes(tableIdentifier, column);
+ return OverrideRepository.this.columnToMetaAttributes(tableIdentifier, column);
}
-
+
public boolean excludeColumn(TableIdentifier identifier, String columnName) {
return excludedColumns.contains(TABLECOLUMN_KEY_FACTORY.newInstance(identifier, columnName));
}
-
+
public String tableToCompositeIdName(TableIdentifier identifier) {
String result = (String) compositeIdNameForTable.get(identifier);
if(result==null) {
@@ -311,7 +311,7 @@
return schemaSelections;
}
}
-
+
public String columnToHibernateTypeName(TableIdentifier table, String columnName, int sqlType, int length, int precision, int scale, boolean nullable, boolean generatedIdentifier) {
String result = null;
String location = "";
@@ -319,7 +319,7 @@
if(table!=null) {
location = Table.qualify(table.getCatalog(), table.getSchema(), table.getName() ) + "." + columnName;
} else {
-
+
location += " Column: " + columnName + info;
}
if(table!=null && columnName!=null) {
@@ -329,20 +329,20 @@
return result;
}
}
-
+
result = OverrideRepository.this.getPreferredHibernateType(sqlType, length, precision, scale, nullable);
if(result==null) {
return super.columnToHibernateTypeName(table, columnName, sqlType, length, precision, scale, nullable, generatedIdentifier);
- }
- else {
- log.debug("<type-mapping> found for [" + location + info + "] to [" + result + "]");
+ }
+ else {
+ log.debug("<type-mapping> found for [" + location + info + "] to [" + result + "]");
return result;
}
}
-
+
public String tableToClassName(TableIdentifier tableIdentifier) {
String className = (String) tableToClassName.get(tableIdentifier);
-
+
if(className!=null) {
if(className.indexOf( "." )>=0) {
return className;
@@ -354,19 +354,19 @@
return StringHelper.qualify(packageName, className);
}
}
- }
-
+ }
+
String packageName = getPackageName(tableIdentifier);
if(packageName==null) {
return super.tableToClassName(tableIdentifier);
- }
+ }
else {
String string = super.tableToClassName(tableIdentifier);
if(string==null) return null;
- return StringHelper.qualify(packageName, StringHelper.unqualify(string));
+ return StringHelper.qualify(packageName, StringHelper.unqualify(string));
}
}
-
+
public List getForeignKeys(TableIdentifier referencedTable) {
List list = (List) foreignKeys.get(referencedTable);
if(list==null) {
@@ -375,7 +375,7 @@
return list;
}
}
-
+
public String columnToPropertyName(TableIdentifier table, String column) {
String result = (String) propertyNameForColumn.get(TABLECOLUMN_KEY_FACTORY.newInstance(table, column));
if(result==null) {
@@ -384,7 +384,7 @@
return result;
}
}
-
+
public String tableToIdentifierPropertyName(TableIdentifier tableIdentifier) {
String result = (String) propertyNameForPrimaryKey.get(tableIdentifier);
if(result==null) {
@@ -393,35 +393,35 @@
return result;
}
}
-
+
public String getTableIdentifierStrategyName(TableIdentifier tableIdentifier) {
String result = (String) identifierStrategyForTable.get(tableIdentifier);
if(result==null) {
- return super.getTableIdentifierStrategyName( tableIdentifier );
+ return super.getTableIdentifierStrategyName( tableIdentifier );
} else {
log.debug("tableIdentifierStrategy for " + tableIdentifier + " -> '" + result + "'");
return result;
}
}
-
+
public Properties getTableIdentifierProperties(TableIdentifier tableIdentifier) {
Properties result = (Properties) identifierPropertiesForTable.get(tableIdentifier);
if(result==null) {
- return super.getTableIdentifierProperties( tableIdentifier );
+ return super.getTableIdentifierProperties( tableIdentifier );
} else {
return result;
}
}
-
+
public List getPrimaryKeyColumnNames(TableIdentifier tableIdentifier) {
List result = (List) primaryKeyColumnsForTable.get(tableIdentifier);
if(result==null) {
- return super.getPrimaryKeyColumnNames(tableIdentifier);
+ return super.getPrimaryKeyColumnNames(tableIdentifier);
} else {
return result;
}
}
-
+
public String foreignKeyToEntityName(String keyname, TableIdentifier fromTable, List fromColumnNames, TableIdentifier referencedTable, List referencedColumnNames, boolean uniqueReference) {
String property = (String) foreignKeyToOneName.get(keyname);
if(property==null) {
@@ -430,13 +430,13 @@
return property;
}
}
-
- @Override
+
+
public String foreignKeyToInverseEntityName(String keyname,
TableIdentifier fromTable, List fromColumnNames,
TableIdentifier referencedTable,
List referencedColumnNames, boolean uniqueReference) {
-
+
String property = (String) foreignKeyToInverseName.get(keyname);
if(property==null) {
return super.foreignKeyToInverseEntityName(keyname, fromTable, fromColumnNames, referencedTable, referencedColumnNames, uniqueReference);
@@ -444,7 +444,7 @@
return property;
}
}
-
+
public String foreignKeyToCollectionName(String keyname, TableIdentifier fromTable, List fromColumns, TableIdentifier referencedTable, List referencedColumns, boolean uniqueReference) {
String property = (String) foreignKeyToInverseName.get(keyname);
if(property==null) {
@@ -453,7 +453,7 @@
return property;
}
}
-
+
public boolean excludeForeignKeyAsCollection(String keyname, TableIdentifier fromTable, List fromColumns, TableIdentifier referencedTable, List referencedColumns) {
Boolean bool = (Boolean) foreignKeyInverseExclude.get(keyname);
if(bool!=null) {
@@ -463,7 +463,7 @@
referencedTable, referencedColumns );
}
}
-
+
public boolean excludeForeignKeyAsManytoOne(String keyname, TableIdentifier fromTable, List fromColumns, TableIdentifier referencedTable, List referencedColumns) {
Boolean bool = (Boolean) foreignKeyToOneExclude.get(keyname);
if(bool!=null) {
@@ -473,8 +473,8 @@
referencedTable, referencedColumns );
}
}
-
-
+
+
public AssociationInfo foreignKeyToInverseAssociationInfo(ForeignKey foreignKey) {
AssociationInfo fkei = (AssociationInfo) foreignKeyToInverseEntityInfo.get(foreignKey.getName());
if(fkei!=null) {
@@ -483,7 +483,7 @@
return super.foreignKeyToInverseAssociationInfo(foreignKey);
}
}
-
+
public AssociationInfo foreignKeyToAssociationInfo(ForeignKey foreignKey) {
AssociationInfo fkei = (AssociationInfo) foreignKeyToEntityInfo.get(foreignKey.getName());
if(fkei!=null) {
@@ -492,7 +492,7 @@
return super.foreignKeyToAssociationInfo(foreignKey);
}
}
- };
+ };
}
protected Map columnToMetaAttributes(TableIdentifier tableIdentifier, String column) {
@@ -500,7 +500,7 @@
if(specific!=null && !specific.isEmpty()) {
return toMetaAttributes(specific);
}
-
+
return null;
}
@@ -514,13 +514,13 @@
if(general!=null && !general.isEmpty()) {
return toMetaAttributes(general);
}
-
+
return null;
-
+
/* inheritance not defined yet
if(specific==null) { specific = Collections.EMPTY_MAP; }
if(general==null) { general = Collections.EMPTY_MAP; }
-
+
MultiMap map = MetaAttributeBinder.mergeMetaMaps( specific, general );
*/
/*
@@ -533,7 +533,7 @@
}
private Map findGeneralAttributes(TableIdentifier identifier) {
- Iterator iterator = tableFilters.iterator();
+ Iterator iterator = tableFilters.iterator();
while(iterator.hasNext() ) {
TableFilter tf = (TableFilter) iterator.next();
Map value = tf.getMetaAttributes(identifier);
@@ -546,16 +546,16 @@
private Map toMetaAttributes(Map value) {
Map result = new HashMap();
-
+
Set set = value.entrySet();
for (Iterator iter = set.iterator(); iter.hasNext();) {
Map.Entry entry = (Map.Entry) iter.next();
String name = (String) entry.getKey();
List values = (List) entry.getValue();
-
- result.put(name, MetaAttributeBinder.toRealMetaAttribute(name, values));
+
+ result.put(name, MetaAttributeBinder.toRealMetaAttribute(name, values));
}
-
+
return result;
}
@@ -573,20 +573,20 @@
existing = new ArrayList();
foreignKeys.put(identifier, existing);
}
- existing.add( fk );
+ existing.add( fk );
}
-
+
tables.add(table);
-
+
if(StringHelper.isNotEmpty(wantedClassName)) {
tableToClassName.put(TableIdentifier.create(table), wantedClassName);
}
}
-
+
private static final TableColumnKeyFactory TABLECOLUMN_KEY_FACTORY;
static {
- TABLECOLUMN_KEY_FACTORY = (TableColumnKeyFactory) KeyFactory.create(TableColumnKeyFactory.class);
+ TABLECOLUMN_KEY_FACTORY = (TableColumnKeyFactory) KeyFactory.create(TableColumnKeyFactory.class);
}
static interface TableColumnKeyFactory {
@@ -598,11 +598,11 @@
typeForColumn.put(TABLECOLUMN_KEY_FACTORY.newInstance(identifier, columnName), type);
}
}
-
+
public void setExcludedColumn(TableIdentifier tableIdentifier, String columnName) {
- excludedColumns.add(TABLECOLUMN_KEY_FACTORY.newInstance(tableIdentifier, columnName));
+ excludedColumns.add(TABLECOLUMN_KEY_FACTORY.newInstance(tableIdentifier, columnName));
}
-
+
public void setPropertyNameForColumn(TableIdentifier identifier, String columnName, String property) {
if(StringHelper.isNotEmpty(property)) {
propertyNameForColumn.put(TABLECOLUMN_KEY_FACTORY.newInstance(identifier, columnName), property);
@@ -614,17 +614,17 @@
final TableIdentifier tid = TableIdentifier.create(table);
identifierStrategyForTable.put(tid, identifierClass);
identifierPropertiesForTable.put(tid, params);
- }
+ }
}
public void addPrimaryKeyNamesForTable(Table table, List boundColumnNames, String propertyName, String compositeIdName) {
- TableIdentifier tableIdentifier = TableIdentifier.create(table);
+ TableIdentifier tableIdentifier = TableIdentifier.create(table);
if(boundColumnNames!=null && !boundColumnNames.isEmpty()) {
primaryKeyColumnsForTable.put(tableIdentifier, boundColumnNames);
}
if(StringHelper.isNotEmpty(propertyName)) {
propertyNameForPrimaryKey.put(tableIdentifier, propertyName);
- }
+ }
if(StringHelper.isNotEmpty(compositeIdName)) {
compositeIdNameForTable.put(tableIdentifier, compositeIdName);
}
@@ -643,14 +643,14 @@
}
/**
- * Both sides of the FK are important,
+ * Both sides of the FK are important,
* the owning side can generate a toOne (ManyToOne or OneToOne), we call this side foreignKeyToOne
* the inverse side can generate a OneToMany OR a OneToOne (in case we have a pure bidirectional OneToOne, we call this side foreignKeyToInverse
*/
public void addForeignKeyInfo(String constraintName, String toOneProperty, Boolean excludeToOne, String inverseProperty, Boolean excludeInverse, AssociationInfo associationInfo, AssociationInfo inverseAssociationInfo) {
if(StringHelper.isNotEmpty(toOneProperty)) {
foreignKeyToOneName.put(constraintName, toOneProperty);
- }
+ }
if(StringHelper.isNotEmpty(inverseProperty)) {
foreignKeyToInverseName.put(constraintName, inverseProperty);
}
@@ -666,24 +666,24 @@
if(inverseAssociationInfo!=null) {
foreignKeyToInverseEntityInfo.put(constraintName, inverseAssociationInfo);
}
-
+
}
public void addMetaAttributeInfo(Table table, Map map) {
if(map!=null && !map.isEmpty()) {
tableMetaAttributes.put(TableIdentifier.create(table), map);
}
-
+
}
public void addMetaAttributeInfo(TableIdentifier tableIdentifier, String name, MultiMap map) {
if(map!=null && !map.isEmpty()) {
columnMetaAttributes.put(TABLECOLUMN_KEY_FACTORY.newInstance( tableIdentifier, name ), map);
}
-
+
}
-
-
-
+
+
+
}
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/EntityPOJOClass.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/EntityPOJOClass.java 2009-02-25 14:35:32 UTC (rev 16033)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/EntityPOJOClass.java 2009-02-26 04:33:15 UTC (rev 16034)
@@ -124,7 +124,7 @@
return getAllPropertiesIterator(clazz);
}
-
+
public Iterator getAllPropertiesIterator(PersistentClass pc) {
List properties = new ArrayList();
List iterators = new ArrayList();
@@ -142,29 +142,29 @@
}*/
}
-
+
// iterators.add( pc.getPropertyIterator() );
// Need to skip <properties> element which are defined via "embedded" components
// Best if we could return an intelligent iterator, but for now we just iterate explicitly.
- Iterator pit = pc.getPropertyIterator();
+ Iterator pit = pc.getPropertyIterator();
while(pit.hasNext())
{
Property element = (Property) pit.next();
- if ( element.getValue() instanceof Component
+ if ( element.getValue() instanceof Component
&& element.getPropertyAccessorName().equals( "embedded" )) {
Component component = (Component) element.getValue();
// need to "explode" property to get proper sequence in java code.
Iterator embeddedProperty = component.getPropertyIterator();
while(embeddedProperty.hasNext()) {
properties.add(embeddedProperty.next());
- }
+ }
} else {
properties.add(element);
}
}
-
+
iterators.add( properties.iterator() );
-
+
Iterator[] it = (Iterator[]) iterators.toArray( new Iterator[iterators.size()] );
return new SkipBackRefPropertyIterator( new JoinedIterator( it ) );
}
@@ -177,7 +177,7 @@
public boolean hasIdentifierProperty() {
return clazz.hasIdentifierProperty() && clazz instanceof RootClass;
}
-
+
public Property getIdentifierProperty() {
return clazz.getIdentifierProperty();
}
@@ -200,20 +200,20 @@
}
AnnotationBuilder constraint = AnnotationBuilder.createAnnotation( importType("javax.persistence.UniqueConstraint") );
constraint.addQuotedAttributes( "columnNames", new IteratorTransformer(key.getColumnIterator()) {
- public Object transform(Object object) {
+ public Object transform(Object object) {
return ((Column)object).getName();
}
});
cons.add( constraint.getResult() );
}
-
+
AnnotationBuilder builder = AnnotationBuilder.createAnnotation( "dummyAnnotation" );
builder.addAttributes( "dummyAttribute", cons.iterator() );
String attributeAsString = builder.getAttributeAsString( "dummyAttribute" );
return attributeAsString==null?"":attributeAsString;
}
-
+
public String generateAnnIdGenerator() {
KeyValue identifier = clazz.getIdentifier();
String strategy = null;
@@ -231,11 +231,11 @@
AnnotationBuilder builder = AnnotationBuilder.createAnnotation( importType("javax.persistence.Id") );
idResult.append(builder.getResult());
idResult.append(" ");
-
+
boolean isGenericGenerator = false; //TODO: how to handle generic now??
if ( !"assigned".equals( strategy ) ) {
-
- if ( !"native".equals( strategy ) ) {
+
+ if ( !"native".equals( strategy ) ) {
if ( "identity".equals( strategy ) ) {
builder.resetAnnotation( importType("javax.persistence.GeneratedValue") );
builder.addAttribute( "strategy", staticImport("javax.persistence.GenerationType", "IDENTITY" ) );
@@ -245,8 +245,8 @@
builder.resetAnnotation( importType("javax.persistence.GeneratedValue") )
.addAttribute( "strategy", staticImport("javax.persistence.GenerationType", "SEQUENCE" ) )
.addQuotedAttribute( "generator", "generator" );
- idResult.append(builder.getResult());
-
+ idResult.append(builder.getResult());
+
builder.resetAnnotation( importType("javax.persistence.SequenceGenerator") )
.addQuotedAttribute( "name", "generator" ) // TODO: shouldn't this be unique, e.g. entityName + sequenceName (or just sequencename) ?
.addQuotedAttribute( "sequenceName", properties.getProperty( org.hibernate.id.SequenceGenerator.SEQUENCE, null ) );
@@ -265,7 +265,7 @@
builder.resetAnnotation( importType("javax.persistence.GeneratedValue") );
builder.addQuotedAttribute( "generator", "generator" );
idResult.append(builder.getResult());
- }
+ }
} else {
builder.resetAnnotation( importType("javax.persistence.GeneratedValue") );
idResult.append(builder.getResult());
@@ -275,18 +275,18 @@
builder.resetAnnotation( importType("org.hibernate.annotations.GenericGenerator") )
.addQuotedAttribute( "name", "generator" )
.addQuotedAttribute( "strategy", strategy);
-
+
List params = new ArrayList();
//wholeString.append( "parameters = { " );
if ( properties != null ) {
Enumeration propNames = properties.propertyNames();
while ( propNames.hasMoreElements() ) {
-
+
String propertyName = (String) propNames.nextElement();
AnnotationBuilder parameter = AnnotationBuilder.createAnnotation( importType("org.hibernate.annotations.Parameter") )
.addQuotedAttribute( "name", propertyName )
.addQuotedAttribute( "value", properties.getProperty( propertyName ) );
- params.add( parameter );
+ params.add( parameter );
}
}
builder.addAttributes( "parameters", params.iterator() );
@@ -295,27 +295,27 @@
wholeString.append( idResult );
}
return wholeString.toString();
- }
+ }
private void buildAnnTableGenerator(StringBuffer wholeString, Properties properties) {
-
+
AnnotationBuilder builder = AnnotationBuilder.createAnnotation( importType("javax.persistence.TableGenerator") );
builder.addQuotedAttribute( "name", "generator" );
builder.addQuotedAttribute( "table", properties.getProperty( "generatorTableName", "hibernate_sequences" ) );
if ( ! isPropertyDefault( PersistentIdentifierGenerator.CATALOG, properties ) ) {
- builder.addQuotedAttribute( "catalog", properties.getProperty( PersistentIdentifierGenerator.CATALOG, "") );
+ builder.addQuotedAttribute( "catalog", properties.getProperty( PersistentIdentifierGenerator.CATALOG, "") );
}
if ( ! isPropertyDefault( PersistentIdentifierGenerator.SCHEMA, properties ) ) {
- builder.addQuotedAttribute( "schema", properties.getProperty( PersistentIdentifierGenerator.SCHEMA, "") );
+ builder.addQuotedAttribute( "schema", properties.getProperty( PersistentIdentifierGenerator.SCHEMA, "") );
}
if (! isPropertyDefault( MultipleHiLoPerTableGenerator.PK_VALUE_NAME, properties ) ) {
- builder.addQuotedAttribute( "pkColumnValue", properties.getProperty( MultipleHiLoPerTableGenerator.PK_VALUE_NAME, "") );
+ builder.addQuotedAttribute( "pkColumnValue", properties.getProperty( MultipleHiLoPerTableGenerator.PK_VALUE_NAME, "") );
}
if ( ! isPropertyDefault( MultipleHiLoPerTableGenerator.MAX_LO, properties, "50" ) ) {
builder.addAttribute( "allocationSize", properties.getProperty( MultipleHiLoPerTableGenerator.MAX_LO, "50" ) );
}
if (! isPropertyDefault( MultipleHiLoPerTableGenerator.PK_COLUMN_NAME, properties ) ) {
- builder.addQuotedAttribute( "pkColumnName", properties.getProperty( MultipleHiLoPerTableGenerator.PK_COLUMN_NAME, "") );
+ builder.addQuotedAttribute( "pkColumnName", properties.getProperty( MultipleHiLoPerTableGenerator.PK_COLUMN_NAME, "") );
}
if (! isPropertyDefault( MultipleHiLoPerTableGenerator.VALUE_COLUMN_NAME, properties ) ) {
builder.addQuotedAttribute( "valueColumnName", properties.getProperty( MultipleHiLoPerTableGenerator.VALUE_COLUMN_NAME, "") );
@@ -348,7 +348,7 @@
span = property.getColumnSpan();
columnIterator = property.getColumnIterator();
}
-
+
if(property.getValue() instanceof ToOne) {
String referencedEntityName = ((ToOne)property.getValue()).getReferencedEntityName();
PersistentClass target = cfg.getClassMapping(referencedEntityName);
@@ -381,7 +381,7 @@
if(referencedColumnsIterator!=null) {
referencedColumn = (Selectable) referencedColumnsIterator.next();
}
-
+
if ( selectable.isFormula() ) {
//TODO formula in multicolumns not supported by annotations
//annotations.append("/* TODO formula in multicolumns not supported by annotations */");
@@ -409,27 +409,27 @@
if(referencedColumn!=null) {
annotations.append(", referencedColumnName=\"" ).append( referencedColumn.getText() ).append( "\"" );
}
-
- appendCommonColumnInfo(annotations, column, insertable, updatable);
+
+ appendCommonColumnInfo(annotations, column, insertable, updatable);
//TODO support secondary table
annotations.append( ")" );
}
- }
-
+ }
+
public String[] getCascadeTypes(Property property) {
StringTokenizer st = new StringTokenizer( property.getCascade(), ", ", false );
List types = new ArrayList();
while ( st.hasMoreElements() ) {
String element = ( (String) st.nextElement() ).toLowerCase();
if ( "persist".equals( element ) ) {
- types.add(importType( "javax.persistence.CascadeType" ) + ".PERSIST");
+ types.add(importType( "javax.persistence.CascadeType" ) + ".PERSIST");
}
else if ( "merge".equals( element ) ) {
types.add(importType( "javax.persistence.CascadeType") + ".MERGE");
}
else if ( "delete".equals( element ) ) {
types.add(importType( "javax.persistence.CascadeType") + ".REMOVE");
- }
+ }
else if ( "refresh".equals( element ) ) {
types.add(importType( "javax.persistence.CascadeType") + ".REFRESH");
}
@@ -448,51 +448,51 @@
buffer.append(getHibernateCascadeTypeAnnotation(property));
return buffer.toString();
}
-
+
public boolean isSharedPkBasedOneToOne(OneToOne oneToOne){
Iterator joinColumnsIt = oneToOne.getColumnIterator();
Set joinColumns = new HashSet();
while ( joinColumnsIt.hasNext() ) {
joinColumns.add( joinColumnsIt.next() );
}
-
+
if ( joinColumns.size() == 0 )
return false;
-
- Iterator<Column> idColumnsIt = getIdentifierProperty().getColumnIterator();
+
+ Iterator idColumnsIt = getIdentifierProperty().getColumnIterator();
Set idColumns = new HashSet();
while ( idColumnsIt.hasNext() ) {
if (!joinColumns.contains(idColumnsIt.next()) )
return false;
}
-
+
return true;
}
-
+
public String generateOneToOneAnnotation(Property property, Configuration cfg) {
OneToOne oneToOne = (OneToOne)property.getValue();
-
+
boolean pkIsAlsoFk = isSharedPkBasedOneToOne(oneToOne);
-
+
AnnotationBuilder ab = AnnotationBuilder.createAnnotation( importType("javax.persistence.OneToOne") )
.addAttribute( "cascade", getCascadeTypes(property))
.addAttribute( "fetch", getFetchType(property));
-
+
if ( oneToOne.getForeignKeyType().equals(ForeignKeyDirection.FOREIGN_KEY_TO_PARENT) ){
ab.addQuotedAttribute("mappedBy", getOneToOneMappedBy(cfg, oneToOne));
}
-
+
StringBuffer buffer = new StringBuffer(ab.getResult());
buffer.append(getHibernateCascadeTypeAnnotation(property));
-
+
if ( pkIsAlsoFk && oneToOne.getForeignKeyType().equals(ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT) ){
AnnotationBuilder ab1 = AnnotationBuilder.createAnnotation( importType("javax.persistence.PrimaryKeyJoinColumn") );
buffer.append(ab1.getResult());
}
-
+
return buffer.toString();
}
-
+
public String getHibernateCascadeTypeAnnotation(Property property) {
StringTokenizer st = new StringTokenizer( property.getCascade(), ", ", false );
String cascadeType = null;
@@ -572,10 +572,10 @@
ab.addAttribute( "fetch", getFetchType (property) );
if ( collection.isInverse() ) {
mappedBy = getOneToManyMappedBy( cfg, collection );
- ab.addQuotedAttribute( "mappedBy", mappedBy );
+ ab.addQuotedAttribute( "mappedBy", mappedBy );
}
annotation.append( ab.getResult() );
-
+
if (mappedBy == null) annotation.append("\n").append( generateJoinColumnsAnnotation(property, cfg) );
}
else {
@@ -585,17 +585,17 @@
AnnotationBuilder ab = AnnotationBuilder.createAnnotation( importType( "javax.persistence.ManyToMany") );
ab.addAttribute( "cascade", getCascadeTypes( property ) );
ab.addAttribute( "fetch", getFetchType (property) );
-
+
if ( collection.isInverse() ) {
mappedBy = getManyToManyMappedBy( cfg, collection );
- ab.addQuotedAttribute( "mappedBy", mappedBy );
+ ab.addQuotedAttribute( "mappedBy", mappedBy );
}
annotation.append(ab.getResult());
if (mappedBy == null) {
annotation.append("\n @");
annotation.append( importType( "javax.persistence.JoinTable") ).append( "(name=\"" );
Table table = collection.getCollectionTable();
-
+
annotation.append( table.getName() );
annotation.append( "\"" );
if ( StringHelper.isNotEmpty( table.getSchema() ) ) {
@@ -711,7 +711,7 @@
}
return mappedBy;
}
-
+
private String getOneToOneMappedBy(Configuration cfg, OneToOne oneToOne) {
String mappedBy;
Iterator joinColumnsIt = oneToOne.getColumnIterator();
@@ -723,13 +723,13 @@
String referencedPropertyName = oneToOne.getReferencedPropertyName();
if ( referencedPropertyName != null )
return referencedPropertyName;
-
+
Iterator properties = pc.getPropertyClosureIterator();
//TODO we should check the table too
boolean isOtherSide = false;
mappedBy = "unresolved";
-
-
+
+
while ( ! isOtherSide && properties.hasNext() ) {
Property oneProperty = (Property) properties.next();
Value manyValue = oneProperty.getValue();
@@ -753,15 +753,15 @@
}
return mappedBy;
}
-
+
public boolean isSubclass() {
- return clazz.getSuperclass()!=null;
+ return clazz.getSuperclass()!=null;
}
-
+
public List getPropertyClosureForFullConstructor() {
return getPropertyClosureForFullConstructor(clazz);
}
-
+
protected List getPropertyClosureForFullConstructor(PersistentClass pc) {
List l = new ArrayList(getPropertyClosureForSuperclassFullConstructor( pc ));
l.addAll(getPropertiesForFullConstructor( pc ));
@@ -771,10 +771,10 @@
public List getPropertiesForFullConstructor() {
return getPropertiesForFullConstructor(clazz);
}
-
+
protected List getPropertiesForFullConstructor(PersistentClass pc) {
List result = new ArrayList();
-
+
for ( Iterator myFields = getAllPropertiesIterator(pc); myFields.hasNext() ; ) {
Property field = (Property) myFields.next();
// TODO: if(!field.isGenerated() ) ) {
@@ -787,17 +787,17 @@
} else if(isFormula(field)) {
continue;
} else {
- result.add( field );
+ result.add( field );
}
}
-
+
return result;
}
private boolean isFormula(Property field) {
Value value = field.getValue();
- boolean foundFormula = false;
-
+ boolean foundFormula = false;
+
if(value!=null && value.getColumnSpan()>0) {
Iterator columnIterator = value.getColumnIterator();
while ( columnIterator.hasNext() ) {
@@ -817,7 +817,7 @@
public List getPropertyClosureForSuperclassFullConstructor() {
return getPropertyClosureForSuperclassFullConstructor(clazz);
}
-
+
public List getPropertyClosureForSuperclassFullConstructor(PersistentClass pc) {
List result = new ArrayList();
if ( pc.getSuperclass() != null ) {
@@ -830,12 +830,12 @@
return result;
}
-
-
+
+
public List getPropertyClosureForMinimalConstructor() {
return getPropertyClosureForMinimalConstructor(clazz);
}
-
+
protected List getPropertyClosureForMinimalConstructor(PersistentClass pc) {
List l = new ArrayList(getPropertyClosureForSuperclassMinConstructor( pc ));
l.addAll(getPropertiesForMinimalConstructor( pc ));
@@ -845,25 +845,25 @@
public List getPropertiesForMinimalConstructor() {
return getPropertiesForMinimalConstructor(clazz);
}
-
+
protected List getPropertiesForMinimalConstructor(PersistentClass pc) {
List result = new ArrayList();
-
+
for ( Iterator myFields = getAllPropertiesIterator(pc); myFields.hasNext() ; ) {
Property property = (Property) myFields.next();
if(property.equals(pc.getIdentifierProperty())) {
if(isAssignedIdentifier(pc, property)) {
result.add(property);
} else {
- continue;
- }
+ continue;
+ }
} else if (property.equals(pc.getVersion())) {
continue; // the version property should not be in the result.
} else if( isRequiredInConstructor(property) ) {
result.add(property);
- }
+ }
}
-
+
return result;
}
@@ -874,7 +874,7 @@
if("assigned".equals(sv.getIdentifierGeneratorStrategy())) {
return true;
}
- }
+ }
}
return false;
}
@@ -882,7 +882,7 @@
public List getPropertyClosureForSuperclassMinimalConstructor() {
return getPropertyClosureForSuperclassMinConstructor(clazz);
}
-
+
protected List getPropertyClosureForSuperclassMinConstructor(PersistentClass pc) {
List result = new ArrayList();
if ( pc.getSuperclass() != null ) {
@@ -895,22 +895,22 @@
return result;
}
-
+
public POJOClass getSuperClass(){
if (!isSubclass())
return null;
return new EntityPOJOClass(clazz.getSuperclass(),c2j);
}
-
+
public String toString() {
return "Entity: " + (clazz==null?"<none>":clazz.getEntityName());
}
-
+
public boolean hasVersionProperty() {
return clazz.isVersioned() && clazz instanceof RootClass;
}
-
+
/*
* @see org.hibernate.tool.hbm2x.pojo.POJOClass#getVersionProperty()
*/
@@ -918,7 +918,7 @@
{
return clazz.getVersion();
}
-
+
static public abstract class IteratorTransformer implements Iterator {
private Iterator delegate;
@@ -926,7 +926,7 @@
public IteratorTransformer(Iterator delegate) {
this.delegate = delegate;
}
-
+
public boolean hasNext() {
return delegate.hasNext();
}
@@ -938,8 +938,8 @@
public abstract Object transform(Object object);
public void remove() {
- delegate.remove();
- }
+ delegate.remove();
+ }
}
-
+
}
15 years, 11 months
Hibernate SVN: r16033 - beanvalidation/trunk/validation-api/src/main/java/javax/validation.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-02-25 09:35:32 -0500 (Wed, 25 Feb 2009)
New Revision: 16033
Modified:
beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validator.java
Log:
minor style
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validator.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validator.java 2009-02-25 13:39:40 UTC (rev 16032)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/Validator.java 2009-02-25 14:35:32 UTC (rev 16033)
@@ -31,13 +31,13 @@
*
* @param object object to validate
* @param groups groups targeted for validation
- * (default to {@link javax.validation.groups.Default})
+ * (default to {@link javax.validation.groups.Default})
*
* @return constraint violations or an empty Set if none
*
* @throws IllegalArgumentException if object is null
- * @throws ValidationException if a non recoverable error happens
- * during the validation process
+ * @throws ValidationException if a non recoverable error happens
+ * during the validation process
*/
<T> Set<ConstraintViolation<T>> validate(T object, Class<?>... groups);
@@ -47,14 +47,14 @@
* @param object object to validate
* @param propertyName property to validate (ie field and getter constraints)
* @param groups groups targeted for validation
- * (default to {@link javax.validation.groups.Default})
+ * (default to {@link javax.validation.groups.Default})
*
* @return constraint violations or an empty Set if none
*
* @throws IllegalArgumentException if object is null, if propertyName null, empty
* or not a valid object property
- * @throws ValidationException if a non recoverable error happens
- * during the validation process
+ * @throws ValidationException if a non recoverable error happens
+ * during the validation process
*/
<T> Set<ConstraintViolation<T>> validateProperty(T object,
String propertyName,
@@ -70,13 +70,14 @@
* @param propertyName property to validate
* @param value property value to validate
* @param groups groups targeted for validation
- * (default to {@link javax.validation.groups.Default})
+ * (default to {@link javax.validation.groups.Default})
*
* @return constraint violations or an empty Set if none
+ *
* @throws IllegalArgumentException if object is null, if propertyName null, empty
* or not a valid object property
- * @throws ValidationException if a non recoverable error happens
- * during the validation process
+ * @throws ValidationException if a non recoverable error happens
+ * during the validation process
*/
<T> Set<ConstraintViolation<T>> validateValue(Class<T> beanType,
String propertyName,
@@ -86,13 +87,15 @@
/**
* Return the descriptor object describing bean constraints
* The returned object (and associated objects including ConstraintDescriptors)
- * are immutable.
+ * are immutable.
*
* @param clazz class type evaluated
+ *
* @return the bean descriptor for the specified class.
+ *
* @throws ValidationException if a non recoverable error happens
* during the metadata discovery or if some
- * constraints are invalid.
+ * constraints are invalid.
*/
BeanDescriptor getConstraintsForClass(Class<?> clazz);
}
15 years, 11 months
Hibernate SVN: r16032 - validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/report.
by hibernate-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2009-02-25 08:39:40 -0500 (Wed, 25 Feb 2009)
New Revision: 16032
Modified:
validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/report/CoverageProcessor.java
validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/report/CoverageReport.java
validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/report/SpecReference.java
Log:
Add support for skipped (stub and broken) tests through testng @Test(groups)
Modified: validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/report/CoverageProcessor.java
===================================================================
--- validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/report/CoverageProcessor.java 2009-02-25 13:09:51 UTC (rev 16031)
+++ validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/report/CoverageProcessor.java 2009-02-25 13:39:40 UTC (rev 16032)
@@ -128,7 +128,7 @@
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnvironment) {
if (auditParser == null) {
- return true;
+ return false;
}
for (TypeElement type : annotations) {
@@ -138,7 +138,7 @@
if (roundEnvironment.processingOver()) {
new CoverageReport(references, auditParser).writeToFile(new File(baseDir, REPORT_FILE_NAME));
}
- return true;
+ return false;
}
private void processAnnotatedMethods(RoundEnvironment env, TypeElement annotation) {
@@ -184,6 +184,24 @@
ref.setAssertion((String) entry.getValue().getValue());
}
}
+ for (AnnotationMirror annotationMirror : processingEnv.getElementUtils().getAllAnnotationMirrors(methodElement))
+ {
+ if (annotationMirror.getAnnotationType().toString().equals("org.testng.annotations.Test"))
+ {
+ Map<? extends ExecutableElement, ? extends AnnotationValue> testAnnotationParameters =
+ processingEnv.getElementUtils().getElementValuesWithDefaults(annotationMirror);
+ for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : testAnnotationParameters.entrySet()) {
+ final String elementKey = entry.getKey().toString();
+
+ if (elementKey.equals("groups()")) {
+ for (AnnotationValue annotationValue : (List<? extends AnnotationValue>) entry.getValue().getValue())
+ {
+ ref.getGroups().add((String) annotationValue.getValue());
+ }
+ }
+ }
+ }
+ }
references.add(ref);
}
Modified: validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/report/CoverageReport.java
===================================================================
--- validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/report/CoverageReport.java 2009-02-25 13:09:51 UTC (rev 16031)
+++ validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/report/CoverageReport.java 2009-02-25 13:39:40 UTC (rev 16032)
@@ -19,10 +19,14 @@
*/
public class CoverageReport {
- public static final String FISHEYE_BASE_URL_PROPERTY = "fisheye_base_url";
+ public enum TestStatus {
+ COVERED, UNCOVERED, UNIMPLEMENTED;
+ }
- public static final String SVN_BASE_URL_PROPERTY = "svn_base_url";
+ public static final String FISHEYE_BASE_URL_PROPERTY = "fisheye_base_url";
+ public static final String SVN_BASE_URL_PROPERTY = "svn_base_url";
+
/*
* References to the spec assertions made by the tck tests
*/
@@ -85,7 +89,7 @@
calculateUnmatched();
writeHeader(out);
writeContents(out);
- writeMasterSummary(out);
+ //writeMasterSummary(out);
writeChapterSummary(out);
writeSectionSummary(out);
writeCoverage(out);
@@ -175,6 +179,12 @@
sb.append(" padding-bottom: 1px;\n");
sb.append(" margin-bottom: 2px;\n");
sb.append(" background-color: #fdd; }\n");
+ sb.append(" .skip {\n");
+ sb.append(" border-top: 1px solid #ff9900;\n");
+ sb.append(" border-bottom: 1px solid #ff9900;\n");
+ sb.append(" padding-bottom: 1px;\n");
+ sb.append(" margin-bottom: 2px;\n");
+ sb.append(" background-color: #ffcc33; }\n");
sb.append(" .untestable {\n");
sb.append(" padding-bottom: 16px;\n");
sb.append(" margin-bottom: 2px;\n");
@@ -297,11 +307,19 @@
sb.append("<th align=\"left\">Chapter</th>");
sb.append("<th>Assertions</th>");
sb.append("<th>Testable</th>");
- sb.append("<th>Tested</th>");
+ sb.append("<th>Tested<br /> (implemented and unimplemented)</th>");
+ sb.append("<th>Tested<br /> (unimplemented)</th>");
+ sb.append("<th>Tested<br /> (implemented)</th>");
sb.append("<th>Coverage %</th>");
sb.append("</tr>");
boolean odd = true;
+
+ int totalAssertions = 0;
+ int totalTestable = 0;
+ int totalTested = 0;
+ int totalUnimplemented = 0;
+ int totalImplemented = 0;
for (String sectionId : auditParser.getSectionIds()) {
@@ -312,16 +330,22 @@
int assertions = auditParser.getAssertionsForSection(sectionId).size();
int testable = 0;
- int coverage = 0;
+ int implemented = 0;
+ int unimplemented = 0;
for (AuditAssertion assertion : auditParser.getAssertionsForSection(sectionId))
{
if (assertion.isTestable()) testable++;
- if (!getCoverageForAssertion(sectionId, assertion.getId()).isEmpty())
+ TestStatus status = getStatus(getCoverageForAssertion(sectionId, assertion.getId()));
+ if (status.equals(TestStatus.COVERED))
{
- coverage++;
+ implemented++;
}
+ else if (status.equals(TestStatus.UNIMPLEMENTED))
+ {
+ unimplemented++;
+ }
}
// Gather stats here
@@ -335,14 +359,29 @@
{
if (assertion.isTestable()) testable++;
- if (!getCoverageForAssertion(subSectionId, assertion.getId()).isEmpty())
+ TestStatus status = getStatus(getCoverageForAssertion(subSectionId, assertion.getId()));
+ if (status.equals(TestStatus.COVERED))
{
- coverage++;
+ implemented++;
}
+ else if (status.equals(TestStatus.UNIMPLEMENTED))
+ {
+ unimplemented++;
+ }
}
}
}
+ int tested = implemented + unimplemented;
+
+ double coveragePercent = testable > 0 ? ((implemented * 1.0) / testable) * 100 : -1;
+
+ totalAssertions += assertions;
+ totalTestable += testable;
+ totalImplemented += implemented;
+ totalTested += tested;
+ totalUnimplemented += unimplemented;
+
if (odd)
{
sb.append("<tr style=\"background-color:#f7f7f7\">");
@@ -364,8 +403,6 @@
sb.append("</a>");
sb.append("</td>");
- double coveragePercent = assertions > 0 ? ((coverage * 1.0) / assertions) * 100 : -1;
-
sb.append("<td align=\"center\">");
sb.append(assertions);
sb.append("</td>");
@@ -375,9 +412,17 @@
sb.append("</td>");
sb.append("<td align=\"center\">");
- sb.append(coverage);
+ sb.append(tested);
sb.append("</td>");
+ sb.append("<td align=\"center\">");
+ sb.append(unimplemented);
+ sb.append("</td>");
+
+ sb.append("<td align=\"center\">");
+ sb.append(implemented);
+ sb.append("</td>");
+
if (coveragePercent >= 0)
{
String bgColor = coveragePercent < 60 ? "#ffaaaa" : coveragePercent < 80 ? "#ffffaa" : "#aaffaa" ;
@@ -396,7 +441,57 @@
}
}
+
+ if (odd)
+ {
+ sb.append("<tr style=\"background-color:#f7f7f7\">");
+ }
+ else
+ {
+ sb.append("<tr style=\"font-weight: bold\">");
+ }
+
+ sb.append("<td>");
+ sb.append("Total");
+ sb.append("</td>");
+
+ sb.append("<td align=\"center\">");
+ sb.append(totalAssertions);
+ sb.append("</td>");
+
+ sb.append("<td align=\"center\">");
+ sb.append(totalTestable);
+ sb.append("</td>");
+
+ sb.append("<td align=\"center\">");
+ sb.append(totalTested);
+ sb.append("</td>");
+
+ sb.append("<td align=\"center\">");
+ sb.append(totalUnimplemented);
+ sb.append("</td>");
+
+ sb.append("<td align=\"center\">");
+ sb.append(totalImplemented);
+ sb.append("</td>");
+
+ double totalCoveragePercent = totalTestable > 0 ? ((totalImplemented * 1.0) / totalTestable) * 100 : -1;
+
+ if (totalCoveragePercent >= 0)
+ {
+ String bgColor = totalCoveragePercent < 60 ? "#ffaaaa" : totalCoveragePercent < 80 ? "#ffffaa" : "#aaffaa" ;
+
+ sb.append("<td align=\"center\" style=\"background-color:" + bgColor + "\">");
+ sb.append(String.format("%.2f%%", totalCoveragePercent));
+ sb.append("</td>");
+ }
+ else
+ {
+ sb.append("<td />");
+ }
+ sb.append("</tr>");
+
sb.append("</table>");
out.write(sb.toString().getBytes());
}
@@ -412,7 +507,9 @@
sb.append("<th align=\"left\">Section</th>");
sb.append("<th>Assertions</th>");
sb.append("<th>Testable</th>");
- sb.append("<th>Tested</th>");
+ sb.append("<th>Tested<br /> (implemented and unimplemented)</th>");
+ sb.append("<th>Tested<br /> (unimplemented)</th>");
+ sb.append("<th>Tested<br /> (implemented)</th>");
sb.append("<th>Coverage %</th>");
sb.append("</tr>");
@@ -443,21 +540,27 @@
int assertions = auditParser.getAssertionsForSection(sectionId).size();
int testable = 0;
- int coverage = 0;
+ int implemented = 0;
+ int unimplemented = 0;
for (AuditAssertion assertion : auditParser.getAssertionsForSection(sectionId))
{
if (assertion.isTestable()) testable++;
- if (!getCoverageForAssertion(sectionId, assertion.getId()).isEmpty())
+ TestStatus status = getStatus(getCoverageForAssertion(sectionId, assertion.getId()));
+ if (status.equals(TestStatus.COVERED))
{
- coverage++;
+ implemented++;
}
+ else if (status.equals(TestStatus.UNIMPLEMENTED))
+ {
+ unimplemented++;
+ }
}
- int coveredAndUnTestable = coverage + (assertions - testable);
+ int tested = implemented + unimplemented;
- double coveragePercent = assertions > 0 ? ((coveredAndUnTestable * 1.0) / (assertions)) * 100 : -1;
+ double coveragePercent = testable > 0 ? ((implemented * 1.0) / testable) * 100 : -1;
sb.append("<td align=\"center\">");
sb.append(assertions);
@@ -468,9 +571,17 @@
sb.append("</td>");
sb.append("<td align=\"center\">");
- sb.append(coverage);
+ sb.append(tested);
sb.append("</td>");
+ sb.append("<td align=\"center\">");
+ sb.append(unimplemented);
+ sb.append("</td>");
+
+ sb.append("<td align=\"center\">");
+ sb.append(implemented);
+ sb.append("</td>");
+
if (coveragePercent >= 0)
{
String bgColor = coveragePercent < 60 ? "#ffaaaa" : coveragePercent < 80 ? "#ffffaa" : "#aaffaa" ;
@@ -508,15 +619,20 @@
for (AuditAssertion assertion : sectionAssertions) {
List<SpecReference> coverage = getCoverageForAssertion(sectionId, assertion.getId());
+ TestStatus status = getStatus(coverage);
String divClass = null;
if (assertion.isTestable())
{
- if (coverage.isEmpty())
+ if (status.equals(TestStatus.UNCOVERED))
{
divClass = "fail";
}
+ else if (status.equals(TestStatus.UNIMPLEMENTED))
+ {
+ divClass = "skip";
+ }
else
{
divClass = "pass";
@@ -558,7 +674,7 @@
String currentPackageName = null;
- if (coverage.isEmpty()) {
+ if (status.equals(TestStatus.UNCOVERED)) {
sb.append(" <p class=\"noCoverage\">No tests exist for this assertion</p>\n");
} else {
for (SpecReference ref : coverage) {
@@ -674,6 +790,27 @@
return refs;
}
+
+ private TestStatus getStatus(List<SpecReference> references)
+ {
+ if (references.isEmpty())
+ {
+ return TestStatus.UNCOVERED;
+ }
+ for (SpecReference reference : references)
+ {
+ if (isImplemented(reference.getGroups()))
+ {
+ return TestStatus.COVERED;
+ }
+ }
+ return TestStatus.UNIMPLEMENTED;
+ }
+
+ private boolean isImplemented(List<String> groups)
+ {
+ return !groups.contains("stub") && !groups.contains("broken");
+ }
private void writeFooter(OutputStream out) throws IOException {
out.write("</table>".getBytes());
Modified: validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/report/SpecReference.java
===================================================================
--- validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/report/SpecReference.java 2009-02-25 13:09:51 UTC (rev 16031)
+++ validator/trunk/tck-utils/impl/src/main/java/org/hibernate/tck/report/SpecReference.java 2009-02-25 13:39:40 UTC (rev 16032)
@@ -1,16 +1,26 @@
package org.hibernate.tck.report;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* Represents the metadata for a single instance of @SpecAssertion
*
* @author Shane Bryzak
*/
public class SpecReference {
+
private String section;
private String assertion;
private String packageName;
private String className;
private String methodName;
+ private List<String> groups;
+
+ public SpecReference()
+ {
+ this.groups = new ArrayList<String>();
+ }
public void setSection(String section) {
this.section = section;
@@ -52,6 +62,11 @@
return methodName;
}
+ public List<String> getGroups()
+ {
+ return groups;
+ }
+
@Override
public String toString()
{
15 years, 11 months