[hibernate-commits] Hibernate SVN: r12852 - in branches/Branch_3_2/HibernateExt/tools/src: test/org/hibernate/tool/ant and 1 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Mon Jul 30 17:59:45 EDT 2007


Author: max.andersen at jboss.com
Date: 2007-07-30 17:59:45 -0400 (Mon, 30 Jul 2007)
New Revision: 12852

Added:
   branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Properties.hbm.xml
   branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/PropertiesTest.java
Modified:
   branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/EntityPOJOClass.java
   branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ant/AntHibernateToolTest.java
Log:
HBX-267 hbm2java handle properties (old commit that got lost)

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	2007-07-30 21:49:10 UTC (rev 12851)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/EntityPOJOClass.java	2007-07-30 21:59:45 UTC (rev 12852)
@@ -138,8 +138,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(); 
+		while(pit.hasNext())
+		{
+			Property element = (Property) pit.next();
+			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() );
-		iterators.add( pc.getPropertyIterator() );
+		
 		Iterator[] it = (Iterator[]) iterators.toArray( new Iterator[iterators.size()] );
 		return new SkipBackRefPropertyIterator( new JoinedIterator( it ) );
 	}

Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ant/AntHibernateToolTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ant/AntHibernateToolTest.java	2007-07-30 21:49:10 UTC (rev 12851)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ant/AntHibernateToolTest.java	2007-07-30 21:59:45 UTC (rev 12852)
@@ -94,7 +94,7 @@
 			fail("property overrides not accepted");
 		} catch (BuildException be) {
 			// should happen
-			assertTrue(be.getMessage().indexOf("FAKEDialect")>0);			
+			assertTrue(be.getMessage(), be.getMessage().indexOf("FAKEDialect")>0);			
 		}
 	}
 	

Added: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Properties.hbm.xml
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Properties.hbm.xml	                        (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/Properties.hbm.xml	2007-07-30 21:59:45 UTC (rev 12852)
@@ -0,0 +1,51 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC 
+	"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+	"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<!-- 
+
+  This mapping is a test mapping for hbm2java
+     
+-->
+
+<hibernate-mapping package="properties">
+
+    <class name="PPerson">
+    	<id name="id" type="string">
+    		<generator class="native"/>
+    	</id>
+
+    	<property name="name" type="string" not-null="true"/>
+    	
+    	<properties name="emergencyContact" unique="true">
+    		<property name="contact" type="boolean" not-null="true"/>
+    		<many-to-one name="company" class="PCompany"/>
+    	</properties>
+    </class>
+    	
+    <class name="PCompany">
+    	<id name="id" type="string">
+    		<generator class="native"/>
+    	</id>
+
+    	<property name="brand" type="string" not-null="true"/>
+    	
+    	<set name="employees" inverse="true">
+    	  <key>
+    	    <column name="company_id"/>
+    	  </key>
+    	  <one-to-many class="PPerson"/>
+    	</set>
+    	
+<!-- 	<one-to-one name="emergencyContact" class="Person"
+		property-ref="emergencyContact">
+		<formula>'true'</formula>
+		<formula>id</formula>
+	</one-to-one> -->
+
+    </class>
+    
+</hibernate-mapping>
+
+

Added: 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	                        (rev 0)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/PropertiesTest.java	2007-07-30 21:59:45 UTC (rev 12852)
@@ -0,0 +1,83 @@
+/*
+ * Created on 2004-12-01
+ *
+ */
+package org.hibernate.tool.hbm2x;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.tool.NonReflectiveTestCase;
+import org.hibernate.tool.hbm2x.pojo.EntityPOJOClass;
+import org.hibernate.tool.hbm2x.pojo.POJOClass;
+import org.hibernate.tool.test.TestHelper;
+
+/**
+ * @author Josh Moore josh.moore at gmx.de
+ * 
+ */
+public class PropertiesTest extends NonReflectiveTestCase {
+
+	private ArtifactCollector artifactCollector;
+	
+	public PropertiesTest(String name) {
+		super( name, "hbm2javaoutput" );
+	}
+
+	protected void setUp() throws Exception {
+		super.setUp();
+
+		artifactCollector = new ArtifactCollector();
+		
+		Exporter exporter = new POJOExporter( getCfg(), getOutputDir() );
+		exporter.setArtifactCollector(artifactCollector);
+		
+		Exporter hbmexporter = new HibernateMappingExporter(getCfg(), getOutputDir());
+		hbmexporter.setArtifactCollector(artifactCollector);
+		
+		exporter.start();
+		hbmexporter.start();
+	}	
+	
+	public void testNoGenerationOfEmbeddedPropertiesComponent() {
+		assertEquals(2, artifactCollector.getFileCount("java"));
+		assertEquals(2, artifactCollector.getFileCount("hbm.xml"));
+	}
+	
+	public void testGenerationOfEmbeddedProperties() {
+		
+		// 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" )));		
+	}
+	
+	public void testCompilable() {
+
+		File file = new File( "compilable" );
+		file.mkdir();
+
+		ArrayList list = new ArrayList();
+		list.add( new File( "src/testoutputdependent/properties/PropertiesUsage.java" )
+				.getAbsolutePath() );		
+		TestHelper.compile( getOutputDir(), file, TestHelper.visitAllFiles(
+				getOutputDir(), list ) );
+
+		TestHelper.deleteDir( file );
+	}
+
+	protected String getBaseForMappings() {
+		return "org/hibernate/tool/hbm2x/";
+	}
+
+	protected String[] getMappings() {
+		return new String[] { "Properties.hbm.xml" };
+	}
+
+
+}




More information about the hibernate-commits mailing list