[hibernate-commits] Hibernate SVN: r10892 - in branches/Branch_3_2/HibernateExt/tools/src: java/org/hibernate/tool/hbm2x/pojo templates/pojo test/org/hibernate/tool/hbm2x

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Thu Nov 30 05:36:06 EST 2006


Author: max.andersen at jboss.com
Date: 2006-11-30 05:35:57 -0500 (Thu, 30 Nov 2006)
New Revision: 10892

Added:
   branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/AnnotationBuilder.java
Modified:
   branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/EntityPOJOClass.java
   branches/Branch_3_2/HibernateExt/tools/src/templates/pojo/Ejb3PropertyGetAnnotation.ftl
   branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Hbm2JavaEjb3Test.java
   branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Passenger.hbm.xml
   branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Puppet.hbm.xml
Log:
Use AnnotationBuilder instead of crude string manipulations

Added: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/AnnotationBuilder.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/AnnotationBuilder.java	2006-11-30 10:34:36 UTC (rev 10891)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/AnnotationBuilder.java	2006-11-30 10:35:57 UTC (rev 10892)
@@ -0,0 +1,124 @@
+package org.hibernate.tool.hbm2x.pojo;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+public class AnnotationBuilder {
+
+	String annotation;
+	LinkedHashMap attributes = new LinkedHashMap(); 
+	
+	public static AnnotationBuilder createAnnotation(String annotation) {
+		return new AnnotationBuilder(annotation);
+	}
+	
+	protected AnnotationBuilder(String annotation) {
+		this.annotation = annotation;
+	}
+
+	public AnnotationBuilder addAttribute(String name, String[] values) {
+		if(values!=null && values.length > 0) {				
+			attributes.put(name, values);
+		}
+		return this;
+	}
+
+	public AnnotationBuilder addAttribute(String name, String value) {
+		if(value!=null) {
+			addAttribute(name, new String[] { value });
+		}
+		return this;
+	}
+	
+	
+	public AnnotationBuilder resetAnnotation(String annotation) {
+		this.annotation = annotation;
+		clearAttributes();
+		return this;
+	}
+	
+	private AnnotationBuilder clearAttributes() {
+		attributes.clear();
+		return this;
+	}
+	
+	public String getResult() {
+		StringBuffer b = new StringBuffer("@");
+		b.append(annotation);
+		if(attributes.isEmpty()) {
+			return b.toString();
+		} else {
+			b.append("(");
+			Iterator elements = attributes.entrySet().iterator();
+			boolean addedBefore = false;
+			while ( elements.hasNext() ) {
+				Map.Entry element = (Map.Entry) elements.next();
+
+				String[] s = (String[]) element.getValue();
+				if(s.length==0) {
+					addedBefore = false;
+					continue;
+				} else {
+					if(addedBefore) {
+						b.append(", ");
+					}
+					b.append(element.getKey()).append("=");
+					if(s.length>1) {
+						b.append( "{" );
+					}
+					for (int i = 0; i < s.length; i++) {
+						b.append(s[i]);
+						if(i<s.length-1) {
+							b.append(", ");
+						}
+					}
+					if(s.length>1) {
+						b.append( "}" );
+					}
+					addedBefore=true;
+				}
+			}
+			b.append( ")" );
+		}
+		return b.toString();
+	}
+
+	public void addQuotedAttributes(String name, Iterator iterator) {
+		List values = new ArrayList();
+		while ( iterator.hasNext() ) {
+			String element = iterator.next().toString();
+			values.add(quote( element ));
+		}
+		addAttribute(name, (String[]) values.toArray( new String[values.size()] ));
+	}
+
+	public void addAttributes(String name, Iterator iterator) {
+		List values = new ArrayList();
+		while ( iterator.hasNext() ) {
+			String element = iterator.next().toString();
+			values.add( element );
+		}
+		addAttribute(name, (String[]) values.toArray( new String[values.size()] ));		
+	}
+	private String quote(String element) {
+		return "\"" + element + "\"";
+	}
+
+	public AnnotationBuilder addQuotedAttribute(String name, String value) {
+		if(value!=null) {
+			addAttribute(name, quote(value));
+		}
+		return this;
+	}
+	
+
+	public String toString() {
+		return getResult();
+	}
+
+	
+}
+

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	2006-11-30 10:34:36 UTC (rev 10891)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/EntityPOJOClass.java	2006-11-30 10:35:57 UTC (rev 10892)
@@ -178,24 +178,18 @@
 			if (table.hasPrimaryKey() && table.getPrimaryKey().getColumns().equals(key.getColumns())) {
 				continue;
 			}
-			
-			String constraint = importType("javax.persistence.UniqueConstraint");
-			constraints.append( "@" + constraint + "( columnNames = { " );
-			
-			Iterator columns = key.getColumnIterator();
-			while ( columns.hasNext() ) {
-				constraints.append( "\"" + ( (Column) columns.next() ).getName() + "\"" )
-						.append( ", " );
-			}
-			constraints.setLength( constraints.length() - 2 );
-			constraints.append( " } ), " );
+			AnnotationBuilder constraint = AnnotationBuilder.createAnnotation( importType("javax.persistence.UniqueConstraint") );
+			constraint.addQuotedAttributes( "columnNames", new IteratorTransformer(key.getColumnIterator()) {
+				public Object transform(Object object) {					
+					return ((Column)object).getName();
+				}
+			});
+			constraints.append(constraint.getResult());
 		}
-		if ( constraints.length() != 0 ) {
-			constraints.setLength( constraints.length() - 2 );
-		}
 		return constraints.toString();
 	}
 
+		
 	public String generateAnnIdGenerator() {
 		KeyValue identifier = clazz.getIdentifier();
 		String strategy = null;
@@ -203,109 +197,106 @@
 		StringBuffer wholeString = new StringBuffer( "    " );
 		if ( identifier instanceof Component ) {
 
-			wholeString.append( "@" + importType("javax.persistence.EmbeddedId") );
+			wholeString.append( AnnotationBuilder.createAnnotation( importType("javax.persistence.EmbeddedId") ).getResult());
 		}
 		else if ( identifier instanceof SimpleValue ) {
 			SimpleValue simpleValue = (SimpleValue) identifier;
 			strategy = simpleValue.getIdentifierGeneratorStrategy();
 			properties = simpleValue.getIdentifierGeneratorProperties();
-			StringBuffer id = new StringBuffer().append("@").append( importType("javax.persistence.Id") );
+			StringBuffer idResult = new StringBuffer();
+			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 ) ) { 
-				id.append(" @").append( importType("javax.persistence.GeneratedValue") );
-				if ( !"native".equals( strategy ) ) {
-					id.append('(');
+			if ( !"assigned".equals( strategy ) ) {
+								
+				if ( !"native".equals( strategy ) ) {					
 					if ( "identity".equals( strategy ) ) {
-						id.append("strategy=");
-						id.append( staticImport("javax.persistence.GenerationType", "IDENTITY" ) );
+						builder.resetAnnotation( importType("javax.persistence.GeneratedValue") );
+						builder.addAttribute( "strategy", staticImport("javax.persistence.GenerationType", "IDENTITY" ) );
+						idResult.append(builder.getResult());
 					}
 					else if ( "sequence".equals( strategy ) ) {
-						id.append("strategy=");
-						id.append( staticImport("javax.persistence.GenerationType", "SEQUENCE") )
-								.append( ", generator=\"generator\"" );
-						buildAnnSequenceGenerator( wholeString, properties );
+						builder.resetAnnotation( importType("javax.persistence.GeneratedValue") )
+							.addAttribute( "strategy", staticImport("javax.persistence.GenerationType", "SEQUENCE" ) )
+						    .addQuotedAttribute( "generator", "generator" );
+						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 ) );
+							//	TODO HA does not support initialValue and allocationSize
+						wholeString.append( builder.getResult() );
 					}
 					else if ( MultipleHiLoPerTableGenerator.class.getName().equals( strategy ) ) {
-						id.append("strategy=");
-						id.append( staticImport("javax.persistence.GenerationType", "TABLE") )
-								.append( ", generator=\"generator\"" );
+						builder.resetAnnotation( importType("javax.persistence.GeneratedValue") )
+						.addAttribute( "strategy", staticImport("javax.persistence.GenerationType", "TABLE" ) )
+					    .addQuotedAttribute( "generator", "generator" );
+						idResult.append(builder.getResult());
 						buildAnnTableGenerator( wholeString, properties );
 					}
 					else {
 						isGenericGenerator = true;
-						id.append( "generator=\"generator\"" );
-
-					}
-					id.append(')');
+						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());
 				}
 			}
 			if ( isGenericGenerator ) {
-				wholeString.append( "@" + importType("org.hibernate.annotations.GenericGenerator"))
-						.append( "(name=\"generator\", strategy=\"" )
-						.append( strategy )
-						.append( "\", " );
-				wholeString.append( "parameters = {  " );
+				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();
-						wholeString.append( "@" + importType("org.hibernate.annotations.Parameter"))
-								.append( "(name=\"" )
-								.append( propertyName )
-								.append( "\", " )
-								.append( "value=\"" )
-								.append( properties.getProperty( propertyName ) )
-								.append( "\"), " );
+						AnnotationBuilder parameter = AnnotationBuilder.createAnnotation( importType("org.hibernate.annotations.Parameter") )
+									.addQuotedAttribute( "name", propertyName )
+									.addQuotedAttribute( "value", properties.getProperty( propertyName ) );
+						params.add( parameter );						
 					}
 				}
-				wholeString.setLength( wholeString.length() - 2 );
-				wholeString.append( " } )\n" );
+				builder.addAttributes( "parameters", params.iterator() );
+				wholeString.append(builder.getResult());
 			}
-			wholeString.append( id );
+			wholeString.append( idResult );
 		}
 		return wholeString.toString();
-	}
+	}	
 
-	private void buildAnnSequenceGenerator(StringBuffer wholeString, Properties properties) {
-		wholeString.append( "@" + importType("javax.persistence.SequenceGenerator") + "(name=\"generator\", sequenceName=\"" )
-				.append( properties.getProperty( org.hibernate.id.SequenceGenerator.SEQUENCE, "" ) )
-				.append( "\")" );
-		//TODO HA does not support initialValue and allocationSize
-		wholeString.append( "\n    " );
-	}
-
 	private void buildAnnTableGenerator(StringBuffer wholeString, Properties properties) {
-		wholeString.append( "@" + importType("javax.persistence.TableGenerator") + "(name=\"generator\", table=\"" )
-				.append( properties.getProperty( "generatorTableName", "hibernate_sequences" ) )
-				.append("\"");
+		
+		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 ) ) {
-			wholeString.append(", catalog=\"")
-				.append( properties.getProperty( PersistentIdentifierGenerator.CATALOG, "") );
+			builder.addQuotedAttribute( "catalog", properties.getProperty( PersistentIdentifierGenerator.CATALOG, "") );			
 		}
 		if ( ! isPropertyDefault( PersistentIdentifierGenerator.SCHEMA, properties ) ) {
-			wholeString.append(", schema=\"")
-				.append( properties.getProperty( PersistentIdentifierGenerator.SCHEMA, "") );
+			builder.addQuotedAttribute( "schema", properties.getProperty( PersistentIdentifierGenerator.SCHEMA, "") );			
 		}
 		if (! isPropertyDefault( MultipleHiLoPerTableGenerator.PK_VALUE_NAME, properties ) ) {
-			wholeString.append(", pkColumnValue=\"")
-					.append(properties.getProperty( MultipleHiLoPerTableGenerator.PK_VALUE_NAME, "" ) ).append("\"");
+			builder.addQuotedAttribute( "pkColumnValue", properties.getProperty( MultipleHiLoPerTableGenerator.PK_VALUE_NAME, "") );			
 		}
 		if ( ! isPropertyDefault( MultipleHiLoPerTableGenerator.MAX_LO, properties, "50" ) ) {
-			wholeString.append(", allocationSize=")
-					.append(properties.getProperty( MultipleHiLoPerTableGenerator.MAX_LO, "50" ) );
+			builder.addAttribute( "allocationSize", properties.getProperty( MultipleHiLoPerTableGenerator.MAX_LO, "50" ) );
 		}
 		if (! isPropertyDefault( MultipleHiLoPerTableGenerator.PK_COLUMN_NAME, properties ) ) {
-			wholeString.append(", pkColumnName=\"")
-					.append( properties.getProperty( MultipleHiLoPerTableGenerator.PK_COLUMN_NAME, "" ) )
-					.append( "\"");
+			builder.addQuotedAttribute( "pkColumnName", properties.getProperty( MultipleHiLoPerTableGenerator.PK_COLUMN_NAME, "") );			
 		}
 		if (! isPropertyDefault( MultipleHiLoPerTableGenerator.VALUE_COLUMN_NAME, properties ) ) {
-			wholeString.append( ", valueColumnName=\"")
-					.append( properties.getProperty( MultipleHiLoPerTableGenerator.VALUE_COLUMN_NAME, "" ) )
-					.append("\"");
+			builder.addQuotedAttribute( "valueColumnName", properties.getProperty( MultipleHiLoPerTableGenerator.VALUE_COLUMN_NAME, "") );
 		}
-		wholeString.append( ")\n    " );
+		wholeString.append( builder.getResult() + "\n    " );
 	}
 
 	private boolean isPropertyDefault(String property, Properties properties) {
@@ -383,41 +374,40 @@
 			//TODO support secondary table
 			annotations.append( ")" );
 		}
-	}
-
-	public String getCascadeType(Property property) {
+	}	
+	
+	public String[] getCascadeTypes(Property property) {
 		StringTokenizer st =  new StringTokenizer( property.getCascade(), ", ", false );
-		String cascadeType = null;
-		StringBuffer cascade = new StringBuffer();
+		List types = new ArrayList();
 		while ( st.hasMoreElements() ) {
 			String element = ( (String) st.nextElement() ).toLowerCase();
 			if ( "persist".equals( element ) ) {
-				if (cascadeType == null) cascadeType = importType( "javax.persistence.CascadeType");
-				cascade.append( cascadeType ).append(".PERSIST").append(", ");
+				types.add(importType( "javax.persistence.CascadeType" ) + ".PERSIST");				
 			}
 			else if ( "merge".equals( element ) ) {
-				if (cascadeType == null) cascadeType = importType( "javax.persistence.CascadeType");
-				cascade.append( cascadeType ).append(".MERGE").append(", ");
+				types.add(importType( "javax.persistence.CascadeType") + ".MERGE");
 			}
 			else if ( "delete".equals( element ) ) {
-				if (cascadeType == null) cascadeType = importType( "javax.persistence.CascadeType");
-				cascade.append( cascadeType ).append(".REMOVE").append(", ");
-			}
+				types.add(importType( "javax.persistence.CascadeType") + ".REMOVE");
+			}			
 			else if ( "refresh".equals( element ) ) {
-				if (cascadeType == null) cascadeType = importType( "javax.persistence.CascadeType");
-				cascade.append( cascadeType ).append(".REFRESH").append(", ");
+				types.add(importType( "javax.persistence.CascadeType") + ".REFRESH");
 			}
 			else if ( "all".equals( element ) ) {
-				if (cascadeType == null) cascadeType = importType( "javax.persistence.CascadeType");
-				cascade.append( cascadeType ).append(".ALL").append(", ");
+				types.add(importType( "javax.persistence.CascadeType") + ".ALL");
 			}
 		}
-		if ( cascade.length() >= 2 ) {
-			cascade.setLength( cascade.length() - 2 );
-		}
-		return cascade.toString();
+		return (String[]) types.toArray( new String[types.size()] );
 	}
 
+	public String generateManyToOneAnnotation(Property property) {
+		StringBuffer buffer = new StringBuffer(AnnotationBuilder.createAnnotation( importType("javax.persistence.ManyToOne") )
+				.addAttribute( "cascade", getCascadeTypes(property))
+				.addAttribute( "fetch", getFetchType(property))
+				.getResult());
+		buffer.append(getHibernateCascadeTypeAnnotation(property));
+		return buffer.toString();
+	}
 	public String getHibernateCascadeTypeAnnotation(Property property) {
 		StringTokenizer st =  new StringTokenizer( property.getCascade(), ", ", false );
 		String cascadeType = null;
@@ -493,30 +483,30 @@
 			Collection collection = (Collection) value;
 			if ( collection.isOneToMany() ) {
 				String mappedBy = null;
-				annotation.append("    @").append( importType( "javax.persistence.OneToMany") )
-						.append( "(cascade={").append(getCascadeType( property ) ).append("}")
-						.append(", fetch=").append( getFetchType( property ) );
+				AnnotationBuilder ab = AnnotationBuilder.createAnnotation( importType( "javax.persistence.OneToMany") );
+				ab.addAttribute( "cascade", getCascadeTypes( property ) );
+				ab.addAttribute( "fetch", getFetchType (property) );
 				if ( collection.isInverse() ) {
-					annotation.append(", mappedBy=\"");
 					mappedBy = getOneToManyMappedBy( cfg, collection );
-					annotation.append( mappedBy ).append("\"");
+					ab.addQuotedAttribute( "mappedBy", mappedBy );					
 				}
-				annotation.append(")");
+				annotation.append( ab.getResult() );
+				
 				if (mappedBy == null) annotation.append("\n").append( generateJoinColumnsAnnotation(property) );
 			}
 			else {
 				//TODO do the @OneToMany @JoinTable
 				//TODO composite element
 				String mappedBy = null;
-				annotation.append("    @").append( importType( "javax.persistence.ManyToMany") )
-						.append( "(cascade={").append(getCascadeType( property ) ).append("}")
-						.append(", fetch=").append( getFetchType( property ) );
+				AnnotationBuilder ab = AnnotationBuilder.createAnnotation( importType( "javax.persistence.ManyToMany") );
+				ab.addAttribute( "cascade", getCascadeTypes( property ) );
+				ab.addAttribute( "fetch", getFetchType (property) );
+				
 				if ( collection.isInverse() ) {
-					annotation.append(", mappedBy=\"");
 					mappedBy = getManyToManyMappedBy( cfg, collection );
-					annotation.append( mappedBy ).append("\"");
+					ab.addQuotedAttribute( "mappedBy", mappedBy );					
 				}
-				annotation.append(")");
+				annotation.append(ab.getResult());
 				if (mappedBy == null) {
 					annotation.append("\n    @");
 					annotation.append( importType( "javax.persistence.JoinTable") ).append( "(name=\"" );
@@ -800,4 +790,28 @@
 	{
 		return clazz.getVersion();
 	}
+	
+	public abstract class IteratorTransformer implements Iterator {
+
+		private Iterator delegate;
+
+		IteratorTransformer(Iterator delegate) {
+			this.delegate = delegate;
+		}
+		
+		public boolean hasNext() {
+			return delegate.hasNext();
+		}
+
+		public Object next() {
+			return transform(delegate.next());
+		}
+
+		public abstract Object transform(Object object);
+
+		public void remove() {
+			delegate.remove();			
+		}		
+	}
+	
 }

Modified: branches/Branch_3_2/HibernateExt/tools/src/templates/pojo/Ejb3PropertyGetAnnotation.ftl
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/templates/pojo/Ejb3PropertyGetAnnotation.ftl	2006-11-30 10:34:36 UTC (rev 10891)
+++ branches/Branch_3_2/HibernateExt/tools/src/templates/pojo/Ejb3PropertyGetAnnotation.ftl	2006-11-30 10:35:57 UTC (rev 10892)
@@ -8,9 +8,7 @@
 </#if>
 <#if c2h.isManyToOne(property)>
 <#--TODO support @OneToOne true and false-->    
-@${pojo.importType("javax.persistence.ManyToOne")}(cascade={${pojo.getCascadeType(property)}},
-        fetch=${pojo.getFetchType(property)})
-    ${pojo.getHibernateCascadeTypeAnnotation(property)}
+${pojo.generateManyToOneAnnotation(property)}
 <#--TODO support optional and targetEntity-->    
 ${pojo.generateJoinColumnsAnnotation(property)}
 <#elseif c2h.isCollection(property)>

Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Hbm2JavaEjb3Test.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Hbm2JavaEjb3Test.java	2006-11-30 10:34:36 UTC (rev 10891)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Hbm2JavaEjb3Test.java	2006-11-30 10:35:57 UTC (rev 10892)
@@ -11,6 +11,8 @@
 import org.hibernate.mapping.PersistentClass;
 import org.hibernate.mapping.Property;
 import org.hibernate.tool.NonReflectiveTestCase;
+import org.hibernate.tool.hbm2x.pojo.AnnotationBuilder;
+import org.hibernate.tool.hbm2x.pojo.EntityPOJOClass;
 import org.hibernate.tool.hbm2x.pojo.POJOClass;
 import org.hibernate.tool.test.TestHelper;
 
@@ -157,11 +159,55 @@
 		
 	}
 	
+	public void testEmptyCascade() {
+		PersistentClass classMapping = getCfg().getClassMapping("org.hibernate.tool.hbm2x.Article");
+		
+		Cfg2JavaTool cfg2java = new Cfg2JavaTool();
+		EntityPOJOClass clazz = (EntityPOJOClass) cfg2java.getPOJOClass(classMapping);
+		Property property = classMapping.getProperty( "author" );
+		
+		assertEquals(0, clazz.getCascadeTypes( property ).length);
+		
+		assertEquals(null,findFirstString( "cascade={}", new File(getOutputDir(), "org/hibernate/tool/hbm2x/Article.java") ));
+	}
+		
+	public void testAnnotationBuilder() {
+
+		AnnotationBuilder builder =  AnnotationBuilder.createAnnotation("SingleCleared").resetAnnotation( "Single" );
+		
+		assertEquals("@Single", builder.getResult());
+		
+		builder = AnnotationBuilder.createAnnotation("javax.persistence.OneToMany")
+				    .addAttribute("willbecleared", (String)null)
+				    .resetAnnotation("javax.persistence.OneToMany")
+					.addAttribute("cascade", new String[] { "val1", "val2"})
+					.addAttribute("fetch", "singleValue");
+		
+		assertEquals("@javax.persistence.OneToMany(cascade={val1, val2}, fetch=singleValue)", builder.getResult());
+		
+		builder = AnnotationBuilder.createAnnotation("javax.persistence.OneToMany");
+		builder.addAttribute("cascade", (String[])null);
+		builder.addAttribute("fetch", (String)null);
+		
+		assertEquals("@javax.persistence.OneToMany", builder.getResult());
+
+		builder = AnnotationBuilder.createAnnotation("abc");
+		ArrayList list = new ArrayList();
+		list.add(new Integer(42));
+		list.add( new String("xxx") );
+		builder.addQuotedAttributes( "it", list.iterator() );
+		
+		assertEquals("@abc(it={\"42\", \"xxx\"})", builder.getResult());		
+	
+	}
+	
 	protected void tearDown() throws Exception {
 		
 		//super.tearDown();
 	}
 	
+	
+	
 	protected String getBaseForMappings() {
 		return "org/hibernate/tool/hbm2x/";
 	}

Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Passenger.hbm.xml
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Passenger.hbm.xml	2006-11-30 10:34:36 UTC (rev 10891)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Passenger.hbm.xml	2006-11-30 10:35:57 UTC (rev 10892)
@@ -14,7 +14,7 @@
             </generator>
         </id>
 
-        <property name="familyName" type="string" not-null="true" length="10000"/>
+        <property name="familyName" type="string" not-null="true" length="234"/>
 
 		<many-to-one
 		    name="currentTrain"

Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Puppet.hbm.xml
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Puppet.hbm.xml	2006-11-30 10:34:36 UTC (rev 10891)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Puppet.hbm.xml	2006-11-30 10:35:57 UTC (rev 10892)
@@ -9,7 +9,11 @@
     <class name="Puppet">
 
     	<id name="id" type="integer">
-            <generator class="increment"/>
+            <generator class="increment">
+            	<param name="testkey">avalue</param>
+            	     	<param name="testkey">avalue</param>
+            	     	<param name="testkey2">avalue2</param>
+            </generator>
         </id>
 
         <property name="name" type="string" not-null="true" length="100"/>




More information about the hibernate-commits mailing list