METAGEN-3
This commit is contained in:
parent
31901374fc
commit
95da451ce7
|
@ -46,7 +46,7 @@
|
||||||
<name>Emmanuel Bernard</name>
|
<name>Emmanuel Bernard</name>
|
||||||
<email>emmanuel@hibernate.org</email>
|
<email>emmanuel@hibernate.org</email>
|
||||||
<url>http://in.relation.to/Bloggers/Emmanuel</url>
|
<url>http://in.relation.to/Bloggers/Emmanuel</url>
|
||||||
</developer>
|
</developer>
|
||||||
<developer>
|
<developer>
|
||||||
<id>hardy.ferentschik</id>
|
<id>hardy.ferentschik</id>
|
||||||
<name>Hardy Ferentschik</name>
|
<name>Hardy Ferentschik</name>
|
||||||
|
@ -85,36 +85,6 @@
|
||||||
<compilerArgument>-proc:none</compilerArgument>
|
<compilerArgument>-proc:none</compilerArgument>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</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="build.compiler" value="extJavac"/>
|
|
||||||
<property name="target.dir" value="${project.build.directory}/generated-src/jpamodelgen"/>
|
|
||||||
<mkdir dir="${target.dir}"/>
|
|
||||||
<javac srcdir="${project.build.testSourceDirectory}"
|
|
||||||
destdir="${target.dir}"
|
|
||||||
failonerror="false"
|
|
||||||
excludes="test/**">
|
|
||||||
<compilerarg value="-proc:only"/>
|
|
||||||
<classpath>
|
|
||||||
<path refid="maven.test.classpath"/>
|
|
||||||
</classpath>
|
|
||||||
</javac>
|
|
||||||
</tasks>
|
|
||||||
<testSourceRoot>${project.build.directory}/generated-src/jpamodelgen</testSourceRoot>
|
|
||||||
</configuration>
|
|
||||||
<goals>
|
|
||||||
<goal>run</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
<artifactId>jaxb2-maven-plugin</artifactId>
|
<artifactId>jaxb2-maven-plugin</artifactId>
|
||||||
|
@ -149,6 +119,16 @@
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<configuration>
|
<configuration>
|
||||||
|
<systemProperties>
|
||||||
|
<property>
|
||||||
|
<name>sourceBaseDir</name>
|
||||||
|
<value>${basedir}/src/test/java</value>
|
||||||
|
</property>
|
||||||
|
<property>
|
||||||
|
<name>outBaseDir</name>
|
||||||
|
<value>${basedir}/target/test-classes</value>
|
||||||
|
</property>
|
||||||
|
</systemProperties>
|
||||||
<suiteXmlFiles>
|
<suiteXmlFiles>
|
||||||
<suiteXmlFile>${basedir}/src/test/suite/unit-tests.xml</suiteXmlFile>
|
<suiteXmlFile>${basedir}/src/test/suite/unit-tests.xml</suiteXmlFile>
|
||||||
</suiteXmlFiles>
|
</suiteXmlFiles>
|
||||||
|
@ -215,7 +195,7 @@
|
||||||
</goals>
|
</goals>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-release-plugin</artifactId>
|
<artifactId>maven-release-plugin</artifactId>
|
||||||
|
|
|
@ -24,7 +24,6 @@ import java.io.StringWriter;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.annotation.processing.ProcessingEnvironment;
|
import javax.annotation.processing.ProcessingEnvironment;
|
||||||
import javax.annotation.processing.FilerException;
|
import javax.annotation.processing.FilerException;
|
||||||
import javax.annotation.Generated;
|
|
||||||
import javax.tools.FileObject;
|
import javax.tools.FileObject;
|
||||||
import javax.tools.Diagnostic;
|
import javax.tools.Diagnostic;
|
||||||
import javax.lang.model.type.TypeMirror;
|
import javax.lang.model.type.TypeMirror;
|
||||||
|
@ -38,7 +37,7 @@ import javax.lang.model.element.TypeElement;
|
||||||
*/
|
*/
|
||||||
public class ClassWriter {
|
public class ClassWriter {
|
||||||
|
|
||||||
public static void writeFile(IMetaEntity entity, ProcessingEnvironment processingEnv, Context context) {
|
public static void writeFile(MetaEntity entity, ProcessingEnvironment processingEnv, Context context) {
|
||||||
try {
|
try {
|
||||||
String metaModelPackage = entity.getPackageName();
|
String metaModelPackage = entity.getPackageName();
|
||||||
|
|
||||||
|
@ -85,7 +84,7 @@ public class ClassWriter {
|
||||||
*
|
*
|
||||||
* @return body content
|
* @return body content
|
||||||
*/
|
*/
|
||||||
private static StringBuffer generateBody(IMetaEntity entity, Context context) {
|
private static StringBuffer generateBody(MetaEntity entity, Context context) {
|
||||||
|
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
PrintWriter pw = null;
|
PrintWriter pw = null;
|
||||||
|
@ -103,9 +102,9 @@ public class ClassWriter {
|
||||||
|
|
||||||
pw.println();
|
pw.println();
|
||||||
|
|
||||||
List<IMetaAttribute> members = entity.getMembers();
|
List<MetaAttribute> members = entity.getMembers();
|
||||||
|
|
||||||
for ( IMetaAttribute metaMember : members ) {
|
for ( MetaAttribute metaMember : members ) {
|
||||||
pw.println( " " + metaMember.getDeclarationString() );
|
pw.println( " " + metaMember.getDeclarationString() );
|
||||||
}
|
}
|
||||||
pw.println();
|
pw.println();
|
||||||
|
@ -119,7 +118,7 @@ public class ClassWriter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void printClassDeclaration(IMetaEntity entity, PrintWriter pw, Context context) {
|
private static void printClassDeclaration(MetaEntity entity, PrintWriter pw, Context context) {
|
||||||
pw.print( "public abstract class " + entity.getSimpleName() + "_" );
|
pw.print( "public abstract class " + entity.getSimpleName() + "_" );
|
||||||
|
|
||||||
final TypeMirror superClass = entity.getTypeElement().getSuperclass();
|
final TypeMirror superClass = entity.getTypeElement().getSuperclass();
|
||||||
|
|
|
@ -26,7 +26,7 @@ import javax.persistence.AccessType;
|
||||||
import javax.annotation.processing.ProcessingEnvironment;
|
import javax.annotation.processing.ProcessingEnvironment;
|
||||||
import javax.tools.Diagnostic;
|
import javax.tools.Diagnostic;
|
||||||
|
|
||||||
import org.hibernate.jpamodelgen.annotation.MetaEntity;
|
import org.hibernate.jpamodelgen.annotation.AnnotationMetaEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Max Andersen
|
* @author Max Andersen
|
||||||
|
@ -38,8 +38,8 @@ public class Context {
|
||||||
private Map<TypeElement, AccessTypeHolder> accessTypes = new HashMap<TypeElement, AccessTypeHolder>();
|
private Map<TypeElement, AccessTypeHolder> accessTypes = new HashMap<TypeElement, AccessTypeHolder>();
|
||||||
private Set<String> elementsAlreadyProcessed = new HashSet<String>();
|
private Set<String> elementsAlreadyProcessed = new HashSet<String>();
|
||||||
private ProcessingEnvironment pe;
|
private ProcessingEnvironment pe;
|
||||||
private final Map<String, IMetaEntity> metaEntitiesToProcess = new HashMap<String, IMetaEntity>();
|
private final Map<String, MetaEntity> metaEntitiesToProcess = new HashMap<String, MetaEntity>();
|
||||||
private final Map<String, IMetaEntity> metaSuperclassAndEmbeddableToProcess = new HashMap<String, IMetaEntity>();
|
private final Map<String, MetaEntity> metaSuperclassAndEmbeddableToProcess = new HashMap<String, MetaEntity>();
|
||||||
|
|
||||||
private static class AccessTypeHolder {
|
private static class AccessTypeHolder {
|
||||||
public AccessType elementAccessType;
|
public AccessType elementAccessType;
|
||||||
|
@ -50,11 +50,11 @@ public class Context {
|
||||||
this.pe = pe;
|
this.pe = pe;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, IMetaEntity> getMetaEntitiesToProcess() {
|
public Map<String, MetaEntity> getMetaEntitiesToProcess() {
|
||||||
return metaEntitiesToProcess;
|
return metaEntitiesToProcess;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, IMetaEntity> getMetaSuperclassAndEmbeddableToProcess() {
|
public Map<String, MetaEntity> getMetaSuperclassAndEmbeddableToProcess() {
|
||||||
return metaSuperclassAndEmbeddableToProcess;
|
return metaSuperclassAndEmbeddableToProcess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ public class Context {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClassWriter.writeFile( new MetaEntity( pe, element, this, defaultAccessTypeForHierarchy ), pe, this );
|
ClassWriter.writeFile( new AnnotationMetaEntity( pe, element, this, defaultAccessTypeForHierarchy ), pe, this );
|
||||||
elementsAlreadyProcessed.add( element.getQualifiedName().toString() );
|
elementsAlreadyProcessed.add( element.getQualifiedName().toString() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ import javax.xml.validation.SchemaFactory;
|
||||||
|
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import org.hibernate.jpamodelgen.annotation.MetaEntity;
|
import org.hibernate.jpamodelgen.annotation.AnnotationMetaEntity;
|
||||||
import org.hibernate.jpamodelgen.xml.XmlMetaEntity;
|
import org.hibernate.jpamodelgen.xml.XmlMetaEntity;
|
||||||
import org.hibernate.jpamodelgen.xml.jaxb.Entity;
|
import org.hibernate.jpamodelgen.xml.jaxb.Entity;
|
||||||
import org.hibernate.jpamodelgen.xml.jaxb.EntityMappings;
|
import org.hibernate.jpamodelgen.xml.jaxb.EntityMappings;
|
||||||
|
@ -125,7 +125,7 @@ public class JPAMetaModelEntityProcessor extends AbstractProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createMetaModelClasses() {
|
private void createMetaModelClasses() {
|
||||||
for ( IMetaEntity entity : context.getMetaEntitiesToProcess().values() ) {
|
for ( MetaEntity entity : context.getMetaEntitiesToProcess().values() ) {
|
||||||
processingEnv.getMessager()
|
processingEnv.getMessager()
|
||||||
.printMessage( Diagnostic.Kind.NOTE, "Writing meta model for " + entity );
|
.printMessage( Diagnostic.Kind.NOTE, "Writing meta model for " + entity );
|
||||||
ClassWriter.writeFile( entity, processingEnv, context );
|
ClassWriter.writeFile( entity, processingEnv, context );
|
||||||
|
@ -136,7 +136,7 @@ public class JPAMetaModelEntityProcessor extends AbstractProcessor {
|
||||||
context.getMetaSuperclassAndEmbeddableToProcess().remove( className );
|
context.getMetaSuperclassAndEmbeddableToProcess().remove( className );
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( IMetaEntity entity : context.getMetaSuperclassAndEmbeddableToProcess().values() ) {
|
for ( MetaEntity entity : context.getMetaSuperclassAndEmbeddableToProcess().values() ) {
|
||||||
processingEnv.getMessager()
|
processingEnv.getMessager()
|
||||||
.printMessage( Diagnostic.Kind.NOTE, "Writing meta model for " + entity );
|
.printMessage( Diagnostic.Kind.NOTE, "Writing meta model for " + entity );
|
||||||
ClassWriter.writeFile( entity, processingEnv, context );
|
ClassWriter.writeFile( entity, processingEnv, context );
|
||||||
|
@ -325,13 +325,13 @@ public class JPAMetaModelEntityProcessor extends AbstractProcessor {
|
||||||
|
|
||||||
if ( element.getKind() == ElementKind.CLASS ) {
|
if ( element.getKind() == ElementKind.CLASS ) {
|
||||||
if ( annotationType.equals( ENTITY_ANN ) ) {
|
if ( annotationType.equals( ENTITY_ANN ) ) {
|
||||||
MetaEntity metaEntity = new MetaEntity( processingEnv, ( TypeElement ) element, context );
|
AnnotationMetaEntity metaEntity = new AnnotationMetaEntity( processingEnv, ( TypeElement ) element, context );
|
||||||
// TODO instead of just adding the entity we have to do some merging.
|
// TODO instead of just adding the entity we have to do some merging.
|
||||||
context.getMetaEntitiesToProcess().put( metaEntity.getQualifiedName(), metaEntity );
|
context.getMetaEntitiesToProcess().put( metaEntity.getQualifiedName(), metaEntity );
|
||||||
}
|
}
|
||||||
else if ( annotationType.equals( MAPPED_SUPERCLASS_ANN )
|
else if ( annotationType.equals( MAPPED_SUPERCLASS_ANN )
|
||||||
|| annotationType.equals( EMBEDDABLE_ANN ) ) {
|
|| annotationType.equals( EMBEDDABLE_ANN ) ) {
|
||||||
MetaEntity metaEntity = new MetaEntity( processingEnv, ( TypeElement ) element, context );
|
AnnotationMetaEntity metaEntity = new AnnotationMetaEntity( processingEnv, ( TypeElement ) element, context );
|
||||||
|
|
||||||
// TODO instead of just adding the entity we have to do some merging.
|
// TODO instead of just adding the entity we have to do some merging.
|
||||||
context.getMetaSuperclassAndEmbeddableToProcess().put( metaEntity.getQualifiedName(), metaEntity );
|
context.getMetaSuperclassAndEmbeddableToProcess().put( metaEntity.getQualifiedName(), metaEntity );
|
||||||
|
@ -351,11 +351,11 @@ public class JPAMetaModelEntityProcessor extends AbstractProcessor {
|
||||||
ormStream = fileObject.openInputStream();
|
ormStream = fileObject.openInputStream();
|
||||||
}
|
}
|
||||||
catch ( IOException e1 ) {
|
catch ( IOException e1 ) {
|
||||||
processingEnv.getMessager()
|
// processingEnv.getMessager()
|
||||||
.printMessage(
|
// .printMessage(
|
||||||
Diagnostic.Kind.WARNING,
|
// Diagnostic.Kind.WARNING,
|
||||||
"Could not load " + resource + " using processingEnv.getFiler().getResource(). Using classpath..."
|
// "Could not load " + resource + " using processingEnv.getFiler().getResource(). Using classpath..."
|
||||||
);
|
// );
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
// unfortunately, the Filer.getResource API seems not to be able to load from /META-INF. One gets a
|
// unfortunately, the Filer.getResource API seems not to be able to load from /META-INF. One gets a
|
||||||
|
|
|
@ -20,7 +20,7 @@ package org.hibernate.jpamodelgen;
|
||||||
/**
|
/**
|
||||||
* @author Hardy Ferentschik
|
* @author Hardy Ferentschik
|
||||||
*/
|
*/
|
||||||
public interface IMetaAttribute {
|
public interface MetaAttribute {
|
||||||
String getDeclarationString();
|
String getDeclarationString();
|
||||||
|
|
||||||
String getMetaType();
|
String getMetaType();
|
|
@ -17,10 +17,10 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpamodelgen;
|
package org.hibernate.jpamodelgen;
|
||||||
|
|
||||||
import org.hibernate.jpamodelgen.IMetaAttribute;
|
import org.hibernate.jpamodelgen.MetaAttribute;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Hardy Ferentschik
|
* @author Hardy Ferentschik
|
||||||
*/
|
*/
|
||||||
public interface IMetaCollection extends IMetaAttribute {
|
public interface MetaCollection extends MetaAttribute {
|
||||||
}
|
}
|
|
@ -24,14 +24,14 @@ import java.util.List;
|
||||||
/**
|
/**
|
||||||
* @author Hardy Ferentschik
|
* @author Hardy Ferentschik
|
||||||
*/
|
*/
|
||||||
public interface IMetaEntity extends ImportContext {
|
public interface MetaEntity extends ImportContext {
|
||||||
String getSimpleName();
|
String getSimpleName();
|
||||||
|
|
||||||
String getQualifiedName();
|
String getQualifiedName();
|
||||||
|
|
||||||
String getPackageName();
|
String getPackageName();
|
||||||
|
|
||||||
List<IMetaAttribute> getMembers();
|
List<MetaAttribute> getMembers();
|
||||||
|
|
||||||
String generateImports();
|
String generateImports();
|
||||||
|
|
|
@ -20,5 +20,5 @@ package org.hibernate.jpamodelgen;
|
||||||
/**
|
/**
|
||||||
* @author Hardy Ferentschik
|
* @author Hardy Ferentschik
|
||||||
*/
|
*/
|
||||||
public interface IMetaSingleAttribute extends IMetaAttribute {
|
public interface MetaSingleAttribute extends MetaAttribute {
|
||||||
}
|
}
|
|
@ -17,7 +17,7 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpamodelgen.annotation;
|
package org.hibernate.jpamodelgen.annotation;
|
||||||
|
|
||||||
import org.hibernate.jpamodelgen.IMetaAttribute;
|
import org.hibernate.jpamodelgen.MetaAttribute;
|
||||||
|
|
||||||
import java.beans.Introspector;
|
import java.beans.Introspector;
|
||||||
|
|
||||||
|
@ -31,14 +31,14 @@ import javax.lang.model.element.ElementKind;
|
||||||
* @author Hardy Ferentschik
|
* @author Hardy Ferentschik
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public abstract class MetaAttribute implements IMetaAttribute {
|
public abstract class AnnotationMetaAttribute implements MetaAttribute {
|
||||||
|
|
||||||
final protected Element element;
|
final protected Element element;
|
||||||
final protected MetaEntity parent;
|
final protected AnnotationMetaEntity parent;
|
||||||
final protected ProcessingEnvironment pe;
|
final protected ProcessingEnvironment pe;
|
||||||
private final String type;
|
private final String type;
|
||||||
|
|
||||||
public MetaAttribute(MetaEntity parent, Element element, String type) {
|
public AnnotationMetaAttribute(AnnotationMetaEntity parent, Element element, String type) {
|
||||||
this.element = element;
|
this.element = element;
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.type = type;
|
this.type = type;
|
|
@ -17,7 +17,7 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpamodelgen.annotation;
|
package org.hibernate.jpamodelgen.annotation;
|
||||||
|
|
||||||
import org.hibernate.jpamodelgen.IMetaCollection;
|
import org.hibernate.jpamodelgen.MetaCollection;
|
||||||
|
|
||||||
import javax.lang.model.element.Element;
|
import javax.lang.model.element.Element;
|
||||||
|
|
||||||
|
@ -27,12 +27,12 @@ import javax.lang.model.element.Element;
|
||||||
* @author Hardy Ferentschik
|
* @author Hardy Ferentschik
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class MetaCollection extends MetaAttribute implements IMetaCollection {
|
public class AnnotationMetaCollection extends AnnotationMetaAttribute implements MetaCollection {
|
||||||
|
|
||||||
private String collectionType;
|
private String collectionType;
|
||||||
|
|
||||||
|
|
||||||
public MetaCollection(MetaEntity parent, Element element, String collectionType, String elementType) {
|
public AnnotationMetaCollection(AnnotationMetaEntity parent, Element element, String collectionType, String elementType) {
|
||||||
super(parent, element, elementType);
|
super(parent, element, elementType);
|
||||||
this.collectionType = collectionType;
|
this.collectionType = collectionType;
|
||||||
}
|
}
|
|
@ -48,8 +48,8 @@ import javax.persistence.ElementCollection;
|
||||||
import javax.tools.Diagnostic.Kind;
|
import javax.tools.Diagnostic.Kind;
|
||||||
import javax.tools.Diagnostic;
|
import javax.tools.Diagnostic;
|
||||||
|
|
||||||
import org.hibernate.jpamodelgen.IMetaEntity;
|
import org.hibernate.jpamodelgen.MetaEntity;
|
||||||
import org.hibernate.jpamodelgen.IMetaAttribute;
|
import org.hibernate.jpamodelgen.MetaAttribute;
|
||||||
import org.hibernate.jpamodelgen.ImportContext;
|
import org.hibernate.jpamodelgen.ImportContext;
|
||||||
import org.hibernate.jpamodelgen.ImportContextImpl;
|
import org.hibernate.jpamodelgen.ImportContextImpl;
|
||||||
import org.hibernate.jpamodelgen.TypeUtils;
|
import org.hibernate.jpamodelgen.TypeUtils;
|
||||||
|
@ -61,7 +61,7 @@ import org.hibernate.jpamodelgen.Context;
|
||||||
* @author Hardy Ferentschik
|
* @author Hardy Ferentschik
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class MetaEntity implements IMetaEntity {
|
public class AnnotationMetaEntity implements MetaEntity {
|
||||||
|
|
||||||
final TypeElement element;
|
final TypeElement element;
|
||||||
final protected ProcessingEnvironment pe;
|
final protected ProcessingEnvironment pe;
|
||||||
|
@ -72,14 +72,14 @@ public class MetaEntity implements IMetaEntity {
|
||||||
private AccessType defaultAccessTypeForHierarchy;
|
private AccessType defaultAccessTypeForHierarchy;
|
||||||
private AccessType defaultAccessTypeForElement;
|
private AccessType defaultAccessTypeForElement;
|
||||||
|
|
||||||
public MetaEntity(ProcessingEnvironment pe, TypeElement element, Context context) {
|
public AnnotationMetaEntity(ProcessingEnvironment pe, TypeElement element, Context context) {
|
||||||
this.element = element;
|
this.element = element;
|
||||||
this.pe = pe;
|
this.pe = pe;
|
||||||
importContext = new ImportContextImpl( getPackageName() );
|
importContext = new ImportContextImpl( getPackageName() );
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MetaEntity(ProcessingEnvironment pe, TypeElement element, Context context, AccessType accessType) {
|
public AnnotationMetaEntity(ProcessingEnvironment pe, TypeElement element, Context context, AccessType accessType) {
|
||||||
this(pe, element, context);
|
this(pe, element, context);
|
||||||
this.defaultAccessTypeForHierarchy = accessType;
|
this.defaultAccessTypeForHierarchy = accessType;
|
||||||
}
|
}
|
||||||
|
@ -101,8 +101,8 @@ public class MetaEntity implements IMetaEntity {
|
||||||
return pe.getElementUtils().getName( packageOf.getQualifiedName() ).toString();
|
return pe.getElementUtils().getName( packageOf.getQualifiedName() ).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<IMetaAttribute> getMembers() {
|
public List<MetaAttribute> getMembers() {
|
||||||
List<IMetaAttribute> membersFound = new ArrayList<IMetaAttribute>();
|
List<MetaAttribute> membersFound = new ArrayList<MetaAttribute>();
|
||||||
final AccessType elementAccessType = getAccessTypeForElement();
|
final AccessType elementAccessType = getAccessTypeForElement();
|
||||||
|
|
||||||
List<? extends Element> fieldsOfClass = ElementFilter.fieldsIn( element.getEnclosedElements() );
|
List<? extends Element> fieldsOfClass = ElementFilter.fieldsIn( element.getEnclosedElements() );
|
||||||
|
@ -132,7 +132,7 @@ public class MetaEntity implements IMetaEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addPersistentMembers(
|
private void addPersistentMembers(
|
||||||
List<IMetaAttribute> membersFound,
|
List<MetaAttribute> membersFound,
|
||||||
AccessType elementAccessType,
|
AccessType elementAccessType,
|
||||||
List<? extends Element> membersOfClass,
|
List<? extends Element> membersOfClass,
|
||||||
AccessType membersKind) {
|
AccessType membersKind) {
|
||||||
|
@ -149,7 +149,7 @@ public class MetaEntity implements IMetaEntity {
|
||||||
}
|
}
|
||||||
for ( Element memberOfClass : membersOfClass ) {
|
for ( Element memberOfClass : membersOfClass ) {
|
||||||
|
|
||||||
MetaAttribute result = memberOfClass.asType().accept( new TypeVisitor( this, explicitAccessType ),
|
AnnotationMetaAttribute result = memberOfClass.asType().accept( new TypeVisitor( this, explicitAccessType ),
|
||||||
memberOfClass
|
memberOfClass
|
||||||
);
|
);
|
||||||
if ( result != null ) {
|
if ( result != null ) {
|
||||||
|
@ -296,27 +296,27 @@ public class MetaEntity implements IMetaEntity {
|
||||||
COLLECTIONS.put( "java.util.Map", "javax.persistence.metamodel.MapAttribute" );
|
COLLECTIONS.put( "java.util.Map", "javax.persistence.metamodel.MapAttribute" );
|
||||||
}
|
}
|
||||||
|
|
||||||
class TypeVisitor extends SimpleTypeVisitor6<MetaAttribute, Element> {
|
class TypeVisitor extends SimpleTypeVisitor6<AnnotationMetaAttribute, Element> {
|
||||||
|
|
||||||
MetaEntity parent;
|
AnnotationMetaEntity parent;
|
||||||
//if null, process all members as implicit
|
//if null, process all members as implicit
|
||||||
//if not null, only process members marked as @Access(explicitAccessType)
|
//if not null, only process members marked as @Access(explicitAccessType)
|
||||||
private AccessType explicitAccessType;
|
private AccessType explicitAccessType;
|
||||||
|
|
||||||
TypeVisitor(MetaEntity parent, AccessType explicitAccessType) {
|
TypeVisitor(AnnotationMetaEntity parent, AccessType explicitAccessType) {
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.explicitAccessType = explicitAccessType;
|
this.explicitAccessType = explicitAccessType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected MetaAttribute defaultAction(TypeMirror e, Element p) {
|
protected AnnotationMetaAttribute defaultAction(TypeMirror e, Element p) {
|
||||||
return super.defaultAction( e, p );
|
return super.defaultAction( e, p );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MetaAttribute visitPrimitive(PrimitiveType t, Element element) {
|
public AnnotationMetaAttribute visitPrimitive(PrimitiveType t, Element element) {
|
||||||
if ( isPersistent( element ) ) {
|
if ( isPersistent( element ) ) {
|
||||||
return new MetaSingleAttribute( parent, element, TypeUtils.toTypeString( t ) );
|
return new AnnotationMetaSingleAttribute( parent, element, TypeUtils.toTypeString( t ) );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return null;
|
return null;
|
||||||
|
@ -344,7 +344,7 @@ public class MetaEntity implements IMetaEntity {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MetaAttribute visitDeclared(DeclaredType t, Element element) {
|
public AnnotationMetaAttribute visitDeclared(DeclaredType t, Element element) {
|
||||||
//FIXME consider XML
|
//FIXME consider XML
|
||||||
if ( isPersistent( element ) ) {
|
if ( isPersistent( element ) ) {
|
||||||
TypeElement returnedElement = ( TypeElement ) pe.getTypeUtils().asElement( t );
|
TypeElement returnedElement = ( TypeElement ) pe.getTypeUtils().asElement( t );
|
||||||
|
@ -359,10 +359,10 @@ public class MetaEntity implements IMetaEntity {
|
||||||
this.parent.defaultAccessTypeForElement );
|
this.parent.defaultAccessTypeForElement );
|
||||||
}
|
}
|
||||||
if ( collection.equals( "javax.persistence.metamodel.MapAttribute" ) ) {
|
if ( collection.equals( "javax.persistence.metamodel.MapAttribute" ) ) {
|
||||||
return new MetaMap( parent, element, collection, getKeyType( t ), getElementType( t ) );
|
return new AnnotationMetaMap( parent, element, collection, getKeyType( t ), getElementType( t ) );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return new MetaCollection( parent, element, collection, getElementType( t ) );
|
return new AnnotationMetaCollection( parent, element, collection, getElementType( t ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -372,7 +372,7 @@ public class MetaEntity implements IMetaEntity {
|
||||||
this.parent.context.processElement( returnedElement,
|
this.parent.context.processElement( returnedElement,
|
||||||
this.parent.defaultAccessTypeForElement );
|
this.parent.defaultAccessTypeForElement );
|
||||||
}
|
}
|
||||||
return new MetaSingleAttribute( parent, element, returnedElement.getQualifiedName().toString() );
|
return new AnnotationMetaSingleAttribute( parent, element, returnedElement.getQualifiedName().toString() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -382,7 +382,7 @@ public class MetaEntity implements IMetaEntity {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MetaAttribute visitExecutable(ExecutableType t, Element p) {
|
public AnnotationMetaAttribute visitExecutable(ExecutableType t, Element p) {
|
||||||
String string = p.getSimpleName().toString();
|
String string = p.getSimpleName().toString();
|
||||||
|
|
||||||
// TODO: implement proper property get/is/boolean detection
|
// TODO: implement proper property get/is/boolean detection
|
|
@ -25,16 +25,16 @@ import javax.lang.model.element.Element;
|
||||||
* @author Hardy Ferentschik
|
* @author Hardy Ferentschik
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class MetaMap extends MetaCollection {
|
public class AnnotationMetaMap extends AnnotationMetaCollection {
|
||||||
|
|
||||||
private final String keyType;
|
private final String keyType;
|
||||||
|
|
||||||
public MetaMap(MetaEntity parent, Element element, String collectionType,
|
public AnnotationMetaMap(AnnotationMetaEntity parent, Element element, String collectionType,
|
||||||
String keyType, String elementType) {
|
String keyType, String elementType) {
|
||||||
super(parent, element, collectionType, elementType);
|
super(parent, element, collectionType, elementType);
|
||||||
this.keyType = keyType;
|
this.keyType = keyType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDeclarationString() {
|
public String getDeclarationString() {
|
||||||
return "public static volatile " + parent.importType(getMetaType()) + "<" + parent.importType(parent.getQualifiedName()) + ", " + parent.importType(keyType) + ", " + parent.importType(getTypeDeclaration()) + "> " + getPropertyName() + ";";
|
return "public static volatile " + parent.importType(getMetaType()) + "<" + parent.importType(parent.getQualifiedName()) + ", " + parent.importType(keyType) + ", " + parent.importType(getTypeDeclaration()) + "> " + getPropertyName() + ";";
|
||||||
}
|
}
|
|
@ -17,7 +17,7 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpamodelgen.annotation;
|
package org.hibernate.jpamodelgen.annotation;
|
||||||
|
|
||||||
import org.hibernate.jpamodelgen.IMetaSingleAttribute;
|
import org.hibernate.jpamodelgen.MetaSingleAttribute;
|
||||||
|
|
||||||
import javax.lang.model.element.Element;
|
import javax.lang.model.element.Element;
|
||||||
|
|
||||||
|
@ -27,9 +27,9 @@ import javax.lang.model.element.Element;
|
||||||
* @author Hardy Ferentschik
|
* @author Hardy Ferentschik
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
public class MetaSingleAttribute extends MetaAttribute implements IMetaSingleAttribute {
|
public class AnnotationMetaSingleAttribute extends AnnotationMetaAttribute implements MetaSingleAttribute {
|
||||||
|
|
||||||
public MetaSingleAttribute(MetaEntity parent, Element element, String type) {
|
public AnnotationMetaSingleAttribute(AnnotationMetaEntity parent, Element element, String type) {
|
||||||
super(parent, element, type);
|
super(parent, element, type);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,12 +18,12 @@
|
||||||
|
|
||||||
package org.hibernate.jpamodelgen.xml;
|
package org.hibernate.jpamodelgen.xml;
|
||||||
|
|
||||||
import org.hibernate.jpamodelgen.IMetaAttribute;
|
import org.hibernate.jpamodelgen.MetaAttribute;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Hardy Ferentschik
|
* @author Hardy Ferentschik
|
||||||
*/
|
*/
|
||||||
public abstract class XmlMetaAttribute implements IMetaAttribute {
|
public abstract class XmlMetaAttribute implements MetaAttribute {
|
||||||
|
|
||||||
private XmlMetaEntity parentEntity;
|
private XmlMetaEntity parentEntity;
|
||||||
|
|
||||||
|
|
|
@ -17,12 +17,12 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpamodelgen.xml;
|
package org.hibernate.jpamodelgen.xml;
|
||||||
|
|
||||||
import org.hibernate.jpamodelgen.IMetaCollection;
|
import org.hibernate.jpamodelgen.MetaCollection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Hardy Ferentschik
|
* @author Hardy Ferentschik
|
||||||
*/
|
*/
|
||||||
public class XmlMetaCollection extends XmlMetaAttribute implements IMetaCollection {
|
public class XmlMetaCollection extends XmlMetaAttribute implements MetaCollection {
|
||||||
|
|
||||||
String collectionType;
|
String collectionType;
|
||||||
|
|
||||||
|
|
|
@ -26,9 +26,9 @@ import javax.lang.model.element.Name;
|
||||||
import javax.lang.model.element.TypeElement;
|
import javax.lang.model.element.TypeElement;
|
||||||
import javax.lang.model.type.DeclaredType;
|
import javax.lang.model.type.DeclaredType;
|
||||||
|
|
||||||
import org.hibernate.jpamodelgen.IMetaAttribute;
|
import org.hibernate.jpamodelgen.MetaAttribute;
|
||||||
import org.hibernate.jpamodelgen.ImportContextImpl;
|
import org.hibernate.jpamodelgen.ImportContextImpl;
|
||||||
import org.hibernate.jpamodelgen.IMetaEntity;
|
import org.hibernate.jpamodelgen.MetaEntity;
|
||||||
import org.hibernate.jpamodelgen.ImportContext;
|
import org.hibernate.jpamodelgen.ImportContext;
|
||||||
import org.hibernate.jpamodelgen.xml.jaxb.Attributes;
|
import org.hibernate.jpamodelgen.xml.jaxb.Attributes;
|
||||||
import org.hibernate.jpamodelgen.xml.jaxb.Basic;
|
import org.hibernate.jpamodelgen.xml.jaxb.Basic;
|
||||||
|
@ -45,7 +45,7 @@ import org.hibernate.jpamodelgen.xml.jaxb.OneToOne;
|
||||||
/**
|
/**
|
||||||
* @author Hardy Ferentschik
|
* @author Hardy Ferentschik
|
||||||
*/
|
*/
|
||||||
public class XmlMetaEntity implements IMetaEntity {
|
public class XmlMetaEntity implements MetaEntity {
|
||||||
|
|
||||||
static Map<String, String> COLLECTIONS = new HashMap<String, String>();
|
static Map<String, String> COLLECTIONS = new HashMap<String, String>();
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ public class XmlMetaEntity implements IMetaEntity {
|
||||||
|
|
||||||
final private ImportContext importContext;
|
final private ImportContext importContext;
|
||||||
|
|
||||||
final private List<IMetaAttribute> members = new ArrayList<IMetaAttribute>();
|
final private List<MetaAttribute> members = new ArrayList<MetaAttribute>();
|
||||||
|
|
||||||
private TypeElement element;
|
private TypeElement element;
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ public class XmlMetaEntity implements IMetaEntity {
|
||||||
return packageName;
|
return packageName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<IMetaAttribute> getMembers() {
|
public List<MetaAttribute> getMembers() {
|
||||||
return members;
|
return members;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,12 +17,12 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpamodelgen.xml;
|
package org.hibernate.jpamodelgen.xml;
|
||||||
|
|
||||||
import org.hibernate.jpamodelgen.IMetaSingleAttribute;
|
import org.hibernate.jpamodelgen.MetaSingleAttribute;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Hardy Ferentschik
|
* @author Hardy Ferentschik
|
||||||
*/
|
*/
|
||||||
public class XmlMetaSingleAttribute extends XmlMetaAttribute implements IMetaSingleAttribute {
|
public class XmlMetaSingleAttribute extends XmlMetaAttribute implements MetaSingleAttribute {
|
||||||
|
|
||||||
public XmlMetaSingleAttribute(XmlMetaEntity parent, String propertyName, String type) {
|
public XmlMetaSingleAttribute(XmlMetaEntity parent, String propertyName, String type) {
|
||||||
super(parent, propertyName, type);
|
super(parent, propertyName, type);
|
||||||
|
|
|
@ -0,0 +1,90 @@
|
||||||
|
// $Id$
|
||||||
|
/*
|
||||||
|
* JBoss, Home of Professional Open Source
|
||||||
|
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
|
||||||
|
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||||
|
* full listing of individual contributors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.hibernate.jpamodelgen.test.accesstype;
|
||||||
|
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import org.hibernate.jpamodelgen.test.util.CompilationTest;
|
||||||
|
import static org.hibernate.jpamodelgen.test.util.TestUtil.assertAbsenceOfField;
|
||||||
|
import static org.hibernate.jpamodelgen.test.util.TestUtil.assertPresenceOfField;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Emmanuel Bernard
|
||||||
|
* @author Hardy Ferentschik
|
||||||
|
*/
|
||||||
|
public class AccessTypeTest extends CompilationTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testExcludeTransientFieldAndStatic() throws Exception {
|
||||||
|
assertAbsenceOfField( Product.class.getName() + "_", "nonPersistent" );
|
||||||
|
assertAbsenceOfField( Product.class.getName() + "_", "nonPersistent2" );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDefaultAccessTypeOnEntity() throws Exception {
|
||||||
|
assertAbsenceOfField( User.class.getName() + "_", "nonPersistent" );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDefaultAccessTypeForSubclassOfEntity() throws Exception {
|
||||||
|
assertAbsenceOfField( Customer.class.getName() + "_", "nonPersistent" );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDefaultAccessTypeForEmbeddable() throws Exception {
|
||||||
|
assertAbsenceOfField( Detail.class.getName() + "_", "nonPersistent" );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInheritedAccessTypeForEmbeddable() throws Exception {
|
||||||
|
assertAbsenceOfField( Country.class.getName() + "_", "nonPersistent" );
|
||||||
|
assertAbsenceOfField(
|
||||||
|
Pet.class.getName() + "_", "nonPersistent", "Collection of embeddable not taken care of"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDefaultAccessTypeForMappedSuperclass() throws Exception {
|
||||||
|
assertAbsenceOfField( Detail.class.getName() + "_", "volume" );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testExplicitAccessTypeAndDefaultFromRootEntity() throws Exception {
|
||||||
|
assertAbsenceOfField(
|
||||||
|
LivingBeing.class.getName() + "_",
|
||||||
|
"nonPersistent",
|
||||||
|
"explicit access type on mapped superclass"
|
||||||
|
);
|
||||||
|
assertAbsenceOfField( Hominidae.class.getName() + "_", "nonPersistent", "explicit access type on entity" );
|
||||||
|
assertAbsenceOfField(
|
||||||
|
Human.class.getName() + "_",
|
||||||
|
"nonPersistent",
|
||||||
|
"proper inheritance from root entity access type"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMemberAccessType() throws Exception {
|
||||||
|
assertPresenceOfField( Customer.class.getName() + "_", "goodPayer", "access type overriding" );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getTestPackage() {
|
||||||
|
return Product.class.getPackage().getName();
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,12 +15,11 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package model;
|
package org.hibernate.jpamodelgen.test.accesstype;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import javax.persistence.Embeddable;
|
import javax.persistence.Embeddable;
|
||||||
import javax.persistence.Access;
|
import javax.persistence.Access;
|
||||||
import javax.persistence.AccessType;
|
|
||||||
import javax.persistence.ElementCollection;
|
import javax.persistence.ElementCollection;
|
||||||
import javax.persistence.CollectionTable;
|
import javax.persistence.CollectionTable;
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package model;
|
package org.hibernate.jpamodelgen.test.accesstype;
|
||||||
|
|
||||||
import javax.persistence.MappedSuperclass;
|
import javax.persistence.MappedSuperclass;
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package model;
|
package org.hibernate.jpamodelgen.test.accesstype;
|
||||||
|
|
||||||
import javax.persistence.MappedSuperclass;
|
import javax.persistence.MappedSuperclass;
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package model;
|
package org.hibernate.jpamodelgen.test.accesstype;
|
||||||
|
|
||||||
import javax.persistence.Embeddable;
|
import javax.persistence.Embeddable;
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package model;
|
package org.hibernate.jpamodelgen.test.accesstype;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
|
@ -15,7 +15,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package model;
|
package org.hibernate.jpamodelgen.test.accesstype;
|
||||||
|
|
||||||
import javax.persistence.Embeddable;
|
import javax.persistence.Embeddable;
|
||||||
|
|
|
@ -15,11 +15,10 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package model;
|
package org.hibernate.jpamodelgen.test.accesstype;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.Access;
|
import javax.persistence.Access;
|
||||||
import javax.persistence.AccessType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
|
@ -15,7 +15,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package model;
|
package org.hibernate.jpamodelgen.test.accesstype;
|
||||||
|
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
|
@ -15,7 +15,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package model;
|
package org.hibernate.jpamodelgen.test.accesstype;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
// $Id$
|
||||||
|
/*
|
||||||
|
* JBoss, Home of Professional Open Source
|
||||||
|
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
|
||||||
|
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||||
|
* full listing of individual contributors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.hibernate.jpamodelgen.test.accesstype;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Emmanuel Bernard
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
public class Image {
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private byte[] data;
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setData(byte[] data) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,12 +15,11 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package model;
|
package org.hibernate.jpamodelgen.test.accesstype;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import javax.persistence.Embeddable;
|
import javax.persistence.Embeddable;
|
||||||
import javax.persistence.Access;
|
import javax.persistence.Access;
|
||||||
import javax.persistence.AccessType;
|
|
||||||
import javax.persistence.ElementCollection;
|
import javax.persistence.ElementCollection;
|
||||||
|
|
||||||
/**
|
/**
|
|
@ -15,16 +15,17 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package model;
|
package org.hibernate.jpamodelgen.test.accesstype;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.ManyToOne;
|
import javax.persistence.ManyToOne;
|
||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
|
|
||||||
|
import org.hibernate.jpamodelgen.test.accesstype.Product;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Max Andersen
|
* @author Max Andersen
|
|
@ -15,11 +15,10 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package model;
|
package org.hibernate.jpamodelgen.test.accesstype;
|
||||||
|
|
||||||
import javax.persistence.MappedSuperclass;
|
import javax.persistence.MappedSuperclass;
|
||||||
import javax.persistence.Access;
|
import javax.persistence.Access;
|
||||||
import javax.persistence.AccessType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
|
@ -15,7 +15,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package model;
|
package org.hibernate.jpamodelgen.test.accesstype;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
|
@ -15,7 +15,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package model;
|
package org.hibernate.jpamodelgen.test.accesstype;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
|
@ -15,7 +15,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package model;
|
package org.hibernate.jpamodelgen.test.accesstype;
|
||||||
|
|
||||||
import javax.persistence.Embeddable;
|
import javax.persistence.Embeddable;
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package model;
|
package org.hibernate.jpamodelgen.test.accesstype;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -25,6 +25,9 @@ import javax.persistence.Id;
|
||||||
import javax.persistence.ManyToOne;
|
import javax.persistence.ManyToOne;
|
||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
|
|
||||||
|
import org.hibernate.jpamodelgen.test.accesstype.Item;
|
||||||
|
import org.hibernate.jpamodelgen.test.accesstype.Shop;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Max Andersen
|
* @author Max Andersen
|
|
@ -15,7 +15,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package model;
|
package org.hibernate.jpamodelgen.test.accesstype;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
|
@ -15,7 +15,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package model;
|
package org.hibernate.jpamodelgen.test.accesstype;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
|
@ -0,0 +1,59 @@
|
||||||
|
// $Id$
|
||||||
|
/*
|
||||||
|
* JBoss, Home of Professional Open Source
|
||||||
|
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
|
||||||
|
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||||
|
* full listing of individual contributors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.hibernate.jpamodelgen.test.inheritance;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
// $Id$
|
||||||
|
/*
|
||||||
|
* JBoss, Home of Professional Open Source
|
||||||
|
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
|
||||||
|
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||||
|
* full listing of individual contributors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.hibernate.jpamodelgen.test.inheritance;
|
||||||
|
|
||||||
|
import java.sql.Date;
|
||||||
|
import javax.persistence.MappedSuperclass;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Emmanuel Bernard
|
||||||
|
*/
|
||||||
|
@MappedSuperclass
|
||||||
|
public class Building extends Area {
|
||||||
|
public Date getBuiltIn() {
|
||||||
|
return builtIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBuiltIn(Date builtIn) {
|
||||||
|
this.builtIn = builtIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Date builtIn;
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
// $Id$
|
||||||
|
/*
|
||||||
|
* JBoss, Home of Professional Open Source
|
||||||
|
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
|
||||||
|
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||||
|
* full listing of individual contributors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.hibernate.jpamodelgen.test.inheritance;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Emmanuel Bernard
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
public class Customer extends User {
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
// $Id$
|
||||||
|
/*
|
||||||
|
* JBoss, Home of Professional Open Source
|
||||||
|
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
|
||||||
|
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||||
|
* full listing of individual contributors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.hibernate.jpamodelgen.test.inheritance;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,32 +15,33 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package test;
|
package org.hibernate.jpamodelgen.test.inheritance;
|
||||||
|
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.testng.Assert;
|
|
||||||
import model.Customer_;
|
import org.hibernate.jpamodelgen.test.util.CompilationTest;
|
||||||
import model.User_;
|
import static org.hibernate.jpamodelgen.test.util.TestUtil.assertSuperClass;
|
||||||
import model.House_;
|
|
||||||
import model.Building_;
|
|
||||||
import model.Area_;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
|
* @author Hardy Ferentschik
|
||||||
*/
|
*/
|
||||||
@Test
|
public class InheritanceTest extends CompilationTest {
|
||||||
public class InheritanceTest {
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuperEntity() throws Exception {
|
public void testSuperEntity() throws Exception {
|
||||||
Assert.assertEquals( Customer_.class.getSuperclass(), User_.class,
|
assertSuperClass(
|
||||||
"Entity with super entity should inherit at the metamodel level");
|
Customer.class.getName() + "_", User.class.getName() + "_"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMappedSuperclass() throws Exception {
|
public void testMappedSuperclass() throws Exception {
|
||||||
Assert.assertEquals( House_.class.getSuperclass(), Building_.class,
|
assertSuperClass( House.class.getName() + "_", Building.class.getName() + "_" );
|
||||||
"Entity with mapped superclass should inherit at the metamodel level");
|
assertSuperClass( Building.class.getName() + "_", Area.class.getName() + "_" );
|
||||||
Assert.assertEquals( Building_.class.getSuperclass(), Area_.class,
|
}
|
||||||
"mapped superclass with mapped superclass should inherit at the metamodel level");
|
|
||||||
|
@Override
|
||||||
|
protected String getTestPackage() {
|
||||||
|
return Customer.class.getPackage().getName();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,58 @@
|
||||||
|
// $Id$
|
||||||
|
/*
|
||||||
|
* JBoss, Home of Professional Open Source
|
||||||
|
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
|
||||||
|
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||||
|
* full listing of individual contributors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.hibernate.jpamodelgen.test.inheritance;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,127 @@
|
||||||
|
// $Id:$
|
||||||
|
/*
|
||||||
|
* JBoss, Home of Professional Open Source
|
||||||
|
* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
|
||||||
|
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||||
|
* full listing of individual contributors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.hibernate.jpamodelgen.test.util;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FilenameFilter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import javax.tools.Diagnostic;
|
||||||
|
import javax.tools.DiagnosticCollector;
|
||||||
|
import javax.tools.JavaCompiler;
|
||||||
|
import javax.tools.JavaFileObject;
|
||||||
|
import javax.tools.StandardJavaFileManager;
|
||||||
|
import javax.tools.ToolProvider;
|
||||||
|
|
||||||
|
import static org.testng.FileAssert.fail;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Hardy Ferentschik
|
||||||
|
*/
|
||||||
|
public abstract class CompilationTest {
|
||||||
|
|
||||||
|
private static final String PATH_SEPARATOR = System.getProperty( "file.separator" );
|
||||||
|
private static final String sourceBaseDir;
|
||||||
|
private static final String outBaseDir;
|
||||||
|
|
||||||
|
static {
|
||||||
|
String tmp = System.getProperty( "sourceBaseDir" );
|
||||||
|
if ( tmp == null ) {
|
||||||
|
fail( "The system property sourceBaseDir has to be set and point to the base directory of the test java sources." );
|
||||||
|
}
|
||||||
|
sourceBaseDir = tmp;
|
||||||
|
|
||||||
|
tmp = System.getProperty( "outBaseDir" );
|
||||||
|
if ( tmp == null ) {
|
||||||
|
fail( "The system property outBaseDir has to be set and point to the base directory of the test output directory." );
|
||||||
|
}
|
||||||
|
outBaseDir = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompilationTest() {
|
||||||
|
try {
|
||||||
|
compile();
|
||||||
|
}
|
||||||
|
catch ( Exception e ) {
|
||||||
|
fail( "Unable to compile test sources. " + e.getMessage() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void compile() throws IOException {
|
||||||
|
List<String> options = createJavaOptions();
|
||||||
|
|
||||||
|
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
|
||||||
|
DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
|
||||||
|
StandardJavaFileManager fileManager = compiler.getStandardFileManager( diagnostics, null, null );
|
||||||
|
Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromFiles(
|
||||||
|
getCompilationUnits( sourceBaseDir )
|
||||||
|
);
|
||||||
|
|
||||||
|
// TODO - need to call the compiler twice. Once to compile the test classes and generate the java files
|
||||||
|
// of the generated metamodel. The second compile is for generated the class files of the metamodel.
|
||||||
|
// Note sure why this is not recursive the same way as on the command line
|
||||||
|
compileSources( options, compiler, diagnostics, fileManager, compilationUnits );
|
||||||
|
|
||||||
|
compilationUnits = fileManager.getJavaFileObjectsFromFiles(
|
||||||
|
getCompilationUnits( outBaseDir )
|
||||||
|
);
|
||||||
|
compileSources( options, compiler, diagnostics, fileManager, compilationUnits );
|
||||||
|
fileManager.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void compileSources(List<String> options, JavaCompiler compiler, DiagnosticCollector<JavaFileObject> diagnostics, StandardJavaFileManager fileManager, Iterable<? extends JavaFileObject> compilationUnits) {
|
||||||
|
JavaCompiler.CompilationTask task = compiler.getTask(
|
||||||
|
null, fileManager, diagnostics, options, null, compilationUnits
|
||||||
|
);
|
||||||
|
task.call();
|
||||||
|
// for ( Diagnostic diagnostic : diagnostics.getDiagnostics() ) {
|
||||||
|
// System.out.println( diagnostic.getMessage( null ) );
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> createJavaOptions() {
|
||||||
|
// TODO
|
||||||
|
// passing any other options as -d seems to throw IllegalArgumentExceptions. I would like to set -s for example
|
||||||
|
// in order to see whether recursive recompilation would work then. Also '-proc only' could be interesting
|
||||||
|
List<String> options = new ArrayList<String>();
|
||||||
|
options.add( "-d" );
|
||||||
|
options.add( outBaseDir );
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<File> getCompilationUnits(String baseDir) {
|
||||||
|
List<File> javaFiles = new ArrayList<File>();
|
||||||
|
String packageDirName = baseDir + PATH_SEPARATOR + getTestPackage().replace( ".", PATH_SEPARATOR );
|
||||||
|
File packageDir = new File( packageDirName );
|
||||||
|
FilenameFilter javaFileFilter = new FilenameFilter() {
|
||||||
|
@Override
|
||||||
|
public boolean accept(File dir, String name) {
|
||||||
|
return name.endsWith( ".java" );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
for ( File file : packageDir.listFiles( javaFileFilter ) ) {
|
||||||
|
javaFiles.add( file );
|
||||||
|
}
|
||||||
|
return javaFiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract protected String getTestPackage();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,83 @@
|
||||||
|
// $Id:$
|
||||||
|
/*
|
||||||
|
* JBoss, Home of Professional Open Source
|
||||||
|
* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
|
||||||
|
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||||
|
* full listing of individual contributors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.hibernate.jpamodelgen.test.util;
|
||||||
|
|
||||||
|
import org.testng.Assert;
|
||||||
|
import static org.testng.Assert.assertNotNull;
|
||||||
|
import static org.testng.FileAssert.fail;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Hardy Ferentschik
|
||||||
|
*/
|
||||||
|
public class TestUtil {
|
||||||
|
|
||||||
|
private TestUtil() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertClassGenerated(String className) {
|
||||||
|
try {
|
||||||
|
assertNotNull( Class.forName( className ) );
|
||||||
|
}
|
||||||
|
catch ( ClassNotFoundException e ) {
|
||||||
|
fail( e.getMessage() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertAbsenceOfField(String className, String fieldName) throws ClassNotFoundException {
|
||||||
|
assertAbsenceOfField( className, fieldName, "field should not be persistent" );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertAbsenceOfField(String className, String fieldName, String errorString)
|
||||||
|
throws ClassNotFoundException {
|
||||||
|
Assert.assertFalse( isFieldHere( className, fieldName ), errorString );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertPresenceOfField(String className, String fieldName, String errorString)
|
||||||
|
throws ClassNotFoundException {
|
||||||
|
Assert.assertTrue( isFieldHere( className, fieldName ), errorString );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertSuperClass(String className, String superClassName) {
|
||||||
|
Class<?> clazz;
|
||||||
|
Class<?> superClazz;
|
||||||
|
try {
|
||||||
|
clazz = Class.forName( className );
|
||||||
|
superClazz = Class.forName( superClassName );
|
||||||
|
Assert.assertEquals(
|
||||||
|
clazz.getSuperclass(), superClazz,
|
||||||
|
"Entity " + superClassName + " should be the superclass of " + className
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch ( ClassNotFoundException e ) {
|
||||||
|
fail( "Unable to load metamodel class: " + e.getMessage() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isFieldHere(String className, String fieldName) throws ClassNotFoundException {
|
||||||
|
Class<?> clazz = Class.forName( className );
|
||||||
|
try {
|
||||||
|
clazz.getField( fieldName );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch ( NoSuchFieldException e ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package model.xmlmapped;
|
package org.hibernate.jpamodelgen.test.xmlmapped;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Hardy Ferentschik
|
* @author Hardy Ferentschik
|
|
@ -15,10 +15,10 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package model.xmlmapped;
|
package org.hibernate.jpamodelgen.test.xmlmapped;
|
||||||
|
|
||||||
import model.Address;
|
import org.hibernate.jpamodelgen.test.accesstype.*;
|
||||||
import model.Area;
|
import org.hibernate.jpamodelgen.test.accesstype.Address;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Hardy Ferentschik
|
* @author Hardy Ferentschik
|
||||||
|
@ -30,7 +30,7 @@ public class Building extends Area {
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAddress(Address address) {
|
public void setAddress(org.hibernate.jpamodelgen.test.accesstype.Address address) {
|
||||||
this.address = address;
|
this.address = address;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -15,7 +15,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package model.xmlmapped;
|
package org.hibernate.jpamodelgen.test.xmlmapped;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Hardy Ferentschik
|
* @author Hardy Ferentschik
|
|
@ -15,7 +15,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package model.xmlmapped;
|
package org.hibernate.jpamodelgen.test.xmlmapped;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Hardy Ferentschik
|
* @author Hardy Ferentschik
|
|
@ -15,41 +15,46 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package test;
|
package org.hibernate.jpamodelgen.test.xmlmapped;
|
||||||
|
|
||||||
import static org.testng.Assert.assertNotNull;
|
|
||||||
import static org.testng.Assert.assertTrue;
|
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import org.hibernate.jpamodelgen.test.util.CompilationTest;
|
||||||
|
import static org.hibernate.jpamodelgen.test.util.TestUtil.assertClassGenerated;
|
||||||
|
import static org.hibernate.jpamodelgen.test.util.TestUtil.assertPresenceOfField;
|
||||||
|
import static org.hibernate.jpamodelgen.test.util.TestUtil.assertSuperClass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Hardy Ferentschik
|
* @author Hardy Ferentschik
|
||||||
*/
|
*/
|
||||||
public class XmlMappingTest {
|
public class XmlMappingTest extends CompilationTest {
|
||||||
@Test
|
@Test
|
||||||
public void testXmlConfiguredEmbeddedClassGenerated() throws Exception {
|
public void testXmlConfiguredEmbeddedClassGenerated() throws Exception {
|
||||||
assertNotNull( Class.forName( "model.xmlmapped.Address_" ) );
|
assertClassGenerated( Address.class.getName() + "_" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testXmlConfiguredMappedSuperclassGenerated() throws Exception {
|
public void testXmlConfiguredMappedSuperclassGenerated() throws Exception {
|
||||||
Class<?> building = Class.forName( "model.xmlmapped.Building_" );
|
assertClassGenerated( Building.class.getName() + "_" );
|
||||||
assertNotNull( building );
|
assertPresenceOfField(
|
||||||
assertNotNull( building.getField( "address" ) );
|
Building.class.getName() + "_", "address", "address field should exist"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testClassHierarchy() throws Exception {
|
public void testClassHierarchy() throws Exception {
|
||||||
Class<?> mammal = Class.forName( "model.xmlmapped.Mammal_" );
|
assertClassGenerated( Mammal.class.getName() + "_" );
|
||||||
assertNotNull( mammal );
|
assertClassGenerated( LivingBeing.class.getName() + "_" );
|
||||||
|
assertSuperClass( Mammal.class.getName() + "_", LivingBeing.class.getName() + "_" );
|
||||||
Class<?> being = Class.forName( "model.xmlmapped.LivingBeing_" );
|
|
||||||
assertNotNull( being );
|
|
||||||
|
|
||||||
assertTrue( mammal.getSuperclass().equals( being ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = ClassNotFoundException.class)
|
@Test(expectedExceptions = ClassNotFoundException.class)
|
||||||
public void testNonExistentMappedClassesGetIgnored() throws Exception {
|
public void testNonExistentMappedClassesGetIgnored() throws Exception {
|
||||||
Class.forName( "model.Dummy_" );
|
Class.forName( "org.hibernate.jpamodelgen.test.model.Dummy_" );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getTestPackage() {
|
||||||
|
return Address.class.getPackage().getName();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,94 +0,0 @@
|
||||||
// $Id$
|
|
||||||
/*
|
|
||||||
* JBoss, Home of Professional Open Source
|
|
||||||
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
|
|
||||||
* by the @authors tag. See the copyright.txt in the distribution for a
|
|
||||||
* full listing of individual contributors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package test;
|
|
||||||
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
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 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" );
|
|
||||||
}
|
|
||||||
|
|
||||||
@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 {
|
|
||||||
user_.getField( fieldName );
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (NoSuchFieldException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,166 +0,0 @@
|
||||||
// $Id$
|
|
||||||
/*
|
|
||||||
* JBoss, Home of Professional Open Source
|
|
||||||
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
|
|
||||||
* by the @authors tag. See the copyright.txt in the distribution for a
|
|
||||||
* full listing of individual contributors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package test;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Set;
|
|
||||||
import javax.persistence.Tuple;
|
|
||||||
import javax.persistence.criteria.CriteriaBuilder;
|
|
||||||
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.Root;
|
|
||||||
|
|
||||||
import model.Item;
|
|
||||||
import model.Item_;
|
|
||||||
import model.Order;
|
|
||||||
import model.Order_;
|
|
||||||
import model.Product;
|
|
||||||
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.
|
|
||||||
*
|
|
||||||
* @author Max Andersen
|
|
||||||
* @author Hardy Ferentschik
|
|
||||||
* @author Emmanuel Bernard
|
|
||||||
*/
|
|
||||||
public class QueryTest {
|
|
||||||
|
|
||||||
CriteriaBuilder 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 );
|
|
||||||
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.jpamodelgen.criteria.Order o = qb.asc(n);
|
|
||||||
javax.jpamodelgen.criteria.Order p = qb.ascending(s);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
}
|
|
|
@ -5,7 +5,7 @@
|
||||||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
|
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
|
||||||
version="2.0"
|
version="2.0"
|
||||||
>
|
>
|
||||||
<package>model</package>
|
<package>org.hibernate.jpamodelgen.test.model</package>
|
||||||
<entity class="Dummy" access="FIELD" metadata-complete="true"> <!-- Class does not exist -->
|
<entity class="Dummy" access="FIELD" metadata-complete="true"> <!-- Class does not exist -->
|
||||||
<attributes>
|
<attributes>
|
||||||
<id name="id"/>
|
<id name="id"/>
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd"
|
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd"
|
||||||
version="1.0"
|
version="1.0"
|
||||||
>
|
>
|
||||||
<package>model</package>
|
<package>org.hibernate.jpamodelgen.test.model</package>
|
||||||
<entity class="Airplane" metadata-complete="true" access="PROPERTY">
|
<entity class="Airplane" metadata-complete="true" access="PROPERTY">
|
||||||
<attributes>
|
<attributes>
|
||||||
<id name="serialNumber"/>
|
<id name="serialNumber"/>
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
|
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
|
||||||
version="2.0"
|
version="2.0"
|
||||||
>
|
>
|
||||||
<package>model</package>
|
<package>org.hibernate.jpamodelgen.test.model</package>
|
||||||
<entity class="Dummy" access="FIELD" metadata-complete="true"> <!-- Class does not exist -->
|
<entity class="Dummy" access="FIELD" metadata-complete="true"> <!-- Class does not exist -->
|
||||||
<attributes>
|
<attributes>
|
||||||
<id name="id"/>
|
<id name="id"/>
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
|
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
|
||||||
version="2.0"
|
version="2.0"
|
||||||
>
|
>
|
||||||
<package>model</package>
|
<package>org.hibernate.jpamodelgen.test.accesstype</package>
|
||||||
<!-- default package -->
|
<!-- default package -->
|
||||||
<entity class="Order" access="FIELD" metadata-complete="true"> <!--means ignore annotations-->
|
<entity class="Order" access="FIELD" metadata-complete="true"> <!--means ignore annotations-->
|
||||||
<attributes>
|
<attributes>
|
||||||
|
@ -16,7 +16,7 @@
|
||||||
<basic name="date"/>
|
<basic name="date"/>
|
||||||
<many-to-one name="shop"/>
|
<many-to-one name="shop"/>
|
||||||
<one-to-many name="items"
|
<one-to-many name="items"
|
||||||
target-entity="Item"
|
target-entity="org.hibernate.jpamodelgen.test.accesstype.Item"
|
||||||
fetch="EAGER"> <!-- target-entity optional guess the type from the geenric-->
|
fetch="EAGER"> <!-- target-entity optional guess the type from the geenric-->
|
||||||
<cascade>
|
<cascade>
|
||||||
<cascade-persist/>
|
<cascade-persist/>
|
||||||
|
|
|
@ -7,8 +7,8 @@
|
||||||
<mapping-file>/META-INF/dummy.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/malformed-mapping-xml.xml</mapping-file>
|
||||||
<mapping-file>/META-INF/jpa1-orm.xml</mapping-file>
|
<mapping-file>/META-INF/jpa1-orm.xml</mapping-file>
|
||||||
<mapping-file>/model/xmlmapped/address.xml</mapping-file>
|
<mapping-file>/org/hibernate/jpamodelgen/test/xmlmapped/address.xml</mapping-file>
|
||||||
<mapping-file>/model/xmlmapped/building.xml</mapping-file>
|
<mapping-file>/org/hibernate/jpamodelgen/test/xmlmapped/building.xml</mapping-file>
|
||||||
<mapping-file>/model/xmlmapped/mammal.xml</mapping-file>
|
<mapping-file>/org/hibernate/jpamodelgen/test/xmlmapped/mammal.xml</mapping-file>
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
</persistence>
|
</persistence>
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
|
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
|
||||||
version="2.0"
|
version="2.0"
|
||||||
>
|
>
|
||||||
<package>model.xmlmapped</package> <!-- default package -->
|
<package>org.hibernate.jpamodelgen.test.xmlmapped</package> <!-- default package -->
|
||||||
<embeddable class="Address" access="FIELD" metadata-complete="true"> <!--means ignore annotations-->
|
<embeddable class="Address" access="FIELD" metadata-complete="true"> <!--means ignore annotations-->
|
||||||
<attributes>
|
<attributes>
|
||||||
<basic name="street1"/>
|
<basic name="street1"/>
|
|
@ -5,7 +5,7 @@
|
||||||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
|
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
|
||||||
version="2.0"
|
version="2.0"
|
||||||
>
|
>
|
||||||
<package>model.xmlmapped</package>
|
<package>org.hibernate.jpamodelgen.test.xmlmapped</package>
|
||||||
<mapped-superclass class="Building" access="FIELD" metadata-complete="true"> <!--means ignore annotations-->
|
<mapped-superclass class="Building" access="FIELD" metadata-complete="true"> <!--means ignore annotations-->
|
||||||
<attributes>
|
<attributes>
|
||||||
<one-to-one name="address" fetch="LAZY"/>
|
<one-to-one name="address" fetch="LAZY"/>
|
|
@ -5,7 +5,7 @@
|
||||||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
|
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
|
||||||
version="2.0"
|
version="2.0"
|
||||||
>
|
>
|
||||||
<package>model.xmlmapped</package>
|
<package>org.hibernate.jpamodelgen.test.xmlmapped</package>
|
||||||
<entity class="LivingBeing" access="FIELD" metadata-complete="true">
|
<entity class="LivingBeing" access="FIELD" metadata-complete="true">
|
||||||
<attributes>
|
<attributes>
|
||||||
<basic name="isReallyAlive"/>
|
<basic name="isReallyAlive"/>
|
|
@ -3,7 +3,9 @@
|
||||||
<suite name="Hibernate Model Generator Tests" verbose="1">
|
<suite name="Hibernate Model Generator Tests" verbose="1">
|
||||||
<test name="Unit tests">
|
<test name="Unit tests">
|
||||||
<packages>
|
<packages>
|
||||||
<package name="test"/>
|
<package name="org.hibernate.jpamodelgen.test.accesstype"/>
|
||||||
|
<package name="org.hibernate.jpamodelgen.test.inheritance"/>
|
||||||
|
<package name="org.hibernate.jpamodelgen.test.xmlmapped"/>
|
||||||
</packages>
|
</packages>
|
||||||
</test>
|
</test>
|
||||||
</suite>
|
</suite>
|
Loading…
Reference in New Issue