Hibernate SVN: r10893 - in trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/generics: . dynamic
by hibernate-commits@lists.jboss.org
Author: nusco
Date: 2006-11-30 07:25:02 -0500 (Thu, 30 Nov 2006)
New Revision: 10893
Added:
trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/generics/dynamic/
trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/generics/dynamic/Book.java
trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/generics/dynamic/DynamicGenericsResolutionTest.java
trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/generics/dynamic/Edition.java
trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/generics/dynamic/Reprint.java
Log:
Test to expose ANN-494
Added: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/generics/dynamic/Book.java
===================================================================
--- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/generics/dynamic/Book.java 2006-11-30 10:35:57 UTC (rev 10892)
+++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/generics/dynamic/Book.java 2006-11-30 12:25:02 UTC (rev 10893)
@@ -0,0 +1,15 @@
+package org.hibernate.test.annotations.generics.dynamic;
+
+import javax.persistence.Embeddable;
+import javax.persistence.Id;
+
+@Embeddable
+public class Book {
+
+ @Id
+ public final String title;
+
+ public Book(String title) {
+ this.title = title;
+ }
+}
Added: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/generics/dynamic/DynamicGenericsResolutionTest.java
===================================================================
--- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/generics/dynamic/DynamicGenericsResolutionTest.java 2006-11-30 10:35:57 UTC (rev 10892)
+++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/generics/dynamic/DynamicGenericsResolutionTest.java 2006-11-30 12:25:02 UTC (rev 10893)
@@ -0,0 +1,53 @@
+package org.hibernate.test.annotations.generics.dynamic;
+
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.test.annotations.TestCase;
+
+public class DynamicGenericsResolutionTest extends TestCase {
+
+ Session session;
+
+ public void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void tearDown() throws Exception {
+ session.close();
+ super.tearDown();
+ }
+
+ private void clean(Class<?> clazz, String id) {
+ Transaction tx = session.beginTransaction();
+ session.delete( session.get( clazz, id ) );
+ tx.commit();
+ }
+
+ public void testDinamicallyResolvesGenericTypes() {
+ session = getSessions().openSession();
+ session.getTransaction().begin();
+ Book book = new Book( "The Naked Lunch" );
+ Edition<Book> edition = new Edition<Book>( "Second", book );
+ edition.originalDocument = book;
+
+ Reprint series = new Reprint( "Happy Joyful Christmas Readings" );
+ series.batch.add( edition );
+ persist( series );
+
+ clean( Reprint.class, series.name );
+ }
+
+ private void persist(Object data) {
+ session.persist( data );
+ session.getTransaction().commit();
+ session.clear();
+ }
+
+ protected Class[] getMappings() {
+ return new Class[]{
+ Book.class,
+ Edition.class,
+ Reprint.class
+ };
+ }
+}
Added: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/generics/dynamic/Edition.java
===================================================================
--- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/generics/dynamic/Edition.java 2006-11-30 10:35:57 UTC (rev 10892)
+++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/generics/dynamic/Edition.java 2006-11-30 12:25:02 UTC (rev 10893)
@@ -0,0 +1,18 @@
+package org.hibernate.test.annotations.generics.dynamic;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+@Entity
+public class Edition<T> {
+
+ @Id
+ public final String code;
+
+ public T originalDocument;
+
+ public Edition(String name, T originalDocument) {
+ this.code = name;
+ this.originalDocument = originalDocument;
+ }
+}
Added: trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/generics/dynamic/Reprint.java
===================================================================
--- trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/generics/dynamic/Reprint.java 2006-11-30 10:35:57 UTC (rev 10892)
+++ trunk/HibernateExt/metadata/src/test/org/hibernate/test/annotations/generics/dynamic/Reprint.java 2006-11-30 12:25:02 UTC (rev 10893)
@@ -0,0 +1,23 @@
+
+package org.hibernate.test.annotations.generics.dynamic;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+
+@Entity
+public class Reprint {
+
+ @Id
+ public final String name;
+
+ public Reprint(String name) {
+ this.name = name;
+ }
+
+ @OneToMany
+ Set<Edition<Book>> batch = new HashSet<Edition<Book>>();
+}
17 years, 12 months
Hibernate SVN: r10892 - in branches/Branch_3_2/HibernateExt/tools/src: java/org/hibernate/tool/hbm2x/pojo templates/pojo test/org/hibernate/tool/hbm2x
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)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-->
-(a)${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"/>
17 years, 12 months
Hibernate SVN: r10891 - branches/Branch_3_2/HibernateExt/tools/src/test5.0/org/hibernate/tool/hbm2x
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2006-11-30 05:34:36 -0500 (Thu, 30 Nov 2006)
New Revision: 10891
Modified:
branches/Branch_3_2/HibernateExt/tools/src/test5.0/org/hibernate/tool/hbm2x/Hbm2JavaEjb3ForJDK50Test.java
Log:
workaround not-null association.
Modified: branches/Branch_3_2/HibernateExt/tools/src/test5.0/org/hibernate/tool/hbm2x/Hbm2JavaEjb3ForJDK50Test.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test5.0/org/hibernate/tool/hbm2x/Hbm2JavaEjb3ForJDK50Test.java 2006-11-30 10:34:17 UTC (rev 10890)
+++ branches/Branch_3_2/HibernateExt/tools/src/test5.0/org/hibernate/tool/hbm2x/Hbm2JavaEjb3ForJDK50Test.java 2006-11-30 10:34:36 UTC (rev 10891)
@@ -201,6 +201,11 @@
Object puppetInst = puppet.newInstance();
puppet.getMethod( "setName", new Class[]{String.class} ).invoke( puppetInst, new Object[]{"Barbie"} );
+
+ if(className.equals("Bungalow")) { // hack to avoid not-null execption
+ puppet.getMethod("setMascot", new Class[] { puppet }).invoke( puppetInst, new Object[] { puppetInst } );
+ }
+
s.getTransaction().begin();
s.persist( puppetInst );
s.getTransaction().commit();
@@ -238,4 +243,8 @@
};
}
+ protected void tearDown() throws Exception {
+ // TODO Auto-generated method stub
+ //super.tearDown();
+ }
}
17 years, 12 months
Hibernate SVN: r10890 - branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2006-11-30 05:34:17 -0500 (Thu, 30 Nov 2006)
New Revision: 10890
Modified:
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/OracleViewsTest.java
Log:
force oraclemetadatadialect on oracle related test
Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/OracleViewsTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/OracleViewsTest.java 2006-11-30 10:33:09 UTC (rev 10889)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/test/jdbc2cfg/OracleViewsTest.java 2006-11-30 10:34:17 UTC (rev 10890)
@@ -9,6 +9,8 @@
import junit.framework.Test;
import junit.framework.TestSuite;
+import org.hibernate.cfg.JDBCMetaDataConfiguration;
+import org.hibernate.cfg.reveng.dialect.OracleMetaDataDialect;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.Oracle9Dialect;
import org.hibernate.mapping.PersistentClass;
@@ -55,6 +57,10 @@
return dialect instanceof Oracle9Dialect;
}
+ protected void configure(JDBCMetaDataConfiguration cfg) {
+ cfg.setProperty( "hibernatetool.metadatadialect", OracleMetaDataDialect.class.getName() );
+ }
+
public void testViewAndSynonyms() throws SQLException {
PersistentClass classMapping = cfg.getClassMapping(toClassName("basicview") );
assertNotNull(classMapping);
17 years, 12 months
Hibernate SVN: r10889 - branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ant
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2006-11-30 05:33:09 -0500 (Thu, 30 Nov 2006)
New Revision: 10889
Modified:
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ant/AntAllTests.java
branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ant/JavaFormatterTest.java
Log:
fix "too fast" test ;)
Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ant/AntAllTests.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ant/AntAllTests.java 2006-11-30 10:32:20 UTC (rev 10888)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ant/AntAllTests.java 2006-11-30 10:33:09 UTC (rev 10889)
@@ -10,7 +10,7 @@
//$JUnit-BEGIN$
suite.addTestSuite(HibernateToolTest.class);
suite.addTestSuite(SeamAntTest.class);
- suite.addTestSuite(JavaFormatterTask.class);
+ suite.addTestSuite(JavaFormatterTest.class);
//$JUnit-END$
return suite;
}
Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ant/JavaFormatterTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ant/JavaFormatterTest.java 2006-11-30 10:32:20 UTC (rev 10888)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ant/JavaFormatterTest.java 2006-11-30 10:33:09 UTC (rev 10889)
@@ -65,8 +65,16 @@
executeTarget("prepare");
formatter = new JavaFormatter(null);
+ try {
+ Thread.sleep(10);
+ }
+ catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
assertTrue("formatting should pass when using default settings", formatter.formatFile( file ));
+
assertTrue( before<file.lastModified() );
}
public void testAntxDestDir() {
17 years, 12 months
Hibernate SVN: r10888 - branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/doc
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2006-11-30 05:32:20 -0500 (Thu, 30 Nov 2006)
New Revision: 10888
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/doc/DocHelper.java
Log:
todo
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/doc/DocHelper.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/doc/DocHelper.java 2006-11-30 10:32:03 UTC (rev 10887)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/doc/DocHelper.java 2006-11-30 10:32:20 UTC (rev 10888)
@@ -139,8 +139,8 @@
this.cfg = cfg;
- dialect = Dialect.getDialect(cfg.getProperties() );
-
+ dialect = cfg.buildSettings().getDialect(); // TODO: get it from somewhere "cached".
+
Settings settings = cfg.buildSettings();
String defaultCatalog = settings.getDefaultCatalogName();
17 years, 12 months
Hibernate SVN: r10887 - branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/dialect
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2006-11-30 05:32:03 -0500 (Thu, 30 Nov 2006)
New Revision: 10887
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/dialect/AbstractMetaDataDialect.java
Log:
throw on close error
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/dialect/AbstractMetaDataDialect.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/dialect/AbstractMetaDataDialect.java 2006-11-30 10:31:29 UTC (rev 10886)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/dialect/AbstractMetaDataDialect.java 2006-11-30 10:32:03 UTC (rev 10887)
@@ -44,7 +44,7 @@
provider.closeConnection(connection);
}
catch (SQLException e) {
- getSQLExceptionConverter().convert(e, "Problem while closing connection", null);
+ throw getSQLExceptionConverter().convert(e, "Problem while closing connection", null);
} finally {
connection = null;
}
17 years, 12 months
Hibernate SVN: r10886 - branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2006-11-30 05:31:29 -0500 (Thu, 30 Nov 2006)
New Revision: 10886
Modified:
branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/JDBCReader.java
Log:
log
Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/JDBCReader.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/JDBCReader.java 2006-11-30 10:03:47 UTC (rev 10885)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/cfg/reveng/JDBCReader.java 2006-11-30 10:31:29 UTC (rev 10886)
@@ -192,14 +192,14 @@
String pkColumnName = (String) exportedKeyRs.get("PKCOLUMN_NAME");
String fkName = (String) exportedKeyRs.get("FK_NAME");
short keySeq = ((Short)exportedKeyRs.get("KEY_SEQ")).shortValue();
-
- log.debug("foreign key name: " + fkName);
Table fkTable = dbs.getTable(fkSchema, fkCatalog, fkTableName);
if(fkTable==null) {
// filter out stuff we don't have tables for!
log.debug("Foreign key " + fkName + " references unknown or filtered table " + Table.qualify(fkCatalog, fkSchema, fkTableName) );
continue;
+ } else {
+ log.debug("Foreign key " + fkName);
}
// TODO: if there is a relation to a column which is not a pk
17 years, 12 months
Hibernate SVN: r10885 - branches/Branch_3_2/HibernateExt/ejb-api/src/javax/persistence
by hibernate-commits@lists.jboss.org
Author: max.andersen(a)jboss.com
Date: 2006-11-30 05:03:47 -0500 (Thu, 30 Nov 2006)
New Revision: 10885
Modified:
branches/Branch_3_2/HibernateExt/ejb-api/src/javax/persistence/AttributeOverride.java
Log:
javadoc shuffled for name/column
Modified: branches/Branch_3_2/HibernateExt/ejb-api/src/javax/persistence/AttributeOverride.java
===================================================================
--- branches/Branch_3_2/HibernateExt/ejb-api/src/javax/persistence/AttributeOverride.java 2006-11-30 08:05:05 UTC (rev 10884)
+++ branches/Branch_3_2/HibernateExt/ejb-api/src/javax/persistence/AttributeOverride.java 2006-11-30 10:03:47 UTC (rev 10885)
@@ -23,12 +23,12 @@
@Target({TYPE, METHOD, FIELD}) @Retention(RUNTIME)
public @interface AttributeOverride {
/**
- * The column that is being mapped to the persistent attribute
+ * The name of the property whose mapping is being overridden if property-based access is being
+ * used, or the name of the field if field-based access is used.
*/
String name();
/**
- * The name of the property whose mapping is being overridden if property-based access is being
- * used, or the name of the field if field-based access is used.
+ * The column that is being mapped to the persistent attribute
*/
Column column();
}
17 years, 12 months
Hibernate SVN: r10884 - trunk/Hibernate3/doc/reference
by hibernate-commits@lists.jboss.org
Author: honma
Date: 2006-11-30 03:05:05 -0500 (Thu, 30 Nov 2006)
New Revision: 10884
Modified:
trunk/Hibernate3/doc/reference/build.xml
Log:
i duplicated comment out line of ja in all.doc target.
Modified: trunk/Hibernate3/doc/reference/build.xml
===================================================================
--- trunk/Hibernate3/doc/reference/build.xml 2006-11-30 03:43:15 UTC (rev 10883)
+++ trunk/Hibernate3/doc/reference/build.xml 2006-11-30 08:05:05 UTC (rev 10884)
@@ -41,9 +41,9 @@
<!-- TRANSLATOR: Duplicate this line for your language -->
<antcall target="lang.all"><param name="lang" value="en"/></antcall>
<antcall target="lang.all"><param name="lang" value="zh-cn"/></antcall>
+ <antcall target="lang.all"><param name="lang" value="ja"/></antcall>
<!-- TODO: These translations need updating...
<antcall target="lang.all"><param name="lang" value="es"/></antcall>
- <antcall target="lang.all"><param name="lang" value="ja"/></antcall>
<antcall target="lang.all"><param name="lang" value="fr"/></antcall>
<antcall target="lang.all"><param name="lang" value="ko"/></antcall>
-->
17 years, 12 months