Hibernate SVN: r17071 - in jpamodelgen/trunk/generator/src/test/java: test and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-07-10 12:25:46 -0400 (Fri, 10 Jul 2009)
New Revision: 17071
Added:
jpamodelgen/trunk/generator/src/test/java/model/Country.java
jpamodelgen/trunk/generator/src/test/java/model/Inhabitant.java
jpamodelgen/trunk/generator/src/test/java/model/Pet.java
Modified:
jpamodelgen/trunk/generator/src/test/java/model/Address.java
jpamodelgen/trunk/generator/src/test/java/test/AccessTypeTest.java
Log:
AccessType: test for embeddable rules
Modified: jpamodelgen/trunk/generator/src/test/java/model/Address.java
===================================================================
--- jpamodelgen/trunk/generator/src/test/java/model/Address.java 2009-07-10 16:23:22 UTC (rev 17070)
+++ jpamodelgen/trunk/generator/src/test/java/model/Address.java 2009-07-10 16:25:46 UTC (rev 17071)
@@ -1,15 +1,22 @@
package model;
+import java.util.Set;
import javax.persistence.Embeddable;
+import javax.persistence.Access;
+import javax.persistence.AccessType;
+import javax.persistence.ElementCollection;
+import javax.persistence.CollectionTable;
/**
* @author Emmanuel Bernard
*/
@Embeddable
+(a)Access(javax.persistence.AccessType.PROPERTY)
public class Address {
private String street1;
private String city;
- private String country;
+ private Country country;
+ private Set<Inhabitant> inhabitants;
public String getStreet1() {
return street1;
@@ -27,11 +34,21 @@
this.city = city;
}
- public String getCountry() {
+ public Country getCountry() {
return country;
}
- public void setCountry(String country) {
+ public void setCountry(Country country) {
this.country = country;
}
+
+ @ElementCollection
+ @CollectionTable(name = "Add_Inh")
+ public Set<Inhabitant> getInhabitants() {
+ return inhabitants;
+ }
+
+ public void setInhabitants(Set<Inhabitant> inhabitants) {
+ this.inhabitants = inhabitants;
+ }
}
Added: jpamodelgen/trunk/generator/src/test/java/model/Country.java
===================================================================
--- jpamodelgen/trunk/generator/src/test/java/model/Country.java (rev 0)
+++ jpamodelgen/trunk/generator/src/test/java/model/Country.java 2009-07-10 16:25:46 UTC (rev 17071)
@@ -0,0 +1,29 @@
+package model;
+
+import javax.persistence.Embeddable;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Embeddable
+public class Country {
+ String name;
+ String iso2Code;
+ String nonPersistent;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getIso2Code() {
+ return iso2Code;
+ }
+
+ public void setIso2Code(String iso2Code) {
+ this.iso2Code = iso2Code;
+ }
+}
Added: jpamodelgen/trunk/generator/src/test/java/model/Inhabitant.java
===================================================================
--- jpamodelgen/trunk/generator/src/test/java/model/Inhabitant.java (rev 0)
+++ jpamodelgen/trunk/generator/src/test/java/model/Inhabitant.java 2009-07-10 16:25:46 UTC (rev 17071)
@@ -0,0 +1,26 @@
+package model;
+
+import java.util.Set;
+import javax.persistence.Embeddable;
+import javax.persistence.Access;
+import javax.persistence.AccessType;
+import javax.persistence.ElementCollection;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Embeddable
+(a)Access(javax.persistence.AccessType.FIELD)
+public class Inhabitant {
+ private String name;
+ @ElementCollection
+ private Set<Pet> pets;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Added: jpamodelgen/trunk/generator/src/test/java/model/Pet.java
===================================================================
--- jpamodelgen/trunk/generator/src/test/java/model/Pet.java (rev 0)
+++ jpamodelgen/trunk/generator/src/test/java/model/Pet.java 2009-07-10 16:25:46 UTC (rev 17071)
@@ -0,0 +1,23 @@
+package model;
+
+import javax.persistence.Embeddable;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Embeddable
+public class Pet {
+ String name;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getNonPersistent() {
+ return null;
+ }
+}
Modified: jpamodelgen/trunk/generator/src/test/java/test/AccessTypeTest.java
===================================================================
--- jpamodelgen/trunk/generator/src/test/java/test/AccessTypeTest.java 2009-07-10 16:23:22 UTC (rev 17070)
+++ jpamodelgen/trunk/generator/src/test/java/test/AccessTypeTest.java 2009-07-10 16:25:46 UTC (rev 17071)
@@ -31,10 +31,16 @@
@Test
public void testDefaultAccessTypeForEmbeddable() throws Exception{
- absenceOfField( "model.Detail_", "nonPersistent " );
+ absenceOfField( "model.Detail_", "nonPersistent" );
}
@Test
+ public void testInheritedAccessTypeForEmbeddable() throws Exception{
+ absenceOfField( "model.Country_", "nonPersistent" );
+ absenceOfField( "model.Pet_", "nonPersistent", "Colleciton of membeddable not taken care of" );
+ }
+
+ @Test
public void testDefaultAccessTypeForMappedSuperclass() throws Exception{
absenceOfField( "model.Detail_", "volume" );
}
15 years, 3 months
Hibernate SVN: r17070 - in jpamodelgen/trunk/generator: src/main/java/org/hibernate/jpa/metamodel/ap and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-07-10 12:23:22 -0400 (Fri, 10 Jul 2009)
New Revision: 17070
Added:
jpamodelgen/trunk/generator/src/main/xsd/persistence_2_0.xsd
jpamodelgen/trunk/generator/src/test/resources/META-INF/jpa1-orm.xml
jpamodelgen/trunk/generator/src/test/resources/META-INF/malformed-mapping-xml.xml
Removed:
jpamodelgen/trunk/generator/src/main/xsd/persistence.xsd
Modified:
jpamodelgen/trunk/generator/pom.xml
jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/JPAMetaModelEntityProcessor.java
jpamodelgen/trunk/generator/src/test/resources/META-INF/order.xml
jpamodelgen/trunk/generator/src/test/resources/META-INF/persistence.xml
Log:
xml parsing validates now against the xsd
Modified: jpamodelgen/trunk/generator/pom.xml
===================================================================
--- jpamodelgen/trunk/generator/pom.xml 2009-07-10 16:02:57 UTC (rev 17069)
+++ jpamodelgen/trunk/generator/pom.xml 2009-07-10 16:23:22 UTC (rev 17070)
@@ -27,8 +27,10 @@
<resources>
<resource>
<directory>src/main/resources</directory>
- <filtering>true</filtering>
</resource>
+ <resource>
+ <directory>src/main/xsd</directory>
+ </resource>
</resources>
<plugins>
<plugin>
Modified: jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/JPAMetaModelEntityProcessor.java
===================================================================
--- jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/JPAMetaModelEntityProcessor.java 2009-07-10 16:02:57 UTC (rev 17069)
+++ jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/JPAMetaModelEntityProcessor.java 2009-07-10 16:23:22 UTC (rev 17070)
@@ -3,6 +3,7 @@
import java.io.IOException;
import java.io.InputStream;
+import java.net.URL;
import java.util.Collection;
import java.util.List;
import java.util.Set;
@@ -26,7 +27,11 @@
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+import org.xml.sax.SAXException;
+
import org.hibernate.jpa.metamodel.ap.annotation.MetaEntity;
import org.hibernate.jpa.metamodel.ap.xml.XmlMetaEntity;
import org.hibernate.jpa.metamodel.xml.jaxb.Entity;
@@ -54,6 +59,8 @@
private static final String MAPPED_SUPERCLASS_ANN = MappedSuperclass.class.getName();
private static final String EMBEDDABLE_ANN = Embeddable.class.getName();
private static final AccessType DEFAULT_XML_ACCESS_TYPE = AccessType.PROPERTY;
+ private static final String PERSISTENCE_XML_XSD = "persistence_2_0.xsd";
+ private static final String ORM_XSD = "orm_2_0.xsd";
private boolean xmlProcessed = false;
private Context context;
@@ -134,7 +141,7 @@
}
private void parsePersistenceXml() {
- Persistence persistence = parseXml( PERSISTENCE_XML, Persistence.class );
+ Persistence persistence = parseXml( PERSISTENCE_XML, Persistence.class, PERSISTENCE_XML_XSD );
if ( persistence != null )
{
@@ -149,9 +156,8 @@
xmlProcessed = true;
}
-
private void parsingOrmXml(String resource) {
- EntityMappings mappings = parseXml( resource, EntityMappings.class );
+ EntityMappings mappings = parseXml( resource, EntityMappings.class, ORM_XSD );
if ( mappings == null ) {
return;
}
@@ -319,7 +325,7 @@
String pkg = getPackage( resource );
String name = getRelativeName( resource );
processingEnv.getMessager()
- .printMessage( Diagnostic.Kind.NOTE, "Checking for " + resource );
+ .printMessage( Diagnostic.Kind.NOTE, "Reading resource " + resource );
InputStream ormStream;
try {
FileObject fileObject = processingEnv.getFiler().getResource( StandardLocation.CLASS_OUTPUT, pkg, name );
@@ -347,10 +353,11 @@
*
* @param resource the xml file name
* @param clazz The type of jaxb node to return
+ * @param schemaName The schema to validate against (can be {@code null});
*
* @return The top level jaxb instance contained in the xml file or {@code null} in case the file could not be found.
*/
- private <T> T parseXml(String resource, Class<T> clazz) {
+ private <T> T parseXml(String resource, Class<T> clazz, String schemaName) {
InputStream stream = getInputStreamForResource( resource );
@@ -361,19 +368,19 @@
try {
JAXBContext jc = JAXBContext.newInstance( ObjectFactory.class );
Unmarshaller unmarshaller = jc.createUnmarshaller();
+ if ( schemaName != null ) {
+ unmarshaller.setSchema( getSchema( schemaName ) );
+ }
return clazz.cast( unmarshaller.unmarshal( stream ) );
}
catch ( JAXBException e ) {
- processingEnv.getMessager().printMessage( Diagnostic.Kind.NOTE, "Error unmarshalling " + resource );
- e.printStackTrace();
+ String message = "Error unmarshalling " + resource + " with exception :\n " + e;
+ processingEnv.getMessager().printMessage( Diagnostic.Kind.WARNING, message );
return null;
}
catch ( Exception e ) {
- processingEnv.getMessager().printMessage(
- Diagnostic.Kind.ERROR,
- "Problem while reading " + resource + " " + e.getMessage()
- );
- e.printStackTrace();
+ String message = "Error reading " + resource + " with exception :\n " + e;
+ processingEnv.getMessager().printMessage( Diagnostic.Kind.WARNING, message );
return null;
}
}
@@ -395,4 +402,23 @@
return resourceName.substring( resourceName.lastIndexOf( PATH_SEPARATOR ) + 1 );
}
}
+
+ private Schema getSchema(String schemaName) {
+ Schema schema = null;
+ URL schemaUrl = this.getClass().getClassLoader().getResource( schemaName );
+ if ( schemaUrl == null ) {
+ return schema;
+ }
+
+ SchemaFactory sf = SchemaFactory.newInstance( javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI );
+ try {
+ schema = sf.newSchema( schemaUrl );
+ }
+ catch ( SAXException e ) {
+ processingEnv.getMessager().printMessage(
+ Diagnostic.Kind.WARNING, "Unable to create schema for " + schemaName + ": " + e.getMessage()
+ );
+ }
+ return schema;
+ }
}
Deleted: jpamodelgen/trunk/generator/src/main/xsd/persistence.xsd
===================================================================
--- jpamodelgen/trunk/generator/src/main/xsd/persistence.xsd 2009-07-10 16:02:57 UTC (rev 17069)
+++ jpamodelgen/trunk/generator/src/main/xsd/persistence.xsd 2009-07-10 16:23:22 UTC (rev 17070)
@@ -1,247 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- persistence.xml schema -->
-<xsd:schema targetNamespace="http://java.sun.com/xml/ns/persistence"
- xmlns:xsd="http://www.w3.org/2001/XMLSchema"
- xmlns:persistence="http://java.sun.com/xml/ns/persistence"
- elementFormDefault="qualified"
- attributeFormDefault="unqualified"
- version="2.0">
- <xsd:annotation>
- <xsd:documentation>
- @(#)persistence_2_0.xsd 1.0 August 27 2008
- </xsd:documentation>
- </xsd:annotation>
- <xsd:annotation>
- <xsd:documentation><![CDATA[
-This is the XML Schema for the persistence configuration file.
-The file must be named "META-INF/persistence.xml" in the
-persistence archive.
-Persistence configuration files must indicate
-the persistence schema by using the persistence namespace:
-http://java.sun.com/xml/ns/persistence
-and indicate the version of the schema by
-using the version element as shown below:
-<persistence xmlns="http://java.sun.com/xml/ns/persistence"
-xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
-http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
-version="2.0">
-...
-</persistence>
-]]></xsd:documentation>
- </xsd:annotation>
- <xsd:simpleType name="versionType">
- <xsd:restriction base="xsd:token">
- <xsd:pattern value="[0-9]+(\.[0-9]+)*"/>
- </xsd:restriction>
- </xsd:simpleType>
- <!-- **************************************************** -->
- <xsd:element name="persistence">
- <xsd:complexType>
- <xsd:sequence>
- <!-- **************************************************** -->
- <xsd:element name="persistence-unit"
- minOccurs="1" maxOccurs="unbounded">
- <xsd:complexType>
- <xsd:annotation>
- <xsd:documentation>Configuration of a persistence unit.
- </xsd:documentation>
- </xsd:annotation>
- <xsd:sequence>
- <!-- **************************************************** -->
- <xsd:element name="description" type="xsd:string"
- minOccurs="0">
- <xsd:annotation>
- <xsd:documentation>
- Description of this persistence unit.
- </xsd:documentation>
- </xsd:annotation>
- </xsd:element>
- <!-- **************************************************** -->
- <xsd:element name="provider" type="xsd:string"
- minOccurs="0">
- <xsd:annotation>
- <xsd:documentation>
- Provider class that supplies EntityManagers for this
- persistence unit.
- </xsd:documentation>
- </xsd:annotation>
- </xsd:element>
- <!-- **************************************************** -->
- <xsd:element name="jta-data-source" type="xsd:string"
- minOccurs="0">
- <xsd:annotation>
- <xsd:documentation>
- The container-specific name of the JTA datasource to use.
- </xsd:documentation>
- </xsd:annotation>
- </xsd:element>
- <!-- **************************************************** -->
- <xsd:element name="non-jta-data-source" type="xsd:string"
- minOccurs="0">
- <xsd:annotation>
- <xsd:documentation>
- The container-specific name of a non-JTA datasource to use.
- </xsd:documentation>
- </xsd:annotation>
- </xsd:element>
- <!-- **************************************************** -->
- <xsd:element name="mapping-file" type="xsd:string"
- minOccurs="0" maxOccurs="unbounded">
- <xsd:annotation>
- <xsd:documentation>File containing mapping information. Loaded as a resource
- by the persistence provider.
- </xsd:documentation>
- </xsd:annotation>
- </xsd:element>
- <!-- **************************************************** -->
- <xsd:element name="jar-file" type="xsd:string"
- minOccurs="0" maxOccurs="unbounded">
- <xsd:annotation>
- <xsd:documentation>
- Jar file that should be scanned for entities.
- Not applicable to Java SE persistence units.
- </xsd:documentation>
- </xsd:annotation>
- </xsd:element>
- <!-- **************************************************** -->
- <xsd:element name="class" type="xsd:string"
- minOccurs="0" maxOccurs="unbounded">
- <xsd:annotation>
- <xsd:documentation>
- Class to scan for annotations. It should be annotated
- with either @Entity, @Embeddable or @MappedSuperclass.
- </xsd:documentation>
- </xsd:annotation>
- </xsd:element>
- <!-- **************************************************** -->
- <xsd:element name="exclude-unlisted-classes" type="xsd:boolean"
- default="false" minOccurs="0">
- <xsd:annotation>
- <xsd:documentation>
- When set to true then only listed classes and jars will
- be scanned for persistent classes, otherwise the enclosing
- jar or directory will also be scanned. Not applicable to
- Java SE persistence units.
- </xsd:documentation>
- </xsd:annotation>
- </xsd:element>
- <!-- **************************************************** -->
- <xsd:element name="caching"
- type="persistence:persistence-unit-caching-type"
- minOccurs="0">
- <xsd:annotation>
- <xsd:documentation>
- Defines whether caching is enabled for the
- persistence unit if caching is supported by the
- persistence provider. When set to ALL, all entities
- will be cached. When set to NONE, no entities will
- be cached. When set to ENABLE_SELECTIVE, only entities
- specified as cacheable will be cached. When set toDISABLE_SELECTIVE, entities specified as not cacheable
- will not be cached.
- </xsd:documentation>
- </xsd:annotation>
- </xsd:element>
- <!-- **************************************************** -->
- <xsd:element
- name="validation-mode"
- type="persistence:persistence-unit-validation-mode-type"
- minOccurs="0">
- <xsd:annotation>
- <xsd:documentation>
- Specifies the validation mode to be used for the
- persistence unit.
- </xsd:documentation>
- </xsd:annotation>
- </xsd:element>
- <!-- **************************************************** -->
- <xsd:element name="properties" minOccurs="0">
- <xsd:annotation>
- <xsd:documentation>
- A list of vendor-specific properties.
- </xsd:documentation>
- </xsd:annotation>
- <xsd:complexType>
- <xsd:sequence>
- <xsd:element name="property"
- minOccurs="0" maxOccurs="unbounded">
- <xsd:annotation>
- <xsd:documentation>
- A name-value pair.
- </xsd:documentation>
- </xsd:annotation>
- <xsd:complexType>
- <xsd:attribute name="name" type="xsd:string"
- use="required"/>
- <xsd:attribute name="value" type="xsd:string"
- use="required"/>
- </xsd:complexType>
- </xsd:element>
- </xsd:sequence>
- </xsd:complexType>
- </xsd:element>
- </xsd:sequence>
- <!-- **************************************************** -->
- <xsd:attribute name="name" type="xsd:string" use="required">
- <xsd:annotation>
- <xsd:documentation>
- Name used in code to reference this persistence unit.
- </xsd:documentation>
- </xsd:annotation></xsd:attribute>
- <!-- **************************************************** -->
- <xsd:attribute name="transaction-type"
- type="persistence:persistence-unit-transaction-type">
- <xsd:annotation>
- <xsd:documentation>
- Type of transactions used by EntityManagers from this
- persistence unit.
- </xsd:documentation>
- </xsd:annotation>
- </xsd:attribute>
- </xsd:complexType>
- </xsd:element>
- </xsd:sequence>
- <xsd:attribute name="version" type="persistence:versionType"
- fixed="2.0" use="required"/>
- </xsd:complexType>
- </xsd:element>
- <!-- **************************************************** -->
- <xsd:simpleType name="persistence-unit-transaction-type">
- <xsd:annotation>
- <xsd:documentation>
- public enum TransactionType { JTA, RESOURCE_LOCAL };
- </xsd:documentation>
- </xsd:annotation>
- <xsd:restriction base="xsd:token">
- <xsd:enumeration value="JTA"/>
- <xsd:enumeration value="RESOURCE_LOCAL"/>
- </xsd:restriction>
- </xsd:simpleType>
- <!-- **************************************************** -->
- <xsd:simpleType name="persistence-unit-caching-type">
- <xsd:annotation>
- <xsd:documentation>
- public enum CachingType { ALL, NONE, ENABLE_SELECTIVE,
- DISABLE_SELECTIVE};
- </xsd:documentation>
- </xsd:annotation>
- <xsd:restriction base="xsd:token">
- <xsd:enumeration value="ALL"/>
- <xsd:enumeration value="NONE"/>
- <xsd:enumeration value="ENABLE_SELECTIVE"/>
- <xsd:enumeration value="DISABLE_SELECTIVE"/>
- </xsd:restriction>
- </xsd:simpleType>
- <!-- **************************************************** -->
- <xsd:simpleType name="persistence-unit-validation-mode-type">
- <xsd:annotation>
- <xsd:documentation>public enum ValidationMode { AUTO, CALLBACK, NONE};
- </xsd:documentation>
- </xsd:annotation>
- <xsd:restriction base="xsd:token">
- <xsd:enumeration value="AUTO"/>
- <xsd:enumeration value="CALLBACK"/>
- <xsd:enumeration value="NONE"/>
- </xsd:restriction>
- </xsd:simpleType>
-</xsd:schema>
\ No newline at end of file
Copied: jpamodelgen/trunk/generator/src/main/xsd/persistence_2_0.xsd (from rev 17064, jpamodelgen/trunk/generator/src/main/xsd/persistence.xsd)
===================================================================
--- jpamodelgen/trunk/generator/src/main/xsd/persistence_2_0.xsd (rev 0)
+++ jpamodelgen/trunk/generator/src/main/xsd/persistence_2_0.xsd 2009-07-10 16:23:22 UTC (rev 17070)
@@ -0,0 +1,247 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- persistence.xml schema -->
+<xsd:schema targetNamespace="http://java.sun.com/xml/ns/persistence"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:persistence="http://java.sun.com/xml/ns/persistence"
+ elementFormDefault="qualified"
+ attributeFormDefault="unqualified"
+ version="2.0">
+ <xsd:annotation>
+ <xsd:documentation>
+ @(#)persistence_2_0.xsd 1.0 August 27 2008
+ </xsd:documentation>
+ </xsd:annotation>
+ <xsd:annotation>
+ <xsd:documentation><![CDATA[
+This is the XML Schema for the persistence configuration file.
+The file must be named "META-INF/persistence.xml" in the
+persistence archive.
+Persistence configuration files must indicate
+the persistence schema by using the persistence namespace:
+http://java.sun.com/xml/ns/persistence
+and indicate the version of the schema by
+using the version element as shown below:
+<persistence xmlns="http://java.sun.com/xml/ns/persistence"
+xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
+http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
+version="2.0">
+...
+</persistence>
+]]></xsd:documentation>
+ </xsd:annotation>
+ <xsd:simpleType name="versionType">
+ <xsd:restriction base="xsd:token">
+ <xsd:pattern value="[0-9]+(\.[0-9]+)*"/>
+ </xsd:restriction>
+ </xsd:simpleType>
+ <!-- **************************************************** -->
+ <xsd:element name="persistence">
+ <xsd:complexType>
+ <xsd:sequence>
+ <!-- **************************************************** -->
+ <xsd:element name="persistence-unit"
+ minOccurs="1" maxOccurs="unbounded">
+ <xsd:complexType>
+ <xsd:annotation>
+ <xsd:documentation>Configuration of a persistence unit.
+ </xsd:documentation>
+ </xsd:annotation>
+ <xsd:sequence>
+ <!-- **************************************************** -->
+ <xsd:element name="description" type="xsd:string"
+ minOccurs="0">
+ <xsd:annotation>
+ <xsd:documentation>
+ Description of this persistence unit.
+ </xsd:documentation>
+ </xsd:annotation>
+ </xsd:element>
+ <!-- **************************************************** -->
+ <xsd:element name="provider" type="xsd:string"
+ minOccurs="0">
+ <xsd:annotation>
+ <xsd:documentation>
+ Provider class that supplies EntityManagers for this
+ persistence unit.
+ </xsd:documentation>
+ </xsd:annotation>
+ </xsd:element>
+ <!-- **************************************************** -->
+ <xsd:element name="jta-data-source" type="xsd:string"
+ minOccurs="0">
+ <xsd:annotation>
+ <xsd:documentation>
+ The container-specific name of the JTA datasource to use.
+ </xsd:documentation>
+ </xsd:annotation>
+ </xsd:element>
+ <!-- **************************************************** -->
+ <xsd:element name="non-jta-data-source" type="xsd:string"
+ minOccurs="0">
+ <xsd:annotation>
+ <xsd:documentation>
+ The container-specific name of a non-JTA datasource to use.
+ </xsd:documentation>
+ </xsd:annotation>
+ </xsd:element>
+ <!-- **************************************************** -->
+ <xsd:element name="mapping-file" type="xsd:string"
+ minOccurs="0" maxOccurs="unbounded">
+ <xsd:annotation>
+ <xsd:documentation>File containing mapping information. Loaded as a resource
+ by the persistence provider.
+ </xsd:documentation>
+ </xsd:annotation>
+ </xsd:element>
+ <!-- **************************************************** -->
+ <xsd:element name="jar-file" type="xsd:string"
+ minOccurs="0" maxOccurs="unbounded">
+ <xsd:annotation>
+ <xsd:documentation>
+ Jar file that should be scanned for entities.
+ Not applicable to Java SE persistence units.
+ </xsd:documentation>
+ </xsd:annotation>
+ </xsd:element>
+ <!-- **************************************************** -->
+ <xsd:element name="class" type="xsd:string"
+ minOccurs="0" maxOccurs="unbounded">
+ <xsd:annotation>
+ <xsd:documentation>
+ Class to scan for annotations. It should be annotated
+ with either @Entity, @Embeddable or @MappedSuperclass.
+ </xsd:documentation>
+ </xsd:annotation>
+ </xsd:element>
+ <!-- **************************************************** -->
+ <xsd:element name="exclude-unlisted-classes" type="xsd:boolean"
+ default="false" minOccurs="0">
+ <xsd:annotation>
+ <xsd:documentation>
+ When set to true then only listed classes and jars will
+ be scanned for persistent classes, otherwise the enclosing
+ jar or directory will also be scanned. Not applicable to
+ Java SE persistence units.
+ </xsd:documentation>
+ </xsd:annotation>
+ </xsd:element>
+ <!-- **************************************************** -->
+ <xsd:element name="caching"
+ type="persistence:persistence-unit-caching-type"
+ minOccurs="0">
+ <xsd:annotation>
+ <xsd:documentation>
+ Defines whether caching is enabled for the
+ persistence unit if caching is supported by the
+ persistence provider. When set to ALL, all entities
+ will be cached. When set to NONE, no entities will
+ be cached. When set to ENABLE_SELECTIVE, only entities
+ specified as cacheable will be cached. When set toDISABLE_SELECTIVE, entities specified as not cacheable
+ will not be cached.
+ </xsd:documentation>
+ </xsd:annotation>
+ </xsd:element>
+ <!-- **************************************************** -->
+ <xsd:element
+ name="validation-mode"
+ type="persistence:persistence-unit-validation-mode-type"
+ minOccurs="0">
+ <xsd:annotation>
+ <xsd:documentation>
+ Specifies the validation mode to be used for the
+ persistence unit.
+ </xsd:documentation>
+ </xsd:annotation>
+ </xsd:element>
+ <!-- **************************************************** -->
+ <xsd:element name="properties" minOccurs="0">
+ <xsd:annotation>
+ <xsd:documentation>
+ A list of vendor-specific properties.
+ </xsd:documentation>
+ </xsd:annotation>
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="property"
+ minOccurs="0" maxOccurs="unbounded">
+ <xsd:annotation>
+ <xsd:documentation>
+ A name-value pair.
+ </xsd:documentation>
+ </xsd:annotation>
+ <xsd:complexType>
+ <xsd:attribute name="name" type="xsd:string"
+ use="required"/>
+ <xsd:attribute name="value" type="xsd:string"
+ use="required"/>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:sequence>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:sequence>
+ <!-- **************************************************** -->
+ <xsd:attribute name="name" type="xsd:string" use="required">
+ <xsd:annotation>
+ <xsd:documentation>
+ Name used in code to reference this persistence unit.
+ </xsd:documentation>
+ </xsd:annotation></xsd:attribute>
+ <!-- **************************************************** -->
+ <xsd:attribute name="transaction-type"
+ type="persistence:persistence-unit-transaction-type">
+ <xsd:annotation>
+ <xsd:documentation>
+ Type of transactions used by EntityManagers from this
+ persistence unit.
+ </xsd:documentation>
+ </xsd:annotation>
+ </xsd:attribute>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:sequence>
+ <xsd:attribute name="version" type="persistence:versionType"
+ fixed="2.0" use="required"/>
+ </xsd:complexType>
+ </xsd:element>
+ <!-- **************************************************** -->
+ <xsd:simpleType name="persistence-unit-transaction-type">
+ <xsd:annotation>
+ <xsd:documentation>
+ public enum TransactionType { JTA, RESOURCE_LOCAL };
+ </xsd:documentation>
+ </xsd:annotation>
+ <xsd:restriction base="xsd:token">
+ <xsd:enumeration value="JTA"/>
+ <xsd:enumeration value="RESOURCE_LOCAL"/>
+ </xsd:restriction>
+ </xsd:simpleType>
+ <!-- **************************************************** -->
+ <xsd:simpleType name="persistence-unit-caching-type">
+ <xsd:annotation>
+ <xsd:documentation>
+ public enum CachingType { ALL, NONE, ENABLE_SELECTIVE,
+ DISABLE_SELECTIVE};
+ </xsd:documentation>
+ </xsd:annotation>
+ <xsd:restriction base="xsd:token">
+ <xsd:enumeration value="ALL"/>
+ <xsd:enumeration value="NONE"/>
+ <xsd:enumeration value="ENABLE_SELECTIVE"/>
+ <xsd:enumeration value="DISABLE_SELECTIVE"/>
+ </xsd:restriction>
+ </xsd:simpleType>
+ <!-- **************************************************** -->
+ <xsd:simpleType name="persistence-unit-validation-mode-type">
+ <xsd:annotation>
+ <xsd:documentation>public enum ValidationMode { AUTO, CALLBACK, NONE};
+ </xsd:documentation>
+ </xsd:annotation>
+ <xsd:restriction base="xsd:token">
+ <xsd:enumeration value="AUTO"/>
+ <xsd:enumeration value="CALLBACK"/>
+ <xsd:enumeration value="NONE"/>
+ </xsd:restriction>
+ </xsd:simpleType>
+</xsd:schema>
\ No newline at end of file
Added: jpamodelgen/trunk/generator/src/test/resources/META-INF/jpa1-orm.xml
===================================================================
--- jpamodelgen/trunk/generator/src/test/resources/META-INF/jpa1-orm.xml (rev 0)
+++ jpamodelgen/trunk/generator/src/test/resources/META-INF/jpa1-orm.xml 2009-07-10 16:23:22 UTC (rev 17070)
@@ -0,0 +1,14 @@
+<?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_1_0.xsd"
+ version="1.0"
+ >
+ <package>model</package>
+ <entity class="Airplane" metadata-complete="true" access="PROPERTY">
+ <attributes>
+ <id name="serialNumber"/>
+ </attributes>
+ </entity>
+</entity-mappings>
\ No newline at end of file
Copied: jpamodelgen/trunk/generator/src/test/resources/META-INF/malformed-mapping-xml.xml (from rev 17064, jpamodelgen/trunk/generator/src/test/resources/META-INF/dummy.xml)
===================================================================
--- jpamodelgen/trunk/generator/src/test/resources/META-INF/malformed-mapping-xml.xml (rev 0)
+++ jpamodelgen/trunk/generator/src/test/resources/META-INF/malformed-mapping-xml.xml 2009-07-10 16:23:22 UTC (rev 17070)
@@ -0,0 +1,13 @@
+<?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</package>
+ <entity class="Dummy" access="FIELD" metadata-complete="true"> <!-- Class does not exist -->
+ <attributes>
+ <id name="id"/>
+ </entity>
+</entity-mappings>
Modified: jpamodelgen/trunk/generator/src/test/resources/META-INF/order.xml
===================================================================
--- jpamodelgen/trunk/generator/src/test/resources/META-INF/order.xml 2009-07-10 16:02:57 UTC (rev 17069)
+++ jpamodelgen/trunk/generator/src/test/resources/META-INF/order.xml 2009-07-10 16:23:22 UTC (rev 17070)
@@ -5,7 +5,8 @@
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
version="2.0"
>
- <package>model</package> <!-- default package -->
+ <package>model</package>
+ <!-- default package -->
<entity class="Order" access="FIELD" metadata-complete="true"> <!--means ignore annotations-->
<attributes>
<id name="id">
@@ -13,24 +14,16 @@
</id>
<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-->
+ <many-to-one name="shop"/>
+ <one-to-many name="items"
+ target-entity="Item"
+ fetch="EAGER"> <!-- target-entity optional guess the type from the geenric-->
<cascade>
<cascade-persist/>
</cascade>
</one-to-many>
- <many-to-one name="shop"/>
- <element-collection name="notes"/> <!-- new in JPA 2 -->
+ <element-collection name="notes"/>
+ <!-- new in JPA 2 -->
</attributes>
</entity>
</entity-mappings>
-
-
- <!--
-public class Order {
- long id;
- Set<Item> items;
- boolean filled;
- Date date;
- List<String> notes;
- Shop shop;
-} -->
\ No newline at end of file
Modified: jpamodelgen/trunk/generator/src/test/resources/META-INF/persistence.xml
===================================================================
--- jpamodelgen/trunk/generator/src/test/resources/META-INF/persistence.xml 2009-07-10 16:02:57 UTC (rev 17069)
+++ jpamodelgen/trunk/generator/src/test/resources/META-INF/persistence.xml 2009-07-10 16:23:22 UTC (rev 17070)
@@ -6,6 +6,8 @@
<description>Test persistence unit</description>
<mapping-file>/META-INF/order.xml</mapping-file>
<mapping-file>/META-INF/dummy.xml</mapping-file>
+ <mapping-file>/META-INF/malformed-mapping-xml.xml</mapping-file>
+ <mapping-file>/META-INF/jpa1-orm.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>
15 years, 3 months
Hibernate SVN: r17069 - jpamodelgen/trunk.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-07-10 12:02:57 -0400 (Fri, 10 Jul 2009)
New Revision: 17069
Removed:
jpamodelgen/trunk/test/
Log:
deleted obsolete test directory
15 years, 3 months
Hibernate SVN: r17068 - in jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap: annotation and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-07-10 11:50:21 -0400 (Fri, 10 Jul 2009)
New Revision: 17068
Modified:
jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/Context.java
jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/annotation/MetaEntity.java
Log:
Support AccessType for emdebbale (ie propery inheritance by enclosing type)
Modified: jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/Context.java
===================================================================
--- jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/Context.java 2009-07-10 15:04:18 UTC (rev 17067)
+++ jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/Context.java 2009-07-10 15:50:21 UTC (rev 17068)
@@ -16,12 +16,17 @@
*/
public class Context {
//used to cache access types
- private Map<TypeElement, AccessType> accessTypes = new HashMap<TypeElement,AccessType>();
+ private Map<TypeElement, AccessTypeHolder> accessTypes = new HashMap<TypeElement, AccessTypeHolder>();
private Set<String> elementsAlreadyProcessed = new HashSet<String>();
private ProcessingEnvironment pe;
private final Map<String, IMetaEntity> metaEntitiesToProcess = new HashMap<String, IMetaEntity>();
private final Map<String, IMetaEntity> metaSuperclassAndEmbeddableToProcess = new HashMap<String, IMetaEntity>();
+ private static class AccessTypeHolder {
+ public AccessType elementAccessType;
+ public AccessType hierarchyAccessType;
+ }
+
public Context(ProcessingEnvironment pe) {
this.pe = pe;
}
@@ -35,13 +40,33 @@
}
public void addAccessType(TypeElement element, AccessType accessType) {
- accessTypes.put( element, accessType );
+ AccessTypeHolder typeHolder = accessTypes.get( element );
+ if ( typeHolder == null ) {
+ typeHolder = new AccessTypeHolder();
+ accessTypes.put( element, typeHolder );
+ }
+ typeHolder.elementAccessType = accessType;
}
- public Map<TypeElement, AccessType> getAccessTypes() {
- return accessTypes;
+ public void addAccessTypeForHierarchy(TypeElement element, AccessType accessType) {
+ AccessTypeHolder typeHolder = accessTypes.get( element );
+ if ( typeHolder == null ) {
+ typeHolder = new AccessTypeHolder();
+ accessTypes.put( element, typeHolder );
+ }
+ typeHolder.hierarchyAccessType = accessType;
}
+ public AccessType getAccessType(TypeElement element) {
+ final AccessTypeHolder typeHolder = accessTypes.get( element );
+ return typeHolder != null ? typeHolder.elementAccessType : null;
+ }
+
+ public AccessType getDefaultAccessTypeForHerarchy(TypeElement element) {
+ final AccessTypeHolder typeHolder = accessTypes.get( element );
+ return typeHolder != null ? typeHolder.hierarchyAccessType : null;
+ }
+
public Set<String> getElementsAlreadyProcessed() {
return elementsAlreadyProcessed;
}
Modified: jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/annotation/MetaEntity.java
===================================================================
--- jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/annotation/MetaEntity.java 2009-07-10 15:04:18 UTC (rev 17067)
+++ jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/annotation/MetaEntity.java 2009-07-10 15:50:21 UTC (rev 17068)
@@ -27,6 +27,7 @@
import javax.persistence.Embedded;
import javax.persistence.Embeddable;
import javax.persistence.Access;
+import javax.persistence.ElementCollection;
import javax.tools.Diagnostic.Kind;
import javax.tools.Diagnostic;
@@ -46,6 +47,7 @@
private Context context;
//used to propagate the access type of the root entity over to subclasses, superclasses and embeddable
private AccessType defaultAccessTypeForHierarchy;
+ private AccessType defaultAccessTypeForElement;
public MetaEntity(ProcessingEnvironment pe, TypeElement element, Context context) {
this.element = element;
@@ -79,6 +81,7 @@
public List<IMetaAttribute> getMembers() {
List<IMetaAttribute> membersFound = new ArrayList<IMetaAttribute>();
final AccessType elementAccessType = getAccessTypeForElement();
+
List<? extends Element> fieldsOfClass = ElementFilter.fieldsIn( element.getEnclosedElements() );
addPersistentMembers( membersFound, elementAccessType, fieldsOfClass, AccessType.FIELD );
@@ -93,6 +96,7 @@
break; //will be handled or has been handled already
}
else if ( superclass.getAnnotation( MappedSuperclass.class ) != null ) {
+ //FIXME use the class defalut access type
context.processElement( superclass, defaultAccessTypeForHierarchy );
}
}
@@ -136,61 +140,59 @@
}
private AccessType getAccessTypeForElement() {
- //default strategy has more power than local discovery
- //particularly @MappedSuperclass and @Embedded have defaultAccessTypeForHierarchy already filled
- if ( this.defaultAccessTypeForHierarchy != null ) {
- return defaultAccessTypeForHierarchy;
- }
//get local strategy
AccessType accessType = getAccessTypeForClass(element);
- if (accessType != null) {
- this.defaultAccessTypeForHierarchy = accessType;
- return accessType;
+ if (accessType == null) {
+ accessType = this.defaultAccessTypeForHierarchy;
}
-
- //we dont' know
- //if an enity go up
- //
- //superclasses alre always treated after their entities
- //and their access type are discovered
- //FIXME is it really true if only the superclass is changed
- TypeElement superClass = element;
- do {
- superClass = TypeUtils.getSuperclass( superClass );
- if (superClass != null) {
- if ( superClass.getAnnotation( Entity.class ) != null ) {
- //FIXME make it work for XML
- accessType = getAccessTypeForClass(superClass);
- if ( accessType != null ) {
- this.defaultAccessTypeForHierarchy = accessType;
- return accessType;
+ if (accessType == null) {
+ //we dont' know
+ //if an enity go up
+ //
+ //superclasses alre always treated after their entities
+ //and their access type are discovered
+ //FIXME is it really true if only the superclass is changed
+ TypeElement superClass = element;
+ do {
+ superClass = TypeUtils.getSuperclass( superClass );
+ if (superClass != null) {
+ if ( superClass.getAnnotation( Entity.class ) != null
+ || superClass.getAnnotation( MappedSuperclass.class ) != null ) {
+ //FIXME make it work for XML
+ AccessType superClassAccessType = getAccessTypeForClass(superClass);
+ //we've reach the root entity and resolved Ids
+ if ( superClassAccessType != null && defaultAccessTypeForHierarchy != null) {
+ break; //we've found it
+ }
}
- }
- else if ( superClass.getAnnotation( MappedSuperclass.class ) != null ) {
- accessType = getAccessTypeForClass(superClass);
- if ( accessType != null ) {
- this.defaultAccessTypeForHierarchy = accessType;
- return accessType;
+ else {
+ break; //neither @Entity nor @MappedSuperclass
}
}
- else {
- break; //neither @Entity nor @MappedSuperclass
- }
}
+ while ( superClass != null );
}
- while ( superClass != null );
+
+ if ( accessType == null ) {
+ accessType = AccessType.PROPERTY; //default to property
+ this.defaultAccessTypeForElement = accessType;
+ }
//this is a subclass so caching is OK
- this.defaultAccessTypeForHierarchy = accessType;
- context.addAccessType( this.element, AccessType.PROPERTY );
- return AccessType.PROPERTY; //default to getter
+ //this.defaultAccessTypeForHierarchy = accessType;
+ context.addAccessType( this.element, accessType );
+ this.defaultAccessTypeForElement = accessType;
+ return accessType;
}
private AccessType getAccessTypeForClass(TypeElement searchedElement) {
pe.getMessager().printMessage( Diagnostic.Kind.NOTE, "check class" + searchedElement );
- AccessType accessType = context.getAccessTypes().get( searchedElement );
+ AccessType accessType = context.getAccessType( searchedElement );
+
+ if (defaultAccessTypeForHierarchy == null) {
+ this.defaultAccessTypeForHierarchy = context.getDefaultAccessTypeForHerarchy( searchedElement );
+ }
if ( accessType != null ) {
- this.defaultAccessTypeForHierarchy = accessType;
pe.getMessager().printMessage( Diagnostic.Kind.NOTE, "Found in cache" + searchedElement + ":" + accessType );
return accessType;
}
@@ -202,43 +204,55 @@
final Access accessAnn = searchedElement.getAnnotation( Access.class );
AccessType forcedAccessType = accessAnn != null ? accessAnn.value() : null;
if ( forcedAccessType != null) {
- pe.getMessager().printMessage( Diagnostic.Kind.NOTE, "access type " + searchedElement + ":" + accessType );
+ pe.getMessager().printMessage( Diagnostic.Kind.NOTE, "access type " + searchedElement + ":" + forcedAccessType );
context.addAccessType( searchedElement, forcedAccessType );
}
+
//continue nevertheless to check if we are root and if defaultAccessTypeForHierarchy
//should be overridden
+ if ( forcedAccessType == null || defaultAccessTypeForHierarchy == null) {
+ List<? extends Element> myMembers = searchedElement.getEnclosedElements();
+ for ( Element subElement : myMembers ) {
+ List<? extends AnnotationMirror> entityAnnotations =
+ pe.getElementUtils().getAllAnnotationMirrors( subElement );
- List<? extends Element> myMembers = searchedElement.getEnclosedElements();
- for ( Element subElement : myMembers ) {
- List<? extends AnnotationMirror> entityAnnotations =
- pe.getElementUtils().getAllAnnotationMirrors( subElement );
+ for ( Object entityAnnotation : entityAnnotations ) {
+ AnnotationMirror annotationMirror = ( AnnotationMirror ) entityAnnotation;
- for ( Object entityAnnotation : entityAnnotations ) {
- AnnotationMirror annotationMirror = ( AnnotationMirror ) entityAnnotation;
+ final String annotationType = annotationMirror.getAnnotationType().toString();
- final String annotationType = annotationMirror.getAnnotationType().toString();
-
- //FIXME consider XML
- if ( annotationType.equals( Id.class.getName() )
- || annotationType.equals( EmbeddedId.class.getName() ) ) {
- pe.getMessager().printMessage( Diagnostic.Kind.NOTE, "Found id on" + searchedElement );
- final ElementKind kind = subElement.getKind();
- if ( kind == ElementKind.FIELD || kind == ElementKind.METHOD ) {
- accessType = kind == ElementKind.FIELD ? AccessType.FIELD : AccessType.PROPERTY;
- this.defaultAccessTypeForHierarchy = accessType;
- if ( forcedAccessType == null) {
- context.addAccessType( searchedElement, accessType );
- pe.getMessager().printMessage( Diagnostic.Kind.NOTE, "access type " + searchedElement + ":" + accessType );
- return accessType;
+ //FIXME consider XML
+ if ( annotationType.equals( Id.class.getName() )
+ || annotationType.equals( EmbeddedId.class.getName() ) ) {
+ pe.getMessager().printMessage( Diagnostic.Kind.NOTE, "Found id on" + searchedElement );
+ final ElementKind kind = subElement.getKind();
+ if ( kind == ElementKind.FIELD || kind == ElementKind.METHOD ) {
+ accessType = kind == ElementKind.FIELD ? AccessType.FIELD : AccessType.PROPERTY;
+ //FIXME enlever in niveau
+ if (defaultAccessTypeForHierarchy == null) {
+ this.defaultAccessTypeForHierarchy = context.getDefaultAccessTypeForHerarchy( searchedElement );
+ //we've discovered the class hierarchy, let's cache it
+ if ( defaultAccessTypeForHierarchy == null ) {
+ this.defaultAccessTypeForHierarchy = accessType;
+ context.addAccessTypeForHierarchy( searchedElement, defaultAccessTypeForHierarchy );
+ //FIXME should we add
+ //context.addAccessTypeForHierarchy( element, defaultAccessTypeForHierarchy );
+ }
+ }
+ if ( forcedAccessType == null) {
+ context.addAccessType( searchedElement, accessType );
+ pe.getMessager().printMessage( Diagnostic.Kind.NOTE, "access type " + searchedElement + ":" + accessType );
+ return accessType;
+ }
+ else {
+ return forcedAccessType;
+ }
}
- else {
- return forcedAccessType;
- }
}
}
}
}
- return null;
+ return forcedAccessType;
}
@Override
@@ -312,8 +326,15 @@
if ( isPersistent( element ) ) {
TypeElement returnedElement = ( TypeElement ) pe.getTypeUtils().asElement( t );
String collection = COLLECTIONS.get( returnedElement.getQualifiedName().toString() ); // WARNING: .toString() is necessary here since Name equals does not compare to String
- //FIXME collection of element
+
if ( collection != null ) {
+ //collection of element
+ if ( element.getAnnotation( ElementCollection.class ) != null ) {
+ final TypeMirror collectionType = t.getTypeArguments().get( 0 );
+ final TypeElement collectionElement = ( TypeElement ) pe.getTypeUtils().asElement( collectionType );
+ this.parent.context.processElement( collectionElement,
+ this.parent.defaultAccessTypeForElement );
+ }
if ( collection.equals( "javax.persistence.metamodel.MapAttribute" ) ) {
return new MetaMap( parent, element, collection, getKeyType( t ), getElementType( t ) );
}
@@ -326,7 +347,7 @@
if ( element.getAnnotation( Embedded.class ) != null
|| returnedElement.getAnnotation( Embeddable.class ) != null ) {
this.parent.context.processElement( returnedElement,
- this.parent.defaultAccessTypeForHierarchy );
+ this.parent.defaultAccessTypeForElement );
}
return new MetaSingleAttribute( parent, element, returnedElement.getQualifiedName().toString() );
}
15 years, 3 months
Hibernate SVN: r17067 - jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-07-10 11:04:18 -0400 (Fri, 10 Jul 2009)
New Revision: 17067
Modified:
jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/JPAMetaModelEntityProcessor.java
Log:
reading access defaults from xml
Modified: jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/JPAMetaModelEntityProcessor.java
===================================================================
--- jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/JPAMetaModelEntityProcessor.java 2009-07-10 13:19:47 UTC (rev 17066)
+++ jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/JPAMetaModelEntityProcessor.java 2009-07-10 15:04:18 UTC (rev 17067)
@@ -17,6 +17,7 @@
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.Elements;
+import javax.persistence.AccessType;
import javax.persistence.Embeddable;
import javax.persistence.MappedSuperclass;
import javax.tools.Diagnostic;
@@ -32,6 +33,8 @@
import org.hibernate.jpa.metamodel.xml.jaxb.EntityMappings;
import org.hibernate.jpa.metamodel.xml.jaxb.ObjectFactory;
import org.hibernate.jpa.metamodel.xml.jaxb.Persistence;
+import org.hibernate.jpa.metamodel.xml.jaxb.PersistenceUnitDefaults;
+import org.hibernate.jpa.metamodel.xml.jaxb.PersistenceUnitMetadata;
/**
* Main annotation processor.
@@ -46,10 +49,11 @@
private static final String PATH_SEPARATOR = "/";
private static final String PERSISTENCE_XML = "/META-INF/persistence.xml";
- private static final Boolean ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS = Boolean.TRUE;
+ private static final Boolean ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS = Boolean.FALSE;
private static final String ENTITY_ANN = javax.persistence.Entity.class.getName();
private static final String MAPPED_SUPERCLASS_ANN = MappedSuperclass.class.getName();
private static final String EMBEDDABLE_ANN = Embeddable.class.getName();
+ private static final AccessType DEFAULT_XML_ACCESS_TYPE = AccessType.PROPERTY;
private boolean xmlProcessed = false;
private Context context;
@@ -91,7 +95,7 @@
handleRootElementAnnotationMirrors( element );
}
- return !ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
+ return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
}
private void createMetaModelClasses() {
@@ -152,12 +156,47 @@
return;
}
- parseEntities( mappings );
- parseEmbeddable( mappings );
- parseMappedSuperClass( mappings );
+ AccessType accessType = determineGlobalAccessType( mappings );
+
+ parseEntities( mappings, accessType );
+ parseEmbeddable( mappings, accessType );
+ parseMappedSuperClass( mappings, accessType );
}
- private void parseEntities(EntityMappings mappings) {
+ private AccessType determineGlobalAccessType(EntityMappings mappings) {
+ AccessType accessType = DEFAULT_XML_ACCESS_TYPE;
+
+ if ( mappings.getAccess() != null ) {
+ accessType = mapXmlAccessTypeToJpaAccessType( mappings.getAccess() );
+ return accessType; // no need to check persistence unit default
+ }
+
+ PersistenceUnitMetadata meta = mappings.getPersistenceUnitMetadata();
+ if ( meta != null ) {
+ PersistenceUnitDefaults persistenceUnitDefaults = meta.getPersistenceUnitDefaults();
+ if ( persistenceUnitDefaults != null ) {
+ org.hibernate.jpa.metamodel.xml.jaxb.AccessType xmlAccessType = persistenceUnitDefaults.getAccess();
+ if ( xmlAccessType != null ) {
+ accessType = mapXmlAccessTypeToJpaAccessType( xmlAccessType );
+ }
+ }
+ }
+ return accessType;
+ }
+
+ private AccessType mapXmlAccessTypeToJpaAccessType(org.hibernate.jpa.metamodel.xml.jaxb.AccessType xmlAccessType) {
+ switch ( xmlAccessType ) {
+ case FIELD: {
+ return AccessType.FIELD;
+ }
+ case PROPERTY: {
+ return AccessType.PROPERTY;
+ }
+ }
+ return null;
+ }
+
+ private void parseEntities(EntityMappings mappings, AccessType accessType) {
String packageName = mappings.getPackage();
Collection<Entity> entities = mappings.getEntity();
for ( Entity entity : entities ) {
@@ -195,7 +234,7 @@
return utils.getTypeElement( fullyQualifiedClassName );
}
- private void parseEmbeddable(EntityMappings mappings) {
+ private void parseEmbeddable(EntityMappings mappings, AccessType accessType) {
String packageName = mappings.getPackage();
Collection<org.hibernate.jpa.metamodel.xml.jaxb.Embeddable> embeddables = mappings.getEmbeddable();
for ( org.hibernate.jpa.metamodel.xml.jaxb.Embeddable embeddable : embeddables ) {
@@ -223,7 +262,7 @@
}
}
- private void parseMappedSuperClass(EntityMappings mappings) {
+ private void parseMappedSuperClass(EntityMappings mappings, AccessType accessType) {
String packageName = mappings.getPackage();
Collection<org.hibernate.jpa.metamodel.xml.jaxb.MappedSuperclass> mappedSuperClasses = mappings.getMappedSuperclass();
for ( org.hibernate.jpa.metamodel.xml.jaxb.MappedSuperclass mappedSuperClass : mappedSuperClasses ) {
15 years, 3 months
Hibernate SVN: r17066 - jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-07-10 09:19:47 -0400 (Fri, 10 Jul 2009)
New Revision: 17066
Removed:
jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/JpaAnnotationsConstants.java
Log:
removed obsolete class
Deleted: jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/JpaAnnotationsConstants.java
===================================================================
--- jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/JpaAnnotationsConstants.java 2009-07-10 12:14:41 UTC (rev 17065)
+++ jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/JpaAnnotationsConstants.java 2009-07-10 13:19:47 UTC (rev 17066)
@@ -1,27 +0,0 @@
-package org.hibernate.jpa.metamodel.ap;
-
-public class JpaAnnotationsConstants {
- public static final String ANNOTATION_KEY_ALLOCATION_SIZE = "allocationSize()";
- public static final String ANNOTATION_KEY_COLUMN_DEFINITION = "columnDefinition()";
- public static final String ANNOTATION_KEY_DISCRIMINATOR_TYPE = "discriminatorType()";
- public static final String ANNOTATION_KEY_INITIAL_VALUE = "initialValue()";
- public static final String ANNOTATION_KEY_GENERATOR = "generator()";
- public static final String ANNOTATION_KEY_INSERTABLE = "insertable()";
- public static final String ANNOTATION_KEY_INVERSE_JOIN_COLUMNS = "inverseJoinColumns()";
- public static final String ANNOTATION_KEY_JOIN_COLUMNS = "joinColumns()";
- public static final String ANNOTATION_KEY_LENGTH = "length()";
- public static final String ANNOTATION_KEY_MAPPED_BY = "mappedBy()";
- public static final String ANNOTATION_KEY_NAME = "name()";
- public static final String ANNOTATION_KEY_NULLABLE = "nullable()";
- public static final String ANNOTATION_KEY_QUERY = "query()";
- public static final String ANNOTATION_KEY_REFERENCED_COLUMN_NAME = "referencedColumnName()";
- public static final String ANNOTATION_KEY_SEQUENCE_NAME = "sequenceName()";
- public static final String ANNOTATION_KEY_STRATEGY = "strategy()";
- public static final String ANNOTATION_TARGET_ENTITY = "targetEntity()";
- public static final String ANNOTATION_KEY_VALUE = "value()";
-
- public static final String JPA_VERSION = "1.0";
-
- public static final String PROCESSOR_USER_OPTION_XML_OVERRIDE = "xmlOverrideAnnotations";
- public static final String PROCESSOR_USER_OPTION_UPPER_COLUMN_NAMES = "useUpperCaseColumnNames";
-}
15 years, 3 months
Hibernate SVN: r17065 - in jpamodelgen/trunk: generator and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-07-10 08:14:41 -0400 (Fri, 10 Jul 2009)
New Revision: 17065
Modified:
jpamodelgen/trunk/generator/pom.xml
jpamodelgen/trunk/pom.xml
Log:
no need for a separate test project - can be done in a single project
Modified: jpamodelgen/trunk/generator/pom.xml
===================================================================
--- jpamodelgen/trunk/generator/pom.xml 2009-07-10 11:58:29 UTC (rev 17064)
+++ jpamodelgen/trunk/generator/pom.xml 2009-07-10 12:14:41 UTC (rev 17065)
@@ -19,7 +19,6 @@
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
- <version>5.8</version>
<classifier>jdk15</classifier>
</dependency>
</dependencies>
Modified: jpamodelgen/trunk/pom.xml
===================================================================
--- jpamodelgen/trunk/pom.xml 2009-07-10 11:58:29 UTC (rev 17064)
+++ jpamodelgen/trunk/pom.xml 2009-07-10 12:14:41 UTC (rev 17065)
@@ -31,7 +31,6 @@
<modules>
<module>generator</module>
- <module>test</module>
</modules>
<dependencyManagement>
@@ -42,16 +41,6 @@
<version>2.0.Beta3-SNAPSHOT</version>
</dependency>
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>1.5.6</version>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>1.5.6</version>
- </dependency>
- <dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>5.8</version>
15 years, 3 months
Hibernate SVN: r17064 - in jpamodelgen/trunk: generator/src/test and 15 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-07-10 07:58:29 -0400 (Fri, 10 Jul 2009)
New Revision: 17064
Added:
jpamodelgen/trunk/generator/src/test/java/model/
jpamodelgen/trunk/generator/src/test/java/model/Address.java
jpamodelgen/trunk/generator/src/test/java/model/Area.java
jpamodelgen/trunk/generator/src/test/java/model/Building.java
jpamodelgen/trunk/generator/src/test/java/model/Customer.java
jpamodelgen/trunk/generator/src/test/java/model/Detail.java
jpamodelgen/trunk/generator/src/test/java/model/Hominidae.java
jpamodelgen/trunk/generator/src/test/java/model/House.java
jpamodelgen/trunk/generator/src/test/java/model/Human.java
jpamodelgen/trunk/generator/src/test/java/model/Item.java
jpamodelgen/trunk/generator/src/test/java/model/LivingBeing.java
jpamodelgen/trunk/generator/src/test/java/model/Mammals.java
jpamodelgen/trunk/generator/src/test/java/model/Order.java
jpamodelgen/trunk/generator/src/test/java/model/Product.java
jpamodelgen/trunk/generator/src/test/java/model/Shop.java
jpamodelgen/trunk/generator/src/test/java/model/User.java
jpamodelgen/trunk/generator/src/test/java/model/xmlmapped/
jpamodelgen/trunk/generator/src/test/java/model/xmlmapped/Address.java
jpamodelgen/trunk/generator/src/test/java/model/xmlmapped/Building.java
jpamodelgen/trunk/generator/src/test/java/model/xmlmapped/LivingBeing.java
jpamodelgen/trunk/generator/src/test/java/model/xmlmapped/Mammal.java
jpamodelgen/trunk/generator/src/test/java/test/
jpamodelgen/trunk/generator/src/test/java/test/AccessTypeTest.java
jpamodelgen/trunk/generator/src/test/java/test/InheritanceTest.java
jpamodelgen/trunk/generator/src/test/java/test/QueryTest.java
jpamodelgen/trunk/generator/src/test/java/test/XmlMappingTest.java
jpamodelgen/trunk/generator/src/test/resources/META-INF/
jpamodelgen/trunk/generator/src/test/resources/META-INF/dummy.xml
jpamodelgen/trunk/generator/src/test/resources/META-INF/order.xml
jpamodelgen/trunk/generator/src/test/resources/META-INF/persistence.xml
jpamodelgen/trunk/generator/src/test/resources/model/
jpamodelgen/trunk/generator/src/test/resources/model/xmlmapped/
jpamodelgen/trunk/generator/src/test/resources/model/xmlmapped/address.xml
jpamodelgen/trunk/generator/src/test/resources/model/xmlmapped/building.xml
jpamodelgen/trunk/generator/src/test/resources/model/xmlmapped/mammal.xml
jpamodelgen/trunk/generator/src/test/suite/
jpamodelgen/trunk/generator/src/test/suite/unit-tests.xml
Removed:
jpamodelgen/trunk/test/src/main/java/model/Address.java
jpamodelgen/trunk/test/src/main/java/model/Area.java
jpamodelgen/trunk/test/src/main/java/model/Building.java
jpamodelgen/trunk/test/src/main/java/model/Customer.java
jpamodelgen/trunk/test/src/main/java/model/Detail.java
jpamodelgen/trunk/test/src/main/java/model/Hominidae.java
jpamodelgen/trunk/test/src/main/java/model/House.java
jpamodelgen/trunk/test/src/main/java/model/Human.java
jpamodelgen/trunk/test/src/main/java/model/Item.java
jpamodelgen/trunk/test/src/main/java/model/LivingBeing.java
jpamodelgen/trunk/test/src/main/java/model/Mammals.java
jpamodelgen/trunk/test/src/main/java/model/Order.java
jpamodelgen/trunk/test/src/main/java/model/Product.java
jpamodelgen/trunk/test/src/main/java/model/Shop.java
jpamodelgen/trunk/test/src/main/java/model/User.java
jpamodelgen/trunk/test/src/main/java/model/xmlmapped/Address.java
jpamodelgen/trunk/test/src/main/java/model/xmlmapped/Building.java
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/META-INF/dummy.xml
jpamodelgen/trunk/test/src/main/resources/META-INF/order.xml
jpamodelgen/trunk/test/src/main/resources/META-INF/persistence.xml
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
jpamodelgen/trunk/test/src/test/java/tests/AccessTypeTest.java
jpamodelgen/trunk/test/src/test/java/tests/InheritanceTest.java
jpamodelgen/trunk/test/src/test/java/tests/QueryTest.java
jpamodelgen/trunk/test/src/test/java/tests/XmlMappingTest.java
jpamodelgen/trunk/test/src/test/suite/unit-tests.xml
Modified:
jpamodelgen/trunk/generator/pom.xml
Log:
no need for a separate test project - can be done in a single project
Modified: jpamodelgen/trunk/generator/pom.xml
===================================================================
--- jpamodelgen/trunk/generator/pom.xml 2009-07-10 10:08:50 UTC (rev 17063)
+++ jpamodelgen/trunk/generator/pom.xml 2009-07-10 11:58:29 UTC (rev 17064)
@@ -1,4 +1,6 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodel-generator-parent</artifactId>
@@ -14,6 +16,12 @@
<groupId>org.hibernate.java-persistence</groupId>
<artifactId>jpa-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <version>5.8</version>
+ <classifier>jdk15</classifier>
+ </dependency>
</dependencies>
<build>
<defaultGoal>test</defaultGoal>
@@ -35,7 +43,59 @@
</configuration>
</plugin>
<plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>process_annotations</id>
+ <phase>process-test-resources</phase>
+ <configuration>
+ <tasks>
+ <property name="target.dir" value="target/generated-query-classes"/>
+ <mkdir dir="${target.dir}"/>
+ <javac srcdir="src/test/java" destdir="${target.dir}" failonerror="false" excludes="test/**">
+ <compilerarg value="-proc:only"/>
+ <classpath>
+ <path refid="maven.test.classpath"/>
+ </classpath>
+ </javac>
+ </tasks>
+ <sourceRoot>generate</sourceRoot>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ </executions>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.ant</groupId>
+ <artifactId>ant</artifactId>
+ <version>1.7.0</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ <plugin>
<groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <version>1.3</version>
+ <executions>
+ <execution>
+ <id>add-source</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>add-test-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>target/generated-query-classes</source>
+ </sources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<executions>
<execution>
@@ -66,6 +126,11 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <suiteXmlFiles>
+ <suiteXmlFile>${basedir}/src/test/suite/unit-tests.xml</suiteXmlFile>
+ </suiteXmlFiles>
+ </configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Added: jpamodelgen/trunk/generator/src/test/java/model/Address.java
===================================================================
--- jpamodelgen/trunk/generator/src/test/java/model/Address.java (rev 0)
+++ jpamodelgen/trunk/generator/src/test/java/model/Address.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -0,0 +1,37 @@
+package model;
+
+import javax.persistence.Embeddable;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Embeddable
+public class Address {
+ private String street1;
+ private String city;
+ private String country;
+
+ public String getStreet1() {
+ return street1;
+ }
+
+ public void setStreet1(String street1) {
+ this.street1 = street1;
+ }
+
+ public String getCity() {
+ return city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+ public String getCountry() {
+ return country;
+ }
+
+ public void setCountry(String country) {
+ this.country = country;
+ }
+}
Copied: jpamodelgen/trunk/generator/src/test/java/model/Area.java (from rev 17061, jpamodelgen/trunk/test/src/main/java/model/Area.java)
===================================================================
--- jpamodelgen/trunk/generator/src/test/java/model/Area.java (rev 0)
+++ jpamodelgen/trunk/generator/src/test/java/model/Area.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -0,0 +1,42 @@
+package model;
+
+import javax.persistence.MappedSuperclass;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@MappedSuperclass
+public class Area {
+ private int length;
+ private int width;
+ private int height;
+
+ //should not be persistent
+ public int getVolume() {
+ return length*width*height;
+ }
+
+ public int getLength() {
+ return length;
+ }
+
+ public void setLength(int length) {
+ this.length = length;
+ }
+
+ public int getWidth() {
+ return width;
+ }
+
+ public void setWidth(int width) {
+ this.width = width;
+ }
+
+ public int getHeight() {
+ return height;
+ }
+
+ public void setHeight(int height) {
+ this.height = height;
+ }
+}
Copied: jpamodelgen/trunk/generator/src/test/java/model/Building.java (from rev 17061, jpamodelgen/trunk/test/src/main/java/model/Building.java)
===================================================================
--- jpamodelgen/trunk/generator/src/test/java/model/Building.java (rev 0)
+++ jpamodelgen/trunk/generator/src/test/java/model/Building.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -0,0 +1,19 @@
+package model;
+
+import javax.persistence.MappedSuperclass;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@MappedSuperclass
+public class Building extends Area {
+ private Address address;
+
+ public Address getAddress() {
+ return address;
+ }
+
+ public void setAddress(Address address) {
+ this.address = address;
+ }
+}
Copied: jpamodelgen/trunk/generator/src/test/java/model/Customer.java (from rev 17061, jpamodelgen/trunk/test/src/main/java/model/Customer.java)
===================================================================
--- jpamodelgen/trunk/generator/src/test/java/model/Customer.java (rev 0)
+++ jpamodelgen/trunk/generator/src/test/java/model/Customer.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -0,0 +1,28 @@
+package model;
+
+import java.util.Set;
+import javax.persistence.Entity;
+import javax.persistence.OneToMany;
+import javax.persistence.Access;
+import javax.persistence.AccessType;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class Customer extends User {
+ private Set<Order> orders;
+ private String nonPersistent;
+
+ @Access(AccessType.FIELD)
+ boolean goodPayer;
+
+ public Set<Order> getOrders() {
+ return orders;
+ }
+
+ @OneToMany
+ public void setOrders(Set<Order> orders) {
+ this.orders = orders;
+ }
+}
Copied: jpamodelgen/trunk/generator/src/test/java/model/Detail.java (from rev 17061, jpamodelgen/trunk/test/src/main/java/model/Detail.java)
===================================================================
--- jpamodelgen/trunk/generator/src/test/java/model/Detail.java (rev 0)
+++ jpamodelgen/trunk/generator/src/test/java/model/Detail.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -0,0 +1,38 @@
+package model;
+
+import javax.persistence.Embeddable;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Embeddable
+public class Detail {
+ Integer length;
+ Integer width;
+ Integer height;
+ Integer nonPersistent;
+
+ public Integer getLength() {
+ return length;
+ }
+
+ public void setLength(Integer length) {
+ this.length = length;
+ }
+
+ public Integer getWidth() {
+ return width;
+ }
+
+ public void setWidth(Integer width) {
+ this.width = width;
+ }
+
+ public Integer getHeight() {
+ return height;
+ }
+
+ public void setHeight(Integer height) {
+ this.height = height;
+ }
+}
Copied: jpamodelgen/trunk/generator/src/test/java/model/Hominidae.java (from rev 17061, jpamodelgen/trunk/test/src/main/java/model/Hominidae.java)
===================================================================
--- jpamodelgen/trunk/generator/src/test/java/model/Hominidae.java (rev 0)
+++ jpamodelgen/trunk/generator/src/test/java/model/Hominidae.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -0,0 +1,26 @@
+package model;
+
+import javax.persistence.Entity;
+import javax.persistence.Access;
+import javax.persistence.AccessType;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+(a)Access(javax.persistence.AccessType.FIELD)
+public class Hominidae extends Mammals {
+ private int intelligence;
+
+ public int getIntelligence() {
+ return intelligence;
+ }
+
+ public void setIntelligence(int intelligence) {
+ this.intelligence = intelligence;
+ }
+
+ public int getNonPersistent() {
+ return 0;
+ }
+}
Copied: jpamodelgen/trunk/generator/src/test/java/model/House.java (from rev 17061, jpamodelgen/trunk/test/src/main/java/model/House.java)
===================================================================
--- jpamodelgen/trunk/generator/src/test/java/model/House.java (rev 0)
+++ jpamodelgen/trunk/generator/src/test/java/model/House.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -0,0 +1,21 @@
+package model;
+
+import javax.persistence.Id;
+import javax.persistence.Entity;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class House extends Building {
+ @Id
+ private Long id;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+}
Copied: jpamodelgen/trunk/generator/src/test/java/model/Human.java (from rev 17061, jpamodelgen/trunk/test/src/main/java/model/Human.java)
===================================================================
--- jpamodelgen/trunk/generator/src/test/java/model/Human.java (rev 0)
+++ jpamodelgen/trunk/generator/src/test/java/model/Human.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -0,0 +1,20 @@
+package model;
+
+import javax.persistence.Entity;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class Human extends Hominidae {
+ private int nonPersistent;
+ private String name;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Copied: jpamodelgen/trunk/generator/src/test/java/model/Item.java (from rev 17061, jpamodelgen/trunk/test/src/main/java/model/Item.java)
===================================================================
--- jpamodelgen/trunk/generator/src/test/java/model/Item.java (rev 0)
+++ jpamodelgen/trunk/generator/src/test/java/model/Item.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -0,0 +1,71 @@
+package model;
+
+import java.util.Map;
+import java.util.Set;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+
+@Entity
+public class Item {
+
+ long _id;
+
+ int _quantity;
+
+ Product _product;
+
+ Order _order;
+
+ Detail detail;
+
+ @Id
+ public long getId() {
+ return _id;
+ }
+
+ public void setId(long id) {
+ this._id = id;
+ }
+
+ public int getQuantity() {
+ return _quantity;
+ }
+
+ public void setQuantity(int quantity) {
+ this._quantity = quantity;
+ }
+
+ @ManyToOne
+ public Product getProduct() {
+ return _product;
+ }
+
+ public void setProduct(Product product) {
+ this._product = product;
+ }
+
+ @ManyToOne
+ public Order getOrder() {
+ return _order;
+ }
+
+ public void setOrder(Order order) {
+ this._order = order;
+ }
+
+ @OneToMany
+ public Map<String, Order> getNamedOrders() {
+ return null;
+ }
+
+ public Detail getDetail() {
+ return detail;
+ }
+
+ public void setDetail(Detail detail) {
+ this.detail = detail;
+ }
+}
Copied: jpamodelgen/trunk/generator/src/test/java/model/LivingBeing.java (from rev 17061, jpamodelgen/trunk/test/src/main/java/model/LivingBeing.java)
===================================================================
--- jpamodelgen/trunk/generator/src/test/java/model/LivingBeing.java (rev 0)
+++ jpamodelgen/trunk/generator/src/test/java/model/LivingBeing.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -0,0 +1,26 @@
+package model;
+
+import javax.persistence.MappedSuperclass;
+import javax.persistence.Access;
+import javax.persistence.AccessType;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@MappedSuperclass
+(a)Access(javax.persistence.AccessType.FIELD)
+public class LivingBeing {
+ boolean isReallyAlive;
+
+ public boolean isReallyAlive() {
+ return isReallyAlive;
+ }
+
+ public void setReallyAlive(boolean reallyAlive) {
+ isReallyAlive = reallyAlive;
+ }
+
+ public int nonPersistent() {
+ return 0;
+ }
+}
Copied: jpamodelgen/trunk/generator/src/test/java/model/Mammals.java (from rev 17061, jpamodelgen/trunk/test/src/main/java/model/Mammals.java)
===================================================================
--- jpamodelgen/trunk/generator/src/test/java/model/Mammals.java (rev 0)
+++ jpamodelgen/trunk/generator/src/test/java/model/Mammals.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -0,0 +1,30 @@
+package model;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class Mammals extends LivingBeing {
+ private String id;
+ private String nbrOfMammals;
+
+ @Id
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getNbrOfMammals() {
+ return nbrOfMammals;
+ }
+
+ public void setNbrOfMammals(String nbrOfMammals) {
+ this.nbrOfMammals = nbrOfMammals;
+ }
+}
Copied: jpamodelgen/trunk/generator/src/test/java/model/Order.java (from rev 17061, jpamodelgen/trunk/test/src/main/java/model/Order.java)
===================================================================
--- jpamodelgen/trunk/generator/src/test/java/model/Order.java (rev 0)
+++ jpamodelgen/trunk/generator/src/test/java/model/Order.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -0,0 +1,28 @@
+package model;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+import java.util.Date;
+import java.util.List;
+import java.util.Set;
+
+//@Entity
+public class Order {
+
+ //@Id
+ long id;
+
+ //@OneToMany
+ Set<Item> items;
+
+ boolean filled;
+ Date date;
+
+ //@OneToMany
+ List<String> notes;
+
+ //@ManyToOne
+ Shop shop;
+}
Copied: jpamodelgen/trunk/generator/src/test/java/model/Product.java (from rev 17061, jpamodelgen/trunk/test/src/main/java/model/Product.java)
===================================================================
--- jpamodelgen/trunk/generator/src/test/java/model/Product.java (rev 0)
+++ jpamodelgen/trunk/generator/src/test/java/model/Product.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -0,0 +1,30 @@
+package model;
+
+import java.math.BigDecimal;
+import java.util.Set;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+
+@Entity
+public class Product {
+
+ transient String nonPersistent;
+ static String nonPersistent2;
+
+ @Id
+ long id;
+
+ int test;
+
+ String description;
+ BigDecimal price;
+
+ @ManyToOne
+ Shop shop;
+
+ @OneToMany
+ Set<Item> items;
+}
Copied: jpamodelgen/trunk/generator/src/test/java/model/Shop.java (from rev 17061, jpamodelgen/trunk/test/src/main/java/model/Shop.java)
===================================================================
--- jpamodelgen/trunk/generator/src/test/java/model/Shop.java (rev 0)
+++ jpamodelgen/trunk/generator/src/test/java/model/Shop.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -0,0 +1,12 @@
+package model;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+@Entity
+public class Shop {
+ @Id
+ long id;
+ String name;
+}
+
\ No newline at end of file
Copied: jpamodelgen/trunk/generator/src/test/java/model/User.java (from rev 17061, jpamodelgen/trunk/test/src/main/java/model/User.java)
===================================================================
--- jpamodelgen/trunk/generator/src/test/java/model/User.java (rev 0)
+++ jpamodelgen/trunk/generator/src/test/java/model/User.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -0,0 +1,41 @@
+package model;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Transient;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class User {
+ private Long id;
+ private String nonPersistent;
+ private String name;
+
+ @Id
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ @Transient
+ public String getNonPersistent() {
+ return nonPersistent;
+ }
+
+ public void setNonPersistent(String nonPersistent) {
+ this.nonPersistent = nonPersistent;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Copied: jpamodelgen/trunk/generator/src/test/java/model/xmlmapped/Address.java (from rev 17061, jpamodelgen/trunk/test/src/main/java/model/xmlmapped/Address.java)
===================================================================
--- jpamodelgen/trunk/generator/src/test/java/model/xmlmapped/Address.java (rev 0)
+++ jpamodelgen/trunk/generator/src/test/java/model/xmlmapped/Address.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -0,0 +1,34 @@
+package model.xmlmapped;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class Address {
+ private String street1;
+ private String city;
+ private String country;
+
+ public String getStreet1() {
+ return street1;
+ }
+
+ public void setStreet1(String street1) {
+ this.street1 = street1;
+ }
+
+ public String getCity() {
+ return city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+ public String getCountry() {
+ return country;
+ }
+
+ public void setCountry(String country) {
+ this.country = country;
+ }
+}
\ No newline at end of file
Copied: jpamodelgen/trunk/generator/src/test/java/model/xmlmapped/Building.java (from rev 17061, jpamodelgen/trunk/test/src/main/java/model/xmlmapped/Building.java)
===================================================================
--- jpamodelgen/trunk/generator/src/test/java/model/xmlmapped/Building.java (rev 0)
+++ jpamodelgen/trunk/generator/src/test/java/model/xmlmapped/Building.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -0,0 +1,19 @@
+package model.xmlmapped;
+
+import model.Address;
+import model.Area;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class Building extends Area {
+ private Address address;
+
+ public Address getAddress() {
+ return address;
+ }
+
+ public void setAddress(Address address) {
+ this.address = address;
+ }
+}
\ No newline at end of file
Copied: jpamodelgen/trunk/generator/src/test/java/model/xmlmapped/LivingBeing.java (from rev 17062, jpamodelgen/trunk/test/src/main/java/model/xmlmapped/LivingBeing.java)
===================================================================
--- jpamodelgen/trunk/generator/src/test/java/model/xmlmapped/LivingBeing.java (rev 0)
+++ jpamodelgen/trunk/generator/src/test/java/model/xmlmapped/LivingBeing.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -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/generator/src/test/java/model/xmlmapped/Mammal.java (from rev 17062, jpamodelgen/trunk/test/src/main/java/model/xmlmapped/Mammal.java)
===================================================================
--- jpamodelgen/trunk/generator/src/test/java/model/xmlmapped/Mammal.java (rev 0)
+++ jpamodelgen/trunk/generator/src/test/java/model/xmlmapped/Mammal.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -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
Copied: jpamodelgen/trunk/generator/src/test/java/test/AccessTypeTest.java (from rev 17061, jpamodelgen/trunk/test/src/test/java/tests/AccessTypeTest.java)
===================================================================
--- jpamodelgen/trunk/generator/src/test/java/test/AccessTypeTest.java (rev 0)
+++ jpamodelgen/trunk/generator/src/test/java/test/AccessTypeTest.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -0,0 +1,75 @@
+package test;
+
+import java.lang.reflect.Field;
+
+import org.testng.annotations.Test;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.Assert;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Test
+public class AccessTypeTest {
+
+ @Test
+ public void testExcludeTransientFieldAndStatic() throws Exception{
+ absenceOfField( "model.Product_", "nonPersistent" );
+ absenceOfField( "model.Product_", "nonPersistent2" );
+ }
+
+ @Test
+ public void testDefaultAccessTypeOnEntity() throws Exception{
+ absenceOfField( "model.User_", "nonPersistent" );
+ }
+
+ @Test
+ public void testDefaultAccessTypeForSubclassOfEntity() throws Exception{
+ absenceOfField( "model.Customer_", "nonPersistent" );
+ }
+
+ @Test
+ public void testDefaultAccessTypeForEmbeddable() throws Exception{
+ absenceOfField( "model.Detail_", "nonPersistent " );
+ }
+
+ @Test
+ public void testDefaultAccessTypeForMappedSuperclass() throws Exception{
+ absenceOfField( "model.Detail_", "volume" );
+ }
+
+ @Test
+ public void testExplicitAccessTypeAndDefaultFromRootEntity() throws Exception{
+ absenceOfField( "model.LivingBeing_", "nonPersistent", "eplicit access type on mapped superclass" );
+ absenceOfField( "model.Hominidae_", "nonPersistent", "eplicit access type on entity" );
+ absenceOfField( "model.Human_", "nonPersistent", "proper inheritance from root entity access type" );
+ }
+
+ @Test
+ public void testMemberAccessType() throws Exception{
+ presenceOfField( "model.Customer_", "goodPayer", "access type overriding" );
+ }
+
+ private void absenceOfField(String className, String fieldName) throws ClassNotFoundException {
+ absenceOfField( className, fieldName, "field should not be persistent" );
+ }
+ private void absenceOfField(String className, String fieldName, String errorString) throws ClassNotFoundException {
+ Assert.assertFalse( isFieldHere(className, fieldName), errorString );
+ }
+
+ private void presenceOfField(String className, String fieldName, String errorString) throws ClassNotFoundException {
+ Assert.assertTrue( isFieldHere(className, fieldName), errorString );
+ }
+
+ private boolean isFieldHere(String className, String fieldName) throws ClassNotFoundException {
+ Class<?> user_ = Class.forName( className );
+ try {
+ final Field field = user_.getField( fieldName );
+ return true;
+ }
+ catch (NoSuchFieldException e) {
+ return false;
+ }
+ }
+}
Copied: jpamodelgen/trunk/generator/src/test/java/test/InheritanceTest.java (from rev 17061, jpamodelgen/trunk/test/src/test/java/tests/InheritanceTest.java)
===================================================================
--- jpamodelgen/trunk/generator/src/test/java/test/InheritanceTest.java (rev 0)
+++ jpamodelgen/trunk/generator/src/test/java/test/InheritanceTest.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -0,0 +1,29 @@
+package test;
+
+import org.testng.annotations.Test;
+import org.testng.Assert;
+import model.Customer_;
+import model.User_;
+import model.House_;
+import model.Building_;
+import model.Area_;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Test
+public class InheritanceTest {
+ @Test
+ public void testSuperEntity() throws Exception {
+ Assert.assertEquals( Customer_.class.getSuperclass(), User_.class,
+ "Entity with super entity should inherit at the metamodel level");
+ }
+
+ @Test
+ public void testMappedSuperclass() throws Exception {
+ Assert.assertEquals( House_.class.getSuperclass(), Building_.class,
+ "Entity with mapped superclass should inherit at the metamodel level");
+ Assert.assertEquals( Building_.class.getSuperclass(), Area_.class,
+ "mapped superclass with mapped superclass should inherit at the metamodel level");
+ }
+}
Copied: jpamodelgen/trunk/generator/src/test/java/test/QueryTest.java (from rev 17061, jpamodelgen/trunk/test/src/test/java/tests/QueryTest.java)
===================================================================
--- jpamodelgen/trunk/generator/src/test/java/test/QueryTest.java (rev 0)
+++ jpamodelgen/trunk/generator/src/test/java/test/QueryTest.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -0,0 +1,146 @@
+package test;
+
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.Set;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Expression;
+import javax.persistence.criteria.Join;
+import static javax.persistence.criteria.JoinType.INNER;
+import javax.persistence.criteria.ListJoin;
+import javax.persistence.criteria.Path;
+import javax.persistence.criteria.QueryBuilder;
+import javax.persistence.criteria.Root;
+import javax.persistence.Tuple;
+
+import model.Item;
+import model.Order;
+import model.Product;
+import model.Item_;
+import model.Order_;
+import model.Product_;
+import model.Shop_;
+
+/**
+ * Writing queries involves passing typesafe, statically cached, metamodel
+ * objects to the query builder in order to create the various parts of
+ * the query. The typesafe metamodel objects were validated at init time,
+ * so it is impossible to build invalid queries in the application code.
+ */
+public class QueryTest {
+
+ QueryBuilder qb;
+
+ public void test() {
+ CriteriaQuery<Tuple> q = qb.createTupleQuery();
+
+ Root<Order> order = q.from(Order.class);
+ Join<Item, Product> product = order.join(Order_.items)
+ .join(Item_.product);
+
+ Path<BigDecimal> price = product.get(Product_.price);
+ Path<Boolean> filled = order.get(Order_.filled);
+ Path<Date> date = order.get(Order_.date);
+
+ q.select( qb.tuple( order, product ) )
+ .where( qb.and( qb.gt(price, 100.00), qb.not(filled) ) )
+ .orderBy( qb.asc(price), qb.desc(date) );
+ }
+
+ public void testUntypesafe() {
+ CriteriaQuery<Tuple> q = qb.createTupleQuery();
+
+ Root<Order> order = q.from(Order.class);
+ Join<Item, Product> product = order.join("items")
+ .join("product");
+
+ Path<BigDecimal> price = product.get("price");
+ Path<Boolean> filled = order.get("filled");
+ Path<Date> date = order.get("date");
+
+ q.select( qb.tuple( order, product ) )
+ .where( qb.and( qb.gt(price, 100.00), qb.not(filled) ) )
+ .orderBy( qb.asc(price), qb.desc(date) );
+ }
+
+ /**
+ * Navigation by joining
+ */
+ public void test2() {
+ CriteriaQuery<Product> q = qb.createQuery(Product.class);
+
+ Root<Product> product = q.from(Product.class);
+ Join<Item, Order> order = product.join(Product_.items)
+ .join(Item_.order);
+
+ q.select(product)
+ .where( qb.equal(order.get(Order_.id), 12345l) );
+ }
+
+ public void testMap() {
+ CriteriaQuery<Item> q = qb.createQuery(Item.class);
+
+ Root<Item> item = q.from(Item.class);
+ Join<Item, Order> io = item.join(Item_.namedOrders);
+
+ }
+
+ /**
+ * Navigation by compound Path
+ */
+ public void test3() {
+ CriteriaQuery<Item> q = qb.createQuery(Item.class);
+
+ Root<Item> item = q.from(Item.class);
+ Path<String> shopName = item.get(Item_.order)
+ .get(Order_.shop)
+ .get(Shop_.name);
+ q.select(item)
+ .where( qb.equal(shopName, "amazon.com") );
+ }
+
+// public void test4() {
+// CriteriaQuery q = qb.create();
+//
+// Root<Order> order = q.from(Order.class);
+// ListJoin<Order, String> note = order.join(Order_.notes);
+// Expression<Set<Item>> items = order.get(Order_.items);
+// order.fetch(Order_.items, JoinType.INNER);
+//
+// q.select(note)
+// .where( qb.and( qb.lt(note.index(), 10), qb.isNotEmpty(items) ) );
+// }
+
+ public void test4Untypesafe() {
+ CriteriaQuery<String> q = qb.createQuery(String.class);
+
+ Root<Order> order = q.from(Order.class);
+ ListJoin<Order, String> note = order.joinList("notes");
+ Expression<Set<Item>> items = order.get("items");
+ order.fetch("items", INNER);
+
+ q.select(note)
+ .where( qb.and( qb.lt(note.index(), 10), qb.isNotEmpty(items) ) );
+ }
+
+ /*public void test5() {
+ Expression<Long> l= null;
+ Expression<Integer> i= null;
+ Expression<Float> x= null;
+ Expression<Float> y= null;
+
+ Expression<Number> n;
+ Expression<Float> f;
+ Expression<String> s = null;
+
+ n = qb.quot(l, i);
+
+ f = qb.sum(x, y);
+
+ n = qb.quot(x, y);
+
+ javax.jpa.criteria.Order o = qb.asc(n);
+ javax.jpa.criteria.Order p = qb.ascending(s);
+ }*/
+
+}
Copied: jpamodelgen/trunk/generator/src/test/java/test/XmlMappingTest.java (from rev 17063, jpamodelgen/trunk/test/src/test/java/tests/XmlMappingTest.java)
===================================================================
--- jpamodelgen/trunk/generator/src/test/java/test/XmlMappingTest.java (rev 0)
+++ jpamodelgen/trunk/generator/src/test/java/test/XmlMappingTest.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -0,0 +1,38 @@
+package test;
+
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class XmlMappingTest {
+ @Test
+ public void testXmlConfiguredEmbeddedClassGenerated() throws Exception {
+ assertNotNull( Class.forName( "model.xmlmapped.Address_" ) );
+ }
+
+ @Test
+ public void testXmlConfiguredMappedSuperclassGenerated() throws Exception {
+ Class<?> building = Class.forName( "model.xmlmapped.Building_" );
+ assertNotNull( building );
+ 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 ) );
+ }
+
+ @Test(expectedExceptions = ClassNotFoundException.class)
+ public void testNonExistentMappedClassesGetIgnored() throws Exception {
+ Class.forName( "model.Dummy_" );
+ }
+}
\ No newline at end of file
Copied: jpamodelgen/trunk/generator/src/test/resources/META-INF/dummy.xml (from rev 17063, jpamodelgen/trunk/test/src/main/resources/META-INF/dummy.xml)
===================================================================
--- jpamodelgen/trunk/generator/src/test/resources/META-INF/dummy.xml (rev 0)
+++ jpamodelgen/trunk/generator/src/test/resources/META-INF/dummy.xml 2009-07-10 11:58:29 UTC (rev 17064)
@@ -0,0 +1,14 @@
+<?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</package>
+ <entity class="Dummy" access="FIELD" metadata-complete="true"> <!-- Class does not exist -->
+ <attributes>
+ <id name="id"/>
+ </attributes>
+ </entity>
+</entity-mappings>
Copied: jpamodelgen/trunk/generator/src/test/resources/META-INF/order.xml (from rev 17062, jpamodelgen/trunk/test/src/main/resources/META-INF/order.xml)
===================================================================
--- jpamodelgen/trunk/generator/src/test/resources/META-INF/order.xml (rev 0)
+++ jpamodelgen/trunk/generator/src/test/resources/META-INF/order.xml 2009-07-10 11:58:29 UTC (rev 17064)
@@ -0,0 +1,36 @@
+<?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</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 name="date"/>
+ <one-to-many name="items" target-entity="Item" fetch="EAGER"> <!-- target-entity optional guess the type from the geenric-->
+ <cascade>
+ <cascade-persist/>
+ </cascade>
+ </one-to-many>
+ <many-to-one name="shop"/>
+ <element-collection name="notes"/> <!-- new in JPA 2 -->
+ </attributes>
+ </entity>
+</entity-mappings>
+
+
+ <!--
+public class Order {
+ long id;
+ Set<Item> items;
+ boolean filled;
+ Date date;
+ List<String> notes;
+ Shop shop;
+} -->
\ No newline at end of file
Copied: jpamodelgen/trunk/generator/src/test/resources/META-INF/persistence.xml (from rev 17063, jpamodelgen/trunk/test/src/main/resources/META-INF/persistence.xml)
===================================================================
--- jpamodelgen/trunk/generator/src/test/resources/META-INF/persistence.xml (rev 0)
+++ jpamodelgen/trunk/generator/src/test/resources/META-INF/persistence.xml 2009-07-10 11:58:29 UTC (rev 17064)
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence xmlns="http://java.sun.com/xml/ns/persistence"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/persistence persistence.xsd" version="2.0">
+ <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/dummy.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/generator/src/test/resources/model/xmlmapped/address.xml (from rev 17062, jpamodelgen/trunk/test/src/main/resources/model/xmlmapped/address.xml)
===================================================================
--- jpamodelgen/trunk/generator/src/test/resources/model/xmlmapped/address.xml (rev 0)
+++ jpamodelgen/trunk/generator/src/test/resources/model/xmlmapped/address.xml 2009-07-10 11:58:29 UTC (rev 17064)
@@ -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/generator/src/test/resources/model/xmlmapped/building.xml (from rev 17062, jpamodelgen/trunk/test/src/main/resources/model/xmlmapped/building.xml)
===================================================================
--- jpamodelgen/trunk/generator/src/test/resources/model/xmlmapped/building.xml (rev 0)
+++ jpamodelgen/trunk/generator/src/test/resources/model/xmlmapped/building.xml 2009-07-10 11:58:29 UTC (rev 17064)
@@ -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/generator/src/test/resources/model/xmlmapped/mammal.xml (from rev 17062, jpamodelgen/trunk/test/src/main/resources/model/xmlmapped/mammal.xml)
===================================================================
--- jpamodelgen/trunk/generator/src/test/resources/model/xmlmapped/mammal.xml (rev 0)
+++ jpamodelgen/trunk/generator/src/test/resources/model/xmlmapped/mammal.xml 2009-07-10 11:58:29 UTC (rev 17064)
@@ -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>
Copied: jpamodelgen/trunk/generator/src/test/suite/unit-tests.xml (from rev 17061, jpamodelgen/trunk/test/src/test/suite/unit-tests.xml)
===================================================================
--- jpamodelgen/trunk/generator/src/test/suite/unit-tests.xml (rev 0)
+++ jpamodelgen/trunk/generator/src/test/suite/unit-tests.xml 2009-07-10 11:58:29 UTC (rev 17064)
@@ -0,0 +1,9 @@
+<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
+
+<suite name="Hibernate Model Generator Tests" verbose="1">
+ <test name="Unit tests">
+ <packages>
+ <package name="test"/>
+ </packages>
+ </test>
+</suite>
\ No newline at end of file
Deleted: jpamodelgen/trunk/test/src/main/java/model/Address.java
===================================================================
--- jpamodelgen/trunk/test/src/main/java/model/Address.java 2009-07-10 10:08:50 UTC (rev 17063)
+++ jpamodelgen/trunk/test/src/main/java/model/Address.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -1,37 +0,0 @@
-package model;
-
-import javax.persistence.Embeddable;
-
-/**
- * @author Emmanuel Bernard
- */
-@Embeddable
-public class Address {
- private String street1;
- private String city;
- private String country;
-
- public String getStreet1() {
- return street1;
- }
-
- public void setStreet1(String street1) {
- this.street1 = street1;
- }
-
- public String getCity() {
- return city;
- }
-
- public void setCity(String city) {
- this.city = city;
- }
-
- public String getCountry() {
- return country;
- }
-
- public void setCountry(String country) {
- this.country = country;
- }
-}
Deleted: jpamodelgen/trunk/test/src/main/java/model/Area.java
===================================================================
--- jpamodelgen/trunk/test/src/main/java/model/Area.java 2009-07-10 10:08:50 UTC (rev 17063)
+++ jpamodelgen/trunk/test/src/main/java/model/Area.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -1,42 +0,0 @@
-package model;
-
-import javax.persistence.MappedSuperclass;
-
-/**
- * @author Emmanuel Bernard
- */
-@MappedSuperclass
-public class Area {
- private int length;
- private int width;
- private int height;
-
- //should not be persistent
- public int getVolume() {
- return length*width*height;
- }
-
- public int getLength() {
- return length;
- }
-
- public void setLength(int length) {
- this.length = length;
- }
-
- public int getWidth() {
- return width;
- }
-
- public void setWidth(int width) {
- this.width = width;
- }
-
- public int getHeight() {
- return height;
- }
-
- public void setHeight(int height) {
- this.height = height;
- }
-}
Deleted: jpamodelgen/trunk/test/src/main/java/model/Building.java
===================================================================
--- jpamodelgen/trunk/test/src/main/java/model/Building.java 2009-07-10 10:08:50 UTC (rev 17063)
+++ jpamodelgen/trunk/test/src/main/java/model/Building.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -1,19 +0,0 @@
-package model;
-
-import javax.persistence.MappedSuperclass;
-
-/**
- * @author Emmanuel Bernard
- */
-@MappedSuperclass
-public class Building extends Area {
- private Address address;
-
- public Address getAddress() {
- return address;
- }
-
- public void setAddress(Address address) {
- this.address = address;
- }
-}
Deleted: jpamodelgen/trunk/test/src/main/java/model/Customer.java
===================================================================
--- jpamodelgen/trunk/test/src/main/java/model/Customer.java 2009-07-10 10:08:50 UTC (rev 17063)
+++ jpamodelgen/trunk/test/src/main/java/model/Customer.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -1,28 +0,0 @@
-package model;
-
-import java.util.Set;
-import javax.persistence.Entity;
-import javax.persistence.OneToMany;
-import javax.persistence.Access;
-import javax.persistence.AccessType;
-
-/**
- * @author Emmanuel Bernard
- */
-@Entity
-public class Customer extends User {
- private Set<Order> orders;
- private String nonPersistent;
-
- @Access(AccessType.FIELD)
- boolean goodPayer;
-
- public Set<Order> getOrders() {
- return orders;
- }
-
- @OneToMany
- public void setOrders(Set<Order> orders) {
- this.orders = orders;
- }
-}
Deleted: jpamodelgen/trunk/test/src/main/java/model/Detail.java
===================================================================
--- jpamodelgen/trunk/test/src/main/java/model/Detail.java 2009-07-10 10:08:50 UTC (rev 17063)
+++ jpamodelgen/trunk/test/src/main/java/model/Detail.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -1,38 +0,0 @@
-package model;
-
-import javax.persistence.Embeddable;
-
-/**
- * @author Emmanuel Bernard
- */
-@Embeddable
-public class Detail {
- Integer length;
- Integer width;
- Integer height;
- Integer nonPersistent;
-
- public Integer getLength() {
- return length;
- }
-
- public void setLength(Integer length) {
- this.length = length;
- }
-
- public Integer getWidth() {
- return width;
- }
-
- public void setWidth(Integer width) {
- this.width = width;
- }
-
- public Integer getHeight() {
- return height;
- }
-
- public void setHeight(Integer height) {
- this.height = height;
- }
-}
Deleted: jpamodelgen/trunk/test/src/main/java/model/Hominidae.java
===================================================================
--- jpamodelgen/trunk/test/src/main/java/model/Hominidae.java 2009-07-10 10:08:50 UTC (rev 17063)
+++ jpamodelgen/trunk/test/src/main/java/model/Hominidae.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -1,26 +0,0 @@
-package model;
-
-import javax.persistence.Entity;
-import javax.persistence.Access;
-import javax.persistence.AccessType;
-
-/**
- * @author Emmanuel Bernard
- */
-@Entity
-(a)Access(javax.persistence.AccessType.FIELD)
-public class Hominidae extends Mammals {
- private int intelligence;
-
- public int getIntelligence() {
- return intelligence;
- }
-
- public void setIntelligence(int intelligence) {
- this.intelligence = intelligence;
- }
-
- public int getNonPersistent() {
- return 0;
- }
-}
Deleted: jpamodelgen/trunk/test/src/main/java/model/House.java
===================================================================
--- jpamodelgen/trunk/test/src/main/java/model/House.java 2009-07-10 10:08:50 UTC (rev 17063)
+++ jpamodelgen/trunk/test/src/main/java/model/House.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -1,21 +0,0 @@
-package model;
-
-import javax.persistence.Id;
-import javax.persistence.Entity;
-
-/**
- * @author Emmanuel Bernard
- */
-@Entity
-public class House extends Building {
- @Id
- private Long id;
-
- public Long getId() {
- return id;
- }
-
- public void setId(Long id) {
- this.id = id;
- }
-}
Deleted: jpamodelgen/trunk/test/src/main/java/model/Human.java
===================================================================
--- jpamodelgen/trunk/test/src/main/java/model/Human.java 2009-07-10 10:08:50 UTC (rev 17063)
+++ jpamodelgen/trunk/test/src/main/java/model/Human.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -1,20 +0,0 @@
-package model;
-
-import javax.persistence.Entity;
-
-/**
- * @author Emmanuel Bernard
- */
-@Entity
-public class Human extends Hominidae {
- private int nonPersistent;
- private String name;
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-}
Deleted: jpamodelgen/trunk/test/src/main/java/model/Item.java
===================================================================
--- jpamodelgen/trunk/test/src/main/java/model/Item.java 2009-07-10 10:08:50 UTC (rev 17063)
+++ jpamodelgen/trunk/test/src/main/java/model/Item.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -1,71 +0,0 @@
-package model;
-
-import java.util.Map;
-import java.util.Set;
-
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.ManyToOne;
-import javax.persistence.OneToMany;
-
-@Entity
-public class Item {
-
- long _id;
-
- int _quantity;
-
- Product _product;
-
- Order _order;
-
- Detail detail;
-
- @Id
- public long getId() {
- return _id;
- }
-
- public void setId(long id) {
- this._id = id;
- }
-
- public int getQuantity() {
- return _quantity;
- }
-
- public void setQuantity(int quantity) {
- this._quantity = quantity;
- }
-
- @ManyToOne
- public Product getProduct() {
- return _product;
- }
-
- public void setProduct(Product product) {
- this._product = product;
- }
-
- @ManyToOne
- public Order getOrder() {
- return _order;
- }
-
- public void setOrder(Order order) {
- this._order = order;
- }
-
- @OneToMany
- public Map<String, Order> getNamedOrders() {
- return null;
- }
-
- public Detail getDetail() {
- return detail;
- }
-
- public void setDetail(Detail detail) {
- this.detail = detail;
- }
-}
Deleted: jpamodelgen/trunk/test/src/main/java/model/LivingBeing.java
===================================================================
--- jpamodelgen/trunk/test/src/main/java/model/LivingBeing.java 2009-07-10 10:08:50 UTC (rev 17063)
+++ jpamodelgen/trunk/test/src/main/java/model/LivingBeing.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -1,26 +0,0 @@
-package model;
-
-import javax.persistence.MappedSuperclass;
-import javax.persistence.Access;
-import javax.persistence.AccessType;
-
-/**
- * @author Emmanuel Bernard
- */
-@MappedSuperclass
-(a)Access(javax.persistence.AccessType.FIELD)
-public class LivingBeing {
- boolean isReallyAlive;
-
- public boolean isReallyAlive() {
- return isReallyAlive;
- }
-
- public void setReallyAlive(boolean reallyAlive) {
- isReallyAlive = reallyAlive;
- }
-
- public int nonPersistent() {
- return 0;
- }
-}
Deleted: jpamodelgen/trunk/test/src/main/java/model/Mammals.java
===================================================================
--- jpamodelgen/trunk/test/src/main/java/model/Mammals.java 2009-07-10 10:08:50 UTC (rev 17063)
+++ jpamodelgen/trunk/test/src/main/java/model/Mammals.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -1,30 +0,0 @@
-package model;
-
-import javax.persistence.Entity;
-import javax.persistence.Id;
-
-/**
- * @author Emmanuel Bernard
- */
-@Entity
-public class Mammals extends LivingBeing {
- private String id;
- private String nbrOfMammals;
-
- @Id
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public String getNbrOfMammals() {
- return nbrOfMammals;
- }
-
- public void setNbrOfMammals(String nbrOfMammals) {
- this.nbrOfMammals = nbrOfMammals;
- }
-}
Deleted: jpamodelgen/trunk/test/src/main/java/model/Order.java
===================================================================
--- jpamodelgen/trunk/test/src/main/java/model/Order.java 2009-07-10 10:08:50 UTC (rev 17063)
+++ jpamodelgen/trunk/test/src/main/java/model/Order.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -1,28 +0,0 @@
-package model;
-
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.ManyToOne;
-import javax.persistence.OneToMany;
-import java.util.Date;
-import java.util.List;
-import java.util.Set;
-
-//@Entity
-public class Order {
-
- //@Id
- long id;
-
- //@OneToMany
- Set<Item> items;
-
- boolean filled;
- Date date;
-
- //@OneToMany
- List<String> notes;
-
- //@ManyToOne
- Shop shop;
-}
Deleted: jpamodelgen/trunk/test/src/main/java/model/Product.java
===================================================================
--- jpamodelgen/trunk/test/src/main/java/model/Product.java 2009-07-10 10:08:50 UTC (rev 17063)
+++ jpamodelgen/trunk/test/src/main/java/model/Product.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -1,30 +0,0 @@
-package model;
-
-import java.math.BigDecimal;
-import java.util.Set;
-
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.ManyToOne;
-import javax.persistence.OneToMany;
-
-@Entity
-public class Product {
-
- transient String nonPersistent;
- static String nonPersistent2;
-
- @Id
- long id;
-
- int test;
-
- String description;
- BigDecimal price;
-
- @ManyToOne
- Shop shop;
-
- @OneToMany
- Set<Item> items;
-}
Deleted: jpamodelgen/trunk/test/src/main/java/model/Shop.java
===================================================================
--- jpamodelgen/trunk/test/src/main/java/model/Shop.java 2009-07-10 10:08:50 UTC (rev 17063)
+++ jpamodelgen/trunk/test/src/main/java/model/Shop.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -1,12 +0,0 @@
-package model;
-
-import javax.persistence.Entity;
-import javax.persistence.Id;
-
-@Entity
-public class Shop {
- @Id
- long id;
- String name;
-}
-
\ No newline at end of file
Deleted: jpamodelgen/trunk/test/src/main/java/model/User.java
===================================================================
--- jpamodelgen/trunk/test/src/main/java/model/User.java 2009-07-10 10:08:50 UTC (rev 17063)
+++ jpamodelgen/trunk/test/src/main/java/model/User.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -1,41 +0,0 @@
-package model;
-
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.Transient;
-
-/**
- * @author Emmanuel Bernard
- */
-@Entity
-public class User {
- private Long id;
- private String nonPersistent;
- private String name;
-
- @Id
- public Long getId() {
- return id;
- }
-
- public void setId(Long id) {
- this.id = id;
- }
-
- @Transient
- public String getNonPersistent() {
- return nonPersistent;
- }
-
- public void setNonPersistent(String nonPersistent) {
- this.nonPersistent = nonPersistent;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-}
Deleted: jpamodelgen/trunk/test/src/main/java/model/xmlmapped/Address.java
===================================================================
--- jpamodelgen/trunk/test/src/main/java/model/xmlmapped/Address.java 2009-07-10 10:08:50 UTC (rev 17063)
+++ jpamodelgen/trunk/test/src/main/java/model/xmlmapped/Address.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -1,34 +0,0 @@
-package model.xmlmapped;
-
-/**
- * @author Emmanuel Bernard
- */
-public class Address {
- private String street1;
- private String city;
- private String country;
-
- public String getStreet1() {
- return street1;
- }
-
- public void setStreet1(String street1) {
- this.street1 = street1;
- }
-
- public String getCity() {
- return city;
- }
-
- public void setCity(String city) {
- this.city = city;
- }
-
- public String getCountry() {
- return country;
- }
-
- public void setCountry(String country) {
- this.country = country;
- }
-}
\ No newline at end of file
Deleted: jpamodelgen/trunk/test/src/main/java/model/xmlmapped/Building.java
===================================================================
--- jpamodelgen/trunk/test/src/main/java/model/xmlmapped/Building.java 2009-07-10 10:08:50 UTC (rev 17063)
+++ jpamodelgen/trunk/test/src/main/java/model/xmlmapped/Building.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -1,19 +0,0 @@
-package model.xmlmapped;
-
-import model.Address;
-import model.Area;
-
-/**
- * @author Emmanuel Bernard
- */
-public class Building extends Area {
- private Address address;
-
- public Address getAddress() {
- return address;
- }
-
- public void setAddress(Address address) {
- this.address = address;
- }
-}
\ No newline at end of file
Deleted: jpamodelgen/trunk/test/src/main/java/model/xmlmapped/LivingBeing.java
===================================================================
--- jpamodelgen/trunk/test/src/main/java/model/xmlmapped/LivingBeing.java 2009-07-10 10:08:50 UTC (rev 17063)
+++ jpamodelgen/trunk/test/src/main/java/model/xmlmapped/LivingBeing.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -1,17 +0,0 @@
-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
Deleted: jpamodelgen/trunk/test/src/main/java/model/xmlmapped/Mammal.java
===================================================================
--- jpamodelgen/trunk/test/src/main/java/model/xmlmapped/Mammal.java 2009-07-10 10:08:50 UTC (rev 17063)
+++ jpamodelgen/trunk/test/src/main/java/model/xmlmapped/Mammal.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -1,23 +0,0 @@
-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/dummy.xml
===================================================================
--- jpamodelgen/trunk/test/src/main/resources/META-INF/dummy.xml 2009-07-10 10:08:50 UTC (rev 17063)
+++ jpamodelgen/trunk/test/src/main/resources/META-INF/dummy.xml 2009-07-10 11:58:29 UTC (rev 17064)
@@ -1,14 +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"
- >
- <package>model</package>
- <entity class="Dummy" access="FIELD" metadata-complete="true"> <!-- Class does not exist -->
- <attributes>
- <id name="id"/>
- </attributes>
- </entity>
-</entity-mappings>
Deleted: jpamodelgen/trunk/test/src/main/resources/META-INF/order.xml
===================================================================
--- jpamodelgen/trunk/test/src/main/resources/META-INF/order.xml 2009-07-10 10:08:50 UTC (rev 17063)
+++ jpamodelgen/trunk/test/src/main/resources/META-INF/order.xml 2009-07-10 11:58:29 UTC (rev 17064)
@@ -1,36 +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"
- >
- <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 name="date"/>
- <one-to-many name="items" target-entity="Item" fetch="EAGER"> <!-- target-entity optional guess the type from the geenric-->
- <cascade>
- <cascade-persist/>
- </cascade>
- </one-to-many>
- <many-to-one name="shop"/>
- <element-collection name="notes"/> <!-- new in JPA 2 -->
- </attributes>
- </entity>
-</entity-mappings>
-
-
- <!--
-public class Order {
- long id;
- Set<Item> items;
- boolean filled;
- Date date;
- List<String> notes;
- Shop shop;
-} -->
\ No newline at end of file
Deleted: jpamodelgen/trunk/test/src/main/resources/META-INF/persistence.xml
===================================================================
--- jpamodelgen/trunk/test/src/main/resources/META-INF/persistence.xml 2009-07-10 10:08:50 UTC (rev 17063)
+++ jpamodelgen/trunk/test/src/main/resources/META-INF/persistence.xml 2009-07-10 11:58:29 UTC (rev 17064)
@@ -1,13 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<persistence xmlns="http://java.sun.com/xml/ns/persistence"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/persistence persistence.xsd" version="2.0">
- <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/dummy.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>
Deleted: jpamodelgen/trunk/test/src/main/resources/model/xmlmapped/address.xml
===================================================================
--- jpamodelgen/trunk/test/src/main/resources/model/xmlmapped/address.xml 2009-07-10 10:08:50 UTC (rev 17063)
+++ jpamodelgen/trunk/test/src/main/resources/model/xmlmapped/address.xml 2009-07-10 11:58:29 UTC (rev 17064)
@@ -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"
- >
- <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/model/xmlmapped/building.xml
===================================================================
--- jpamodelgen/trunk/test/src/main/resources/model/xmlmapped/building.xml 2009-07-10 10:08:50 UTC (rev 17063)
+++ jpamodelgen/trunk/test/src/main/resources/model/xmlmapped/building.xml 2009-07-10 11:58:29 UTC (rev 17064)
@@ -1,15 +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"
- >
- <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>
-
Deleted: jpamodelgen/trunk/test/src/main/resources/model/xmlmapped/mammal.xml
===================================================================
--- jpamodelgen/trunk/test/src/main/resources/model/xmlmapped/mammal.xml 2009-07-10 10:08:50 UTC (rev 17063)
+++ jpamodelgen/trunk/test/src/main/resources/model/xmlmapped/mammal.xml 2009-07-10 11:58:29 UTC (rev 17064)
@@ -1,20 +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"
- >
- <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>
Deleted: jpamodelgen/trunk/test/src/test/java/tests/AccessTypeTest.java
===================================================================
--- jpamodelgen/trunk/test/src/test/java/tests/AccessTypeTest.java 2009-07-10 10:08:50 UTC (rev 17063)
+++ jpamodelgen/trunk/test/src/test/java/tests/AccessTypeTest.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -1,75 +0,0 @@
-package tests;
-
-import java.lang.reflect.Field;
-
-import org.testng.annotations.Test;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertTrue;
-import org.testng.Assert;
-
-/**
- * @author Emmanuel Bernard
- */
-@Test
-public class AccessTypeTest {
-
- @Test
- public void testExcludeTransientFieldAndStatic() throws Exception{
- absenceOfField( "model.Product_", "nonPersistent" );
- absenceOfField( "model.Product_", "nonPersistent2" );
- }
-
- @Test
- public void testDefaultAccessTypeOnEntity() throws Exception{
- absenceOfField( "model.User_", "nonPersistent" );
- }
-
- @Test
- public void testDefaultAccessTypeForSubclassOfEntity() throws Exception{
- absenceOfField( "model.Customer_", "nonPersistent" );
- }
-
- @Test
- public void testDefaultAccessTypeForEmbeddable() throws Exception{
- absenceOfField( "model.Detail_", "nonPersistent " );
- }
-
- @Test
- public void testDefaultAccessTypeForMappedSuperclass() throws Exception{
- absenceOfField( "model.Detail_", "volume" );
- }
-
- @Test
- public void testExplicitAccessTypeAndDefaultFromRootEntity() throws Exception{
- absenceOfField( "model.LivingBeing_", "nonPersistent", "eplicit access type on mapped superclass" );
- absenceOfField( "model.Hominidae_", "nonPersistent", "eplicit access type on entity" );
- absenceOfField( "model.Human_", "nonPersistent", "proper inheritance from root entity access type" );
- }
-
- @Test
- public void testMemberAccessType() throws Exception{
- presenceOfField( "model.Customer_", "goodPayer", "access type overriding" );
- }
-
- private void absenceOfField(String className, String fieldName) throws ClassNotFoundException {
- absenceOfField( className, fieldName, "field should not be persistent" );
- }
- private void absenceOfField(String className, String fieldName, String errorString) throws ClassNotFoundException {
- Assert.assertFalse( isFieldHere(className, fieldName), errorString );
- }
-
- private void presenceOfField(String className, String fieldName, String errorString) throws ClassNotFoundException {
- Assert.assertTrue( isFieldHere(className, fieldName), errorString );
- }
-
- private boolean isFieldHere(String className, String fieldName) throws ClassNotFoundException {
- Class<?> user_ = Class.forName( className );
- try {
- final Field field = user_.getField( fieldName );
- return true;
- }
- catch (NoSuchFieldException e) {
- return false;
- }
- }
-}
Deleted: jpamodelgen/trunk/test/src/test/java/tests/InheritanceTest.java
===================================================================
--- jpamodelgen/trunk/test/src/test/java/tests/InheritanceTest.java 2009-07-10 10:08:50 UTC (rev 17063)
+++ jpamodelgen/trunk/test/src/test/java/tests/InheritanceTest.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -1,29 +0,0 @@
-package tests;
-
-import org.testng.annotations.Test;
-import org.testng.Assert;
-import model.Customer_;
-import model.User_;
-import model.House_;
-import model.Building_;
-import model.Area_;
-
-/**
- * @author Emmanuel Bernard
- */
-@Test
-public class InheritanceTest {
- @Test
- public void testSuperEntity() throws Exception {
- Assert.assertEquals( Customer_.class.getSuperclass(), User_.class,
- "Entity with super entity should inherit at the metamodel level");
- }
-
- @Test
- public void testMappedSuperclass() throws Exception {
- Assert.assertEquals( House_.class.getSuperclass(), Building_.class,
- "Entity with mapped superclass should inherit at the metamodel level");
- Assert.assertEquals( Building_.class.getSuperclass(), Area_.class,
- "mapped superclass with mapped superclass should inherit at the metamodel level");
- }
-}
Deleted: jpamodelgen/trunk/test/src/test/java/tests/QueryTest.java
===================================================================
--- jpamodelgen/trunk/test/src/test/java/tests/QueryTest.java 2009-07-10 10:08:50 UTC (rev 17063)
+++ jpamodelgen/trunk/test/src/test/java/tests/QueryTest.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -1,146 +0,0 @@
-package tests;
-
-import java.math.BigDecimal;
-import java.util.Date;
-import java.util.Set;
-import javax.persistence.criteria.CriteriaQuery;
-import javax.persistence.criteria.Expression;
-import javax.persistence.criteria.Join;
-import static javax.persistence.criteria.JoinType.INNER;
-import javax.persistence.criteria.ListJoin;
-import javax.persistence.criteria.Path;
-import javax.persistence.criteria.QueryBuilder;
-import javax.persistence.criteria.Root;
-import javax.persistence.Tuple;
-
-import model.Item;
-import model.Order;
-import model.Product;
-import model.Item_;
-import model.Order_;
-import model.Product_;
-import model.Shop_;
-
-/**
- * Writing queries involves passing typesafe, statically cached, metamodel
- * objects to the query builder in order to create the various parts of
- * the query. The typesafe metamodel objects were validated at init time,
- * so it is impossible to build invalid queries in the application code.
- */
-public class QueryTest {
-
- QueryBuilder qb;
-
- public void test() {
- CriteriaQuery<Tuple> q = qb.createTupleQuery();
-
- Root<Order> order = q.from(Order.class);
- Join<Item, Product> product = order.join(Order_.items)
- .join(Item_.product);
-
- Path<BigDecimal> price = product.get(Product_.price);
- Path<Boolean> filled = order.get(Order_.filled);
- Path<Date> date = order.get(Order_.date);
-
- q.select( qb.tuple( order, product ) )
- .where( qb.and( qb.gt(price, 100.00), qb.not(filled) ) )
- .orderBy( qb.asc(price), qb.desc(date) );
- }
-
- public void testUntypesafe() {
- CriteriaQuery<Tuple> q = qb.createTupleQuery();
-
- Root<Order> order = q.from(Order.class);
- Join<Item, Product> product = order.join("items")
- .join("product");
-
- Path<BigDecimal> price = product.get("price");
- Path<Boolean> filled = order.get("filled");
- Path<Date> date = order.get("date");
-
- q.select( qb.tuple( order, product ) )
- .where( qb.and( qb.gt(price, 100.00), qb.not(filled) ) )
- .orderBy( qb.asc(price), qb.desc(date) );
- }
-
- /**
- * Navigation by joining
- */
- public void test2() {
- CriteriaQuery<Product> q = qb.createQuery(Product.class);
-
- Root<Product> product = q.from(Product.class);
- Join<Item, Order> order = product.join(Product_.items)
- .join(Item_.order);
-
- q.select(product)
- .where( qb.equal(order.get(Order_.id), 12345l) );
- }
-
- public void testMap() {
- CriteriaQuery<Item> q = qb.createQuery(Item.class);
-
- Root<Item> item = q.from(Item.class);
- Join<Item, Order> io = item.join(Item_.namedOrders);
-
- }
-
- /**
- * Navigation by compound Path
- */
- public void test3() {
- CriteriaQuery<Item> q = qb.createQuery(Item.class);
-
- Root<Item> item = q.from(Item.class);
- Path<String> shopName = item.get(Item_.order)
- .get(Order_.shop)
- .get(Shop_.name);
- q.select(item)
- .where( qb.equal(shopName, "amazon.com") );
- }
-
-// public void test4() {
-// CriteriaQuery q = qb.create();
-//
-// Root<Order> order = q.from(Order.class);
-// ListJoin<Order, String> note = order.join(Order_.notes);
-// Expression<Set<Item>> items = order.get(Order_.items);
-// order.fetch(Order_.items, JoinType.INNER);
-//
-// q.select(note)
-// .where( qb.and( qb.lt(note.index(), 10), qb.isNotEmpty(items) ) );
-// }
-
- public void test4Untypesafe() {
- CriteriaQuery<String> q = qb.createQuery(String.class);
-
- Root<Order> order = q.from(Order.class);
- ListJoin<Order, String> note = order.joinList("notes");
- Expression<Set<Item>> items = order.get("items");
- order.fetch("items", INNER);
-
- q.select(note)
- .where( qb.and( qb.lt(note.index(), 10), qb.isNotEmpty(items) ) );
- }
-
- /*public void test5() {
- Expression<Long> l= null;
- Expression<Integer> i= null;
- Expression<Float> x= null;
- Expression<Float> y= null;
-
- Expression<Number> n;
- Expression<Float> f;
- Expression<String> s = null;
-
- n = qb.quot(l, i);
-
- f = qb.sum(x, y);
-
- n = qb.quot(x, y);
-
- javax.jpa.criteria.Order o = qb.asc(n);
- javax.jpa.criteria.Order p = qb.ascending(s);
- }*/
-
-}
Deleted: jpamodelgen/trunk/test/src/test/java/tests/XmlMappingTest.java
===================================================================
--- jpamodelgen/trunk/test/src/test/java/tests/XmlMappingTest.java 2009-07-10 10:08:50 UTC (rev 17063)
+++ jpamodelgen/trunk/test/src/test/java/tests/XmlMappingTest.java 2009-07-10 11:58:29 UTC (rev 17064)
@@ -1,38 +0,0 @@
-package tests;
-
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertTrue;
-import org.testng.annotations.Test;
-
-/**
- * @author Hardy Ferentschik
- */
-public class XmlMappingTest {
- @Test
- public void testXmlConfiguredEmbeddedClassGenerated() throws Exception {
- assertNotNull( Class.forName( "model.xmlmapped.Address_" ) );
- }
-
- @Test
- public void testXmlConfiguredMappedSuperclassGenerated() throws Exception {
- Class<?> building = Class.forName( "model.xmlmapped.Building_" );
- assertNotNull( building );
- 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 ) );
- }
-
- @Test(expectedExceptions = ClassNotFoundException.class)
- public void testNonExistentMappedClassesGetIgnored() throws Exception {
- Class.forName( "model.Dummy_" );
- }
-}
\ No newline at end of file
Deleted: jpamodelgen/trunk/test/src/test/suite/unit-tests.xml
===================================================================
--- jpamodelgen/trunk/test/src/test/suite/unit-tests.xml 2009-07-10 10:08:50 UTC (rev 17063)
+++ jpamodelgen/trunk/test/src/test/suite/unit-tests.xml 2009-07-10 11:58:29 UTC (rev 17064)
@@ -1,9 +0,0 @@
-<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
-
-<suite name="Hibernate Model Generator Tests" verbose="1">
- <test name="Unit tests">
- <packages>
- <package name="tests"/>
- </packages>
- </test>
-</suite>
\ No newline at end of file
15 years, 3 months
Hibernate SVN: r17063 - in jpamodelgen/trunk: generator/src/main/java/org/hibernate/jpa/metamodel/ap/xml and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-07-10 06:08:50 -0400 (Fri, 10 Jul 2009)
New Revision: 17063
Added:
jpamodelgen/trunk/test/src/main/resources/META-INF/dummy.xml
Modified:
jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/JPAMetaModelEntityProcessor.java
jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/xml/XmlMetaEntity.java
jpamodelgen/trunk/test/src/main/resources/META-INF/persistence.xml
jpamodelgen/trunk/test/src/test/java/tests/XmlMappingTest.java
Log:
added some error handling
Modified: jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/JPAMetaModelEntityProcessor.java
===================================================================
--- jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/JPAMetaModelEntityProcessor.java 2009-07-10 09:30:57 UTC (rev 17062)
+++ jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/JPAMetaModelEntityProcessor.java 2009-07-10 10:08:50 UTC (rev 17063)
@@ -162,9 +162,17 @@
Collection<Entity> entities = mappings.getEntity();
for ( Entity entity : entities ) {
String fullyQualifiedClassName = packageName + "." + entity.getClazz();
- Elements utils = processingEnv.getElementUtils();
+
+ if ( !xmlMappedTypeExists( fullyQualifiedClassName ) ) {
+ processingEnv.getMessager().printMessage(
+ Diagnostic.Kind.WARNING,
+ fullyQualifiedClassName + " is mapped in xml, but class does not exists. Skipping meta model generation."
+ );
+ continue;
+ }
+
XmlMetaEntity metaEntity = new XmlMetaEntity(
- entity, packageName, utils.getTypeElement( fullyQualifiedClassName )
+ entity, packageName, getXmlMappedType( fullyQualifiedClassName )
);
if ( context.getMetaEntitiesToProcess().containsKey( fullyQualifiedClassName ) ) {
@@ -177,14 +185,32 @@
}
}
+ private boolean xmlMappedTypeExists(String fullyQualifiedClassName) {
+ Elements utils = processingEnv.getElementUtils();
+ return utils.getTypeElement( fullyQualifiedClassName ) != null;
+ }
+
+ private TypeElement getXmlMappedType(String fullyQualifiedClassName) {
+ Elements utils = processingEnv.getElementUtils();
+ return utils.getTypeElement( fullyQualifiedClassName );
+ }
+
private void parseEmbeddable(EntityMappings mappings) {
String packageName = mappings.getPackage();
Collection<org.hibernate.jpa.metamodel.xml.jaxb.Embeddable> embeddables = mappings.getEmbeddable();
for ( org.hibernate.jpa.metamodel.xml.jaxb.Embeddable embeddable : embeddables ) {
String fullyQualifiedClassName = packageName + "." + embeddable.getClazz();
- Elements utils = processingEnv.getElementUtils();
+
+ if ( !xmlMappedTypeExists( fullyQualifiedClassName ) ) {
+ processingEnv.getMessager().printMessage(
+ Diagnostic.Kind.WARNING,
+ fullyQualifiedClassName + " is mapped in xml, but class does not exists. Skipping meta model generation."
+ );
+ continue;
+ }
+
XmlMetaEntity metaEntity = new XmlMetaEntity(
- embeddable, packageName, utils.getTypeElement( fullyQualifiedClassName )
+ embeddable, packageName, getXmlMappedType( fullyQualifiedClassName )
);
if ( context.getMetaSuperclassAndEmbeddableToProcess().containsKey( fullyQualifiedClassName ) ) {
@@ -202,9 +228,17 @@
Collection<org.hibernate.jpa.metamodel.xml.jaxb.MappedSuperclass> mappedSuperClasses = mappings.getMappedSuperclass();
for ( org.hibernate.jpa.metamodel.xml.jaxb.MappedSuperclass mappedSuperClass : mappedSuperClasses ) {
String fullyQualifiedClassName = packageName + "." + mappedSuperClass.getClazz();
- Elements utils = processingEnv.getElementUtils();
+
+ if ( !xmlMappedTypeExists( fullyQualifiedClassName ) ) {
+ processingEnv.getMessager().printMessage(
+ Diagnostic.Kind.WARNING,
+ fullyQualifiedClassName + " is mapped in xml, but class does not exists. Skipping meta model generation."
+ );
+ continue;
+ }
+
XmlMetaEntity metaEntity = new XmlMetaEntity(
- mappedSuperClass, packageName, utils.getTypeElement( fullyQualifiedClassName )
+ mappedSuperClass, packageName, getXmlMappedType( fullyQualifiedClassName )
);
if ( context.getMetaSuperclassAndEmbeddableToProcess().containsKey( fullyQualifiedClassName ) ) {
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 09:30:57 UTC (rev 17062)
+++ jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/xml/XmlMetaEntity.java 2009-07-10 10:08:50 UTC (rev 17063)
@@ -171,7 +171,6 @@
return types;
}
- // TODO - so far only prototype. Only tested for the Order orm.xml
private String getType(String propertyName) {
String typeName = null;
for ( Element elem : element.getEnclosedElements() ) {
Copied: jpamodelgen/trunk/test/src/main/resources/META-INF/dummy.xml (from rev 17062, jpamodelgen/trunk/test/src/main/resources/META-INF/order.xml)
===================================================================
--- jpamodelgen/trunk/test/src/main/resources/META-INF/dummy.xml (rev 0)
+++ jpamodelgen/trunk/test/src/main/resources/META-INF/dummy.xml 2009-07-10 10:08:50 UTC (rev 17063)
@@ -0,0 +1,14 @@
+<?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</package>
+ <entity class="Dummy" access="FIELD" metadata-complete="true"> <!-- Class does not exist -->
+ <attributes>
+ <id name="id"/>
+ </attributes>
+ </entity>
+</entity-mappings>
Modified: jpamodelgen/trunk/test/src/main/resources/META-INF/persistence.xml
===================================================================
--- jpamodelgen/trunk/test/src/main/resources/META-INF/persistence.xml 2009-07-10 09:30:57 UTC (rev 17062)
+++ jpamodelgen/trunk/test/src/main/resources/META-INF/persistence.xml 2009-07-10 10:08:50 UTC (rev 17063)
@@ -5,6 +5,7 @@
<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/dummy.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>
Modified: jpamodelgen/trunk/test/src/test/java/tests/XmlMappingTest.java
===================================================================
--- jpamodelgen/trunk/test/src/test/java/tests/XmlMappingTest.java 2009-07-10 09:30:57 UTC (rev 17062)
+++ jpamodelgen/trunk/test/src/test/java/tests/XmlMappingTest.java 2009-07-10 10:08:50 UTC (rev 17063)
@@ -30,4 +30,9 @@
assertTrue( mammal.getSuperclass().equals( being ) );
}
+
+ @Test(expectedExceptions = ClassNotFoundException.class)
+ public void testNonExistentMappedClassesGetIgnored() throws Exception {
+ Class.forName( "model.Dummy_" );
+ }
}
\ No newline at end of file
15 years, 3 months
Hibernate SVN: r17062 - in jpamodelgen/trunk: test/src/main/java/model/xmlmapped and 5 other directories.
by hibernate-commits@lists.jboss.org
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
15 years, 3 months