Author: hardy.ferentschik
Date: 2009-07-10 05:30:57 -0400 (Fri, 10 Jul 2009)
New Revision: 17062
Added:
jpamodelgen/trunk/test/src/main/java/model/xmlmapped/LivingBeing.java
jpamodelgen/trunk/test/src/main/java/model/xmlmapped/Mammal.java
jpamodelgen/trunk/test/src/main/resources/model/
jpamodelgen/trunk/test/src/main/resources/model/xmlmapped/
jpamodelgen/trunk/test/src/main/resources/model/xmlmapped/address.xml
jpamodelgen/trunk/test/src/main/resources/model/xmlmapped/building.xml
jpamodelgen/trunk/test/src/main/resources/model/xmlmapped/mammal.xml
Removed:
jpamodelgen/trunk/test/src/main/resources/META-INF/address.xml
jpamodelgen/trunk/test/src/main/resources/META-INF/building.xml
Modified:
jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/xml/XmlMetaEntity.java
jpamodelgen/trunk/test/src/main/resources/META-INF/order.xml
jpamodelgen/trunk/test/src/main/resources/META-INF/persistence.xml
jpamodelgen/trunk/test/src/test/java/tests/XmlMappingTest.java
Log:
some more xml based tests
Modified:
jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/xml/XmlMetaEntity.java
===================================================================
---
jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/xml/XmlMetaEntity.java 2009-07-10
07:12:22 UTC (rev 17061)
+++
jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/xml/XmlMetaEntity.java 2009-07-10
09:30:57 UTC (rev 17062)
@@ -72,9 +72,6 @@
importContext = new ImportContextImpl( getPackageName() );
this.element = element;
Attributes attributes = ormEntity.getAttributes();
- Id id = attributes.getId().get( 0 );
- XmlMetaSingleAttribute attribute = new XmlMetaSingleAttribute( this, id.getName(),
getType( id.getName() ) );
- members.add( attribute );
parseAttributes( attributes );
}
@@ -193,11 +190,11 @@
break;
}
case DECLARED: {
- typeName = ( ( DeclaredType ) elem.asType() ).toString();
+ typeName = elem.asType().toString();
break;
}
case TYPEVAR: {
- typeName = ( ( DeclaredType ) elem.asType() ).toString();
+ typeName = elem.asType().toString();
break;
}
}
@@ -218,6 +215,16 @@
private void parseAttributes(Attributes attributes) {
XmlMetaSingleAttribute attribute;
+
+ if ( !attributes.getId().isEmpty() ) {
+ // TODO what do we do if there are more than one id nodes?
+ Id id = attributes.getId().get( 0 );
+ attribute = new XmlMetaSingleAttribute(
+ this, id.getName(), getType( id.getName() )
+ );
+ members.add( attribute );
+ }
+
for ( Basic basic : attributes.getBasic() ) {
attribute = new XmlMetaSingleAttribute( this, basic.getName(), getType(
basic.getName() ) );
members.add( attribute );
Copied: jpamodelgen/trunk/test/src/main/java/model/xmlmapped/LivingBeing.java (from rev
17061, jpamodelgen/trunk/test/src/main/java/model/LivingBeing.java)
===================================================================
--- jpamodelgen/trunk/test/src/main/java/model/xmlmapped/LivingBeing.java
(rev 0)
+++ jpamodelgen/trunk/test/src/main/java/model/xmlmapped/LivingBeing.java 2009-07-10
09:30:57 UTC (rev 17062)
@@ -0,0 +1,17 @@
+package model.xmlmapped;
+
+public class LivingBeing {
+ boolean isReallyAlive;
+
+ public boolean isReallyAlive() {
+ return isReallyAlive;
+ }
+
+ public void setReallyAlive(boolean reallyAlive) {
+ isReallyAlive = reallyAlive;
+ }
+
+ public int nonPersistent() {
+ return 0;
+ }
+}
\ No newline at end of file
Copied: jpamodelgen/trunk/test/src/main/java/model/xmlmapped/Mammal.java (from rev 17061,
jpamodelgen/trunk/test/src/main/java/model/Mammals.java)
===================================================================
--- jpamodelgen/trunk/test/src/main/java/model/xmlmapped/Mammal.java
(rev 0)
+++ jpamodelgen/trunk/test/src/main/java/model/xmlmapped/Mammal.java 2009-07-10 09:30:57
UTC (rev 17062)
@@ -0,0 +1,23 @@
+package model.xmlmapped;
+
+
+public class Mammal extends LivingBeing {
+ private String id;
+ private String subclass;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getSubclass() {
+ return subclass;
+ }
+
+ public void setSubclass(String subclass) {
+ this.subclass = subclass;
+ }
+}
\ No newline at end of file
Deleted: jpamodelgen/trunk/test/src/main/resources/META-INF/address.xml
===================================================================
--- jpamodelgen/trunk/test/src/main/resources/META-INF/address.xml 2009-07-10 07:12:22 UTC
(rev 17061)
+++ jpamodelgen/trunk/test/src/main/resources/META-INF/address.xml 2009-07-10 09:30:57 UTC
(rev 17062)
@@ -1,18 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<entity-mappings
xmlns="http://java.sun.com/xml/ns/persistence/orm"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm
orm_2_0.xsd"
- version="2.0"
- >
- <!-- careful old JPA1 schema -->
- <package>model.xmlmapped</package> <!-- default package -->
- <embeddable class="Address" access="FIELD"
metadata-complete="true"> <!--means ignore annotations-->
- <attributes>
- <basic name="street1"/>
- <basic name="city"/>
- <basic name="country"/>
- </attributes>
- </embeddable>
-</entity-mappings>
-
Deleted: jpamodelgen/trunk/test/src/main/resources/META-INF/building.xml
===================================================================
--- jpamodelgen/trunk/test/src/main/resources/META-INF/building.xml 2009-07-10 07:12:22
UTC (rev 17061)
+++ jpamodelgen/trunk/test/src/main/resources/META-INF/building.xml 2009-07-10 09:30:57
UTC (rev 17062)
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<entity-mappings
xmlns="http://java.sun.com/xml/ns/persistence/orm"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm
orm_2_0.xsd"
- version="2.0"
- >
- <!-- careful old JPA1 schema -->
- <package>model.xmlmapped</package>
- <!-- default package -->
- <mapped-superclass class="Building" access="FIELD"
metadata-complete="true"> <!--means ignore annotations-->
- <attributes>
- <one-to-one name="address" fetch="LAZY"/>
- </attributes>
- </mapped-superclass>
-</entity-mappings>
-
Modified: jpamodelgen/trunk/test/src/main/resources/META-INF/order.xml
===================================================================
--- jpamodelgen/trunk/test/src/main/resources/META-INF/order.xml 2009-07-10 07:12:22 UTC
(rev 17061)
+++ jpamodelgen/trunk/test/src/main/resources/META-INF/order.xml 2009-07-10 09:30:57 UTC
(rev 17062)
@@ -5,15 +5,14 @@
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm
orm_2_0.xsd"
version="2.0"
- <!-- careful old JPA1 schema -->
<package>model</package> <!-- default package -->
<entity class="Order" access="FIELD"
metadata-complete="true"> <!--means ignore annotations-->
<attributes>
<id name="id">
<column name="fld_id"/>
</id>
- <basic name="filled"></basic>
- <basic name="date"></basic>
+ <basic name="filled"/>
+ <basic name="date"/>
<one-to-many name="items" target-entity="Item"
fetch="EAGER"> <!-- target-entity optional guess the type from the
geenric-->
<cascade>
<cascade-persist/>
Modified: jpamodelgen/trunk/test/src/main/resources/META-INF/persistence.xml
===================================================================
--- jpamodelgen/trunk/test/src/main/resources/META-INF/persistence.xml 2009-07-10 07:12:22
UTC (rev 17061)
+++ jpamodelgen/trunk/test/src/main/resources/META-INF/persistence.xml 2009-07-10 09:30:57
UTC (rev 17062)
@@ -5,7 +5,8 @@
<persistence-unit name="annotation-processor"
transaction-type="JTA">
<description>Test persistence unit</description>
<mapping-file>/META-INF/order.xml</mapping-file>
- <mapping-file>/META-INF/address.xml</mapping-file>
- <mapping-file>/META-INF/building.xml</mapping-file>
+ <mapping-file>/model/xmlmapped/address.xml</mapping-file>
+ <mapping-file>/model/xmlmapped/building.xml</mapping-file>
+ <mapping-file>/model/xmlmapped/mammal.xml</mapping-file>
</persistence-unit>
</persistence>
Copied: jpamodelgen/trunk/test/src/main/resources/model/xmlmapped/address.xml (from rev
17061, jpamodelgen/trunk/test/src/main/resources/META-INF/address.xml)
===================================================================
--- jpamodelgen/trunk/test/src/main/resources/model/xmlmapped/address.xml
(rev 0)
+++ jpamodelgen/trunk/test/src/main/resources/model/xmlmapped/address.xml 2009-07-10
09:30:57 UTC (rev 17062)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<entity-mappings
xmlns="http://java.sun.com/xml/ns/persistence/orm"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm
orm_2_0.xsd"
+ version="2.0"
+ >
+ <package>model.xmlmapped</package> <!-- default package -->
+ <embeddable class="Address" access="FIELD"
metadata-complete="true"> <!--means ignore annotations-->
+ <attributes>
+ <basic name="street1"/>
+ <basic name="city"/>
+ <basic name="country"/>
+ </attributes>
+ </embeddable>
+</entity-mappings>
+
Copied: jpamodelgen/trunk/test/src/main/resources/model/xmlmapped/building.xml (from rev
17061, jpamodelgen/trunk/test/src/main/resources/META-INF/building.xml)
===================================================================
--- jpamodelgen/trunk/test/src/main/resources/model/xmlmapped/building.xml
(rev 0)
+++ jpamodelgen/trunk/test/src/main/resources/model/xmlmapped/building.xml 2009-07-10
09:30:57 UTC (rev 17062)
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<entity-mappings
xmlns="http://java.sun.com/xml/ns/persistence/orm"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm
orm_2_0.xsd"
+ version="2.0"
+ >
+ <package>model.xmlmapped</package>
+ <mapped-superclass class="Building" access="FIELD"
metadata-complete="true"> <!--means ignore annotations-->
+ <attributes>
+ <one-to-one name="address" fetch="LAZY"/>
+ </attributes>
+ </mapped-superclass>
+</entity-mappings>
+
Copied: jpamodelgen/trunk/test/src/main/resources/model/xmlmapped/mammal.xml (from rev
17061, jpamodelgen/trunk/test/src/main/resources/META-INF/order.xml)
===================================================================
--- jpamodelgen/trunk/test/src/main/resources/model/xmlmapped/mammal.xml
(rev 0)
+++ jpamodelgen/trunk/test/src/main/resources/model/xmlmapped/mammal.xml 2009-07-10
09:30:57 UTC (rev 17062)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<entity-mappings
xmlns="http://java.sun.com/xml/ns/persistence/orm"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm
orm_2_0.xsd"
+ version="2.0"
+ >
+ <package>model.xmlmapped</package>
+ <entity class="LivingBeing" access="FIELD"
metadata-complete="true">
+ <attributes>
+ <basic name="isReallyAlive"/>
+ </attributes>
+ </entity>
+ <entity class="Mammal" access="FIELD"
metadata-complete="true">
+ <attributes>
+ <id name="id"/>
+ <basic name="subclass"/>
+ </attributes>
+ </entity>
+</entity-mappings>
Modified: jpamodelgen/trunk/test/src/test/java/tests/XmlMappingTest.java
===================================================================
--- jpamodelgen/trunk/test/src/test/java/tests/XmlMappingTest.java 2009-07-10 07:12:22 UTC
(rev 17061)
+++ jpamodelgen/trunk/test/src/test/java/tests/XmlMappingTest.java 2009-07-10 09:30:57 UTC
(rev 17062)
@@ -1,6 +1,7 @@
package tests;
import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
import org.testng.annotations.Test;
/**
@@ -14,8 +15,19 @@
@Test
public void testXmlConfiguredMappedSuperclassGenerated() throws Exception {
- Class<?> building = Class.forName( "model.xmlmapped.Building_" );
+ Class<?> building = Class.forName( "model.xmlmapped.Building_" );
assertNotNull( building );
- assertNotNull( building.getField( "address" ));
+ assertNotNull( building.getField( "address" ) );
}
+
+ @Test
+ public void testClassHierarchy() throws Exception {
+ Class<?> mammal = Class.forName( "model.xmlmapped.Mammal_" );
+ assertNotNull( mammal );
+
+ Class<?> being = Class.forName( "model.xmlmapped.LivingBeing_" );
+ assertNotNull( being );
+
+ assertTrue( mammal.getSuperclass().equals( being ) );
+ }
}
\ No newline at end of file