[hibernate-commits] Hibernate SVN: r17019 - in jpamodelgen/trunk: generator/src/main/java/org/hibernate/jpa/metamodel/ap and 8 other directories.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Tue Jul 7 12:34:07 EDT 2009
Author: hardy.ferentschik
Date: 2009-07-07 12:34:06 -0400 (Tue, 07 Jul 2009)
New Revision: 17019
Added:
jpamodelgen/trunk/generator/src/main/xsd/persistence.xsd
jpamodelgen/trunk/test/src/main/resources/META-INF/persistence.xml
jpamodelgen/trunk/test/src/test/
jpamodelgen/trunk/test/src/test/java/
jpamodelgen/trunk/test/src/test/java/QueryTest.java
Removed:
jpamodelgen/trunk/test/src/main/java/Test.java
jpamodelgen/trunk/test/src/main/java/model/metamodel/
Modified:
jpamodelgen/trunk/generator/pom.xml
jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/JPAMetaModelEntityProcessor.java
jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/JpaAnnotationsConstants.java
jpamodelgen/trunk/test/pom.xml
Log:
started parsing persistence.xml
Modified: jpamodelgen/trunk/generator/pom.xml
===================================================================
--- jpamodelgen/trunk/generator/pom.xml 2009-07-07 16:33:04 UTC (rev 17018)
+++ jpamodelgen/trunk/generator/pom.xml 2009-07-07 16:34:06 UTC (rev 17019)
@@ -14,16 +14,6 @@
<groupId>org.hibernate.java-persistence</groupId>
<artifactId>jpa-api</artifactId>
</dependency>
-
- <!--
- Test dependencies
- -->
- <dependency>
- <groupId>org.testng</groupId>
- <artifactId>testng</artifactId>
- <scope>test</scope>
- <classifier>jdk15</classifier>
- </dependency>
</dependencies>
<build>
<defaultGoal>test</defaultGoal>
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-07 16:33:04 UTC (rev 17018)
+++ jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/JPAMetaModelEntityProcessor.java 2009-07-07 16:34:06 UTC (rev 17019)
@@ -5,6 +5,7 @@
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
+import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
@@ -36,138 +37,119 @@
import org.hibernate.jpa.metamodel.xml.jaxb.Entity;
import org.hibernate.jpa.metamodel.xml.jaxb.EntityMappings;
import org.hibernate.jpa.metamodel.xml.jaxb.ObjectFactory;
+import org.hibernate.jpa.metamodel.xml.jaxb.Persistence;
//@SupportedAnnotationTypes("javax.persistence.Entity")
@SupportedAnnotationTypes("*")
@SupportedSourceVersion(RELEASE_6)
public class JPAMetaModelEntityProcessor extends AbstractProcessor {
- private static final Map<String, IMetaEntity> metaEntities = new HashMap<String, IMetaEntity>();
+ private static final String PATH_SEPARATOR = "/";
+ private static final String PERSISTENCE_XML = "/META-INF/persistence.xml";
- private boolean ormProcessed = false;
+ private final Map<String, IMetaEntity> metaEntities = new HashMap<String, IMetaEntity>();
+ private boolean xmlProcessed = false;
- public JPAMetaModelEntityProcessor() {
- }
-
public void init(ProcessingEnvironment env) {
super.init( env );
processingEnv.getMessager().printMessage( Diagnostic.Kind.NOTE, "Init Processor " + this );
}
- private void parsingOrmXmls() {
- //make sure that we process ORM files only once per round
- if ( ormProcessed ) {
- return;
+ @Override
+ public boolean process(final Set<? extends TypeElement> annotations,
+ final RoundEnvironment roundEnvironment) {
+
+ if ( roundEnvironment.processingOver() ) {
+ //assuming that when processing is over, we are done and clear resources like ORM parsing
+ //we could keep some ORM parsing in memory but how to detect that a file has changed / not changed?
+ xmlProcessed = false;
+ metaEntities.clear();
+ processingEnv.getMessager().printMessage( Diagnostic.Kind.NOTE, "Clear ORM processing resources" );
+ return false;
}
- parsingOrmXml( "/META-INF", "orm.xml" );
- //simulate 20 different ORM files to parse
- //Removed since these causes issues in Eclipse APT
- //for (int i = 1 ; i <= 20 ; i++) parsingOrmXml("/model" + i , "orm.xml");
- ormProcessed = true;
- }
+ if ( !processingRoundConstainsEntities( annotations ) ) {
+ processingEnv.getMessager()
+ .printMessage( Diagnostic.Kind.NOTE, "Current processing round does not contain entities" );
+ return true;
+ }
- /**
- * Tries to check whether a orm.xml file exists and parses it using JAXB
- */
- private void parsingOrmXml(String pkg, String name) {
+ writeProcessingDiagnostics( annotations, roundEnvironment );
- InputStream ormStream = getInputStreamForResource( pkg, name );
+ parsePersistenceXml();
- String resource = getFullResourcePath( pkg, name );
- if ( ormStream == null ) {
- processingEnv.getMessager().printMessage( Diagnostic.Kind.NOTE, resource + " not found." );
- return;
+ Set<? extends Element> elements = roundEnvironment.getRootElements();
+ for ( Element element : elements ) {
+ handleRootElementAnnotationMirrors( element );
}
- try {
- JAXBContext jc = JAXBContext.newInstance( ObjectFactory.class );
- Unmarshaller unmarshaller = jc.createUnmarshaller();
- EntityMappings mappings = ( EntityMappings ) unmarshaller.unmarshal( ormStream );
- Collection<Entity> entities = mappings.getEntity();
- String packageName = mappings.getPackage();
- for ( Entity entity : entities ) {
- String fullyQualifiedClassName = packageName + "." + entity.getClazz();
- Elements utils = processingEnv.getElementUtils();
- XmlMetaEntity metaEntity = new XmlMetaEntity(
- entity, packageName, utils.getTypeElement( fullyQualifiedClassName )
- );
- writeFile( metaEntity );
- // keep track of alreay processed entities
- metaEntities.put( fullyQualifiedClassName, metaEntity );
+ return true;
+ }
+
+ private boolean processingRoundConstainsEntities(Set<? extends TypeElement> annotations) {
+ for ( TypeElement type : annotations ) {
+ if ( type.getQualifiedName().toString().equals( javax.persistence.Entity.class.getName() ) ) {
+ return true;
}
}
- catch ( JAXBException e ) {
- processingEnv.getMessager().printMessage( Diagnostic.Kind.NOTE, "Error unmarshalling orm.xml" );
- e.printStackTrace();
- }
- catch ( Exception e ) {
- processingEnv.getMessager().printMessage(
- Diagnostic.Kind.ERROR,
- "Problem while reading " + resource + " " + e.getMessage()
- );
- e.printStackTrace();
- //TODO: too bad you can't mark resources as having issues
- }
+ return false;
}
- private InputStream getInputStreamForResource(String pkg, String name) {
- String resource = getFullResourcePath( pkg, name );
- processingEnv.getMessager()
- .printMessage( Diagnostic.Kind.NOTE, "Checking for " + resource );
- InputStream ormStream;
- try {
- FileObject fileObject = processingEnv.getFiler().getResource( StandardLocation.CLASS_OUTPUT, pkg, name );
- ormStream = fileObject.openInputStream();
+ private void parsePersistenceXml() {
+ if ( xmlProcessed ) {
+ return;
}
- catch ( IOException e1 ) {
- processingEnv.getMessager()
- .printMessage(
- Diagnostic.Kind.WARNING,
- "Could not load " + resource + " using Filer.getResource(). Trying classpath..."
- );
- ormStream = this.getClass().getResourceAsStream( resource );
+
+ Persistence persistence = parseXml( PERSISTENCE_XML, Persistence.class );
+
+ if ( persistence != null ) {
+ List<Persistence.PersistenceUnit> persistenceUnits = persistence.getPersistenceUnit();
+ for ( Persistence.PersistenceUnit unit : persistenceUnits ) {
+ List<String> mappingFiles = unit.getMappingFile();
+ for ( String mappingFile : mappingFiles ) {
+ parsingOrmXml( mappingFile );
+ }
+ }
}
- return ormStream;
+ xmlProcessed = true;
}
- private String getFullResourcePath(String pkg, String name) {
- return pkg + "/" + name;
- }
- @Override
- public boolean process(final Set<? extends TypeElement> aAnnotations,
- final RoundEnvironment aRoundEnvironment) {
+ private void parsingOrmXml(String resource) {
- writeInitialProcessingDiagnostics( aAnnotations, aRoundEnvironment );
-
- if ( aRoundEnvironment.processingOver() ) {
- //assuming that when processing is over, we are done and clear resources like ORM parsing
- //we could keep some ORM parsing in memory but how to detect that a file has changed / not changed?
- ormProcessed = false;
- metaEntities.clear();
- processingEnv.getMessager().printMessage( Diagnostic.Kind.NOTE, "Clear ORM processing resources" );
- return false;
+ EntityMappings mappings = parseXml( resource, EntityMappings.class );
+ if ( mappings == null ) {
+ return;
}
+ Collection<Entity> entities = mappings.getEntity();
+ String packageName = mappings.getPackage();
+ for ( Entity entity : entities ) {
+ String fullyQualifiedClassName = packageName + "." + entity.getClazz();
+ Elements utils = processingEnv.getElementUtils();
+ XmlMetaEntity metaEntity = new XmlMetaEntity(
+ entity, packageName, utils.getTypeElement( fullyQualifiedClassName )
+ );
- parsingOrmXmls();
+ if ( metaEntities.containsKey( fullyQualifiedClassName ) ) {
+ processingEnv.getMessager().printMessage(
+ Diagnostic.Kind.WARNING,
+ fullyQualifiedClassName + " was already processed once. Skipping second occurance."
+ );
+ }
- Set<? extends Element> elements = aRoundEnvironment.getRootElements();
- for ( Element element : elements ) {
- handleRootElementAnnotationMirrors( element );
+ writeFile( metaEntity );
+ metaEntities.put( fullyQualifiedClassName, metaEntity );
}
-
- return true;
}
- private void writeInitialProcessingDiagnostics(Set<? extends TypeElement> aAnnotations, RoundEnvironment aRoundEnvironment) {
+ private void writeProcessingDiagnostics(Set<? extends TypeElement> annotations, RoundEnvironment roundEnvironment) {
StringBuilder sb = new StringBuilder();
sb.append( "\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n" );
- sb.append( new Date().toLocaleString() );
+ sb.append( new SimpleDateFormat().format( new Date() ) );
sb.append( "\n" );
- sb.append( "Processing annotations " ).append( aAnnotations ).append( " on:" );
+ sb.append( "Processing annotations " ).append( annotations ).append( " on:" );
- Set<? extends Element> elements = aRoundEnvironment.getRootElements();
+ Set<? extends Element> elements = roundEnvironment.getRootElements();
sb.append( "\n" );
for ( Element element : elements ) {
sb.append( element.toString() );
@@ -235,8 +217,10 @@
}
/**
- * Generate everything after import statements
+ * Generate everything after import statements.
*
+ * @param entity The meta entity for which to write the body
+ *
* @return body content
*/
private StringBuffer generateBody(IMetaEntity entity) {
@@ -270,4 +254,79 @@
}
}
}
+
+ private InputStream getInputStreamForResource(String resource) {
+ String pkg = getPackage( resource );
+ String name = getRelativeName( resource );
+ processingEnv.getMessager()
+ .printMessage( Diagnostic.Kind.NOTE, "Checking for " + resource );
+ InputStream ormStream;
+ try {
+ FileObject fileObject = processingEnv.getFiler().getResource( StandardLocation.CLASS_OUTPUT, pkg, name );
+ ormStream = fileObject.openInputStream();
+ }
+ catch ( IOException e1 ) {
+ processingEnv.getMessager()
+ .printMessage(
+ Diagnostic.Kind.WARNING,
+ "Could not load " + resource + " using Filer.getResource(). Trying classpath..."
+ );
+ ormStream = this.getClass().getResourceAsStream( resource );
+ }
+ return ormStream;
+ }
+
+ /**
+ * Tries to open the specified xml file and return an instance of the specified class using JAXB.
+ *
+ * @param resource the xml file name
+ * @param clazz The type of jaxb node to return
+ *
+ * @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) {
+
+ InputStream stream = getInputStreamForResource( resource );
+
+ if ( stream == null ) {
+ processingEnv.getMessager().printMessage( Diagnostic.Kind.NOTE, resource + " not found." );
+ return null;
+ }
+ try {
+ JAXBContext jc = JAXBContext.newInstance( ObjectFactory.class );
+ Unmarshaller unmarshaller = jc.createUnmarshaller();
+ return clazz.cast( unmarshaller.unmarshal( stream ) );
+ }
+ catch ( JAXBException e ) {
+ processingEnv.getMessager().printMessage( Diagnostic.Kind.NOTE, "Error unmarshalling " + resource );
+ e.printStackTrace();
+ return null;
+ }
+ catch ( Exception e ) {
+ processingEnv.getMessager().printMessage(
+ Diagnostic.Kind.ERROR,
+ "Problem while reading " + resource + " " + e.getMessage()
+ );
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ private String getPackage(String resourceName) {
+ if ( !resourceName.contains( PATH_SEPARATOR ) ) {
+ return "";
+ }
+ else {
+ return resourceName.substring( 0, resourceName.lastIndexOf( PATH_SEPARATOR ) );
+ }
+ }
+
+ private String getRelativeName(String resourceName) {
+ if ( !resourceName.contains( PATH_SEPARATOR ) ) {
+ return resourceName;
+ }
+ else {
+ return resourceName.substring( resourceName.lastIndexOf( PATH_SEPARATOR ) + 1 );
+ }
+ }
}
Modified: 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-07 16:33:04 UTC (rev 17018)
+++ jpamodelgen/trunk/generator/src/main/java/org/hibernate/jpa/metamodel/ap/JpaAnnotationsConstants.java 2009-07-07 16:34:06 UTC (rev 17019)
@@ -1,33 +1,27 @@
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 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 PROCESSOR_USER_OPTION_XML_OVERRIDE =
- "xmlOverrideAnnotations";
- public static final String PROCESSOR_USER_OPTION_UPPER_COLUMN_NAMES =
- "useUpperCaseColumnNames";
+ 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";
}
Added: jpamodelgen/trunk/generator/src/main/xsd/persistence.xsd
===================================================================
--- jpamodelgen/trunk/generator/src/main/xsd/persistence.xsd (rev 0)
+++ jpamodelgen/trunk/generator/src/main/xsd/persistence.xsd 2009-07-07 16:34:06 UTC (rev 17019)
@@ -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
Modified: jpamodelgen/trunk/test/pom.xml
===================================================================
--- jpamodelgen/trunk/test/pom.xml 2009-07-07 16:33:04 UTC (rev 17018)
+++ jpamodelgen/trunk/test/pom.xml 2009-07-07 16:34:06 UTC (rev 17019)
@@ -17,16 +17,12 @@
<artifactId>hibernate-jpamodel-generator</artifactId>
<version>${version}</version>
</dependency>
-
- <!--
- Test dependencies
- -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
- <scope>test</scope>
+ <version>5.8</version>
<classifier>jdk15</classifier>
- </dependency>
+ </dependency>
</dependencies>
<build>
<defaultGoal>test</defaultGoal>
Deleted: jpamodelgen/trunk/test/src/main/java/Test.java
===================================================================
--- jpamodelgen/trunk/test/src/main/java/Test.java 2009-07-07 16:33:04 UTC (rev 17018)
+++ jpamodelgen/trunk/test/src/main/java/Test.java 2009-07-07 16:34:06 UTC (rev 17019)
@@ -1,143 +0,0 @@
-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 model.Item;
-import model.Order;
-import model.Product;
-import model.metamodel.Item_;
-import model.metamodel.Order_;
-import model.metamodel.Product_;
-import model.metamodel.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 Test {
-
- QueryBuilder qb;
-
- public void test() {
- CriteriaQuery q = qb.create();
-
- 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(order, product)
- .where( qb.and( qb.gt(price, 100.00), qb.not(filled) ) )
- .order( qb.asc(price), qb.desc(date) );
- }
-
- public void testUntypesafe() {
- CriteriaQuery q = qb.create();
-
- 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(order, product)
- .where( qb.and( qb.gt(price, 100.00), qb.not(filled) ) )
- .order( qb.asc(price), qb.desc(date) );
- }
-
- /**
- * Navigation by joining
- */
- public void test2() {
- CriteriaQuery q = qb.create();
-
- 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 q = qb.create();
-
- Root<Item> item = q.from(Item.class);
- Join<Item, Order> io = item.join(Item_.namedOrders);
-
- }
-
- /**
- * Navigation by compound Path
- */
- public void test3() {
- CriteriaQuery q = qb.create();
-
- 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 q = qb.create();
-
- 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);
- }*/
-
-}
Added: jpamodelgen/trunk/test/src/main/resources/META-INF/persistence.xml
===================================================================
--- jpamodelgen/trunk/test/src/main/resources/META-INF/persistence.xml (rev 0)
+++ jpamodelgen/trunk/test/src/main/resources/META-INF/persistence.xml 2009-07-07 16:34:06 UTC (rev 17019)
@@ -0,0 +1,9 @@
+<?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/orm.xml</mapping-file>
+ </persistence-unit>
+</persistence>
Copied: jpamodelgen/trunk/test/src/test/java/QueryTest.java (from rev 17010, jpamodelgen/trunk/test/src/main/java/Test.java)
===================================================================
--- jpamodelgen/trunk/test/src/test/java/QueryTest.java (rev 0)
+++ jpamodelgen/trunk/test/src/test/java/QueryTest.java 2009-07-07 16:34:06 UTC (rev 17019)
@@ -0,0 +1,143 @@
+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 model.Item;
+import model.Order;
+import model.Product;
+import model.metamodel.Item_;
+import model.metamodel.Order_;
+import model.metamodel.Product_;
+import model.metamodel.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 q = qb.create();
+
+ 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(order, product)
+ .where( qb.and( qb.gt(price, 100.00), qb.not(filled) ) )
+ .order( qb.asc(price), qb.desc(date) );
+ }
+
+ public void testUntypesafe() {
+ CriteriaQuery q = qb.create();
+
+ 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(order, product)
+ .where( qb.and( qb.gt(price, 100.00), qb.not(filled) ) )
+ .order( qb.asc(price), qb.desc(date) );
+ }
+
+ /**
+ * Navigation by joining
+ */
+ public void test2() {
+ CriteriaQuery q = qb.create();
+
+ 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 q = qb.create();
+
+ Root<Item> item = q.from(Item.class);
+ Join<Item, Order> io = item.join(Item_.namedOrders);
+
+ }
+
+ /**
+ * Navigation by compound Path
+ */
+ public void test3() {
+ CriteriaQuery q = qb.create();
+
+ 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 q = qb.create();
+
+ 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);
+ }*/
+
+}
More information about the hibernate-commits
mailing list