Hibernate SVN: r18680 - in jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test: rawtypes and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-02-01 16:02:12 -0500 (Mon, 01 Feb 2010)
New Revision: 18680
Added:
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawtypes/
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawtypes/DeskWithRawType.java
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawtypes/EmployeeWithRawType.java
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawtypes/RawTypesTest.java
Log:
METAGEN-9
Added: jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawtypes/DeskWithRawType.java
===================================================================
--- jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawtypes/DeskWithRawType.java (rev 0)
+++ jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawtypes/DeskWithRawType.java 2010-02-01 21:02:12 UTC (rev 18680)
@@ -0,0 +1,62 @@
+package org.hibernate.jpamodelgen.test.rawtypes;
+
+import java.util.Collection;
+import javax.persistence.Basic;
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinTable;
+import javax.persistence.ManyToMany;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class DeskWithRawType implements java.io.Serializable {
+
+ @Id
+ protected String id;
+
+ @Basic
+ protected String name;
+
+
+ public DeskWithRawType() {
+ }
+
+ @ManyToMany(targetEntity = EmployeeWithRawType.class, cascade = CascadeType.ALL)
+ @JoinTable(name = "DESK_EMPL",
+ joinColumns =
+ @JoinColumn(
+ name = "DESK_FK", referencedColumnName = "ID"),
+ inverseJoinColumns =
+ @JoinColumn(
+ name = "EMPLO_FK", referencedColumnName = "ID")
+ )
+ protected Collection employees = new java.util.ArrayList();
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Collection getEmployees() {
+ return employees;
+ }
+
+ public void setEmployees(Collection employees) {
+ this.employees = employees;
+ }
+}
\ No newline at end of file
Added: jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawtypes/EmployeeWithRawType.java
===================================================================
--- jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawtypes/EmployeeWithRawType.java (rev 0)
+++ jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawtypes/EmployeeWithRawType.java 2010-02-01 21:02:12 UTC (rev 18680)
@@ -0,0 +1,53 @@
+package org.hibernate.jpamodelgen.test.rawtypes;
+
+import java.util.Collection;
+import javax.persistence.Basic;
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.ManyToMany;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class EmployeeWithRawType implements java.io.Serializable {
+
+ @Id
+ protected String id;
+
+ @Basic
+ protected String name;
+
+
+ @ManyToMany(targetEntity = DeskWithRawType.class, mappedBy = "employees", cascade = CascadeType.ALL)
+ protected Collection desks = new java.util.ArrayList();
+
+
+ public EmployeeWithRawType() {
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Collection getDesks() {
+ return desks;
+ }
+
+ public void setDesks(Collection desks) {
+ this.desks = desks;
+ }
+}
Added: jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawtypes/RawTypesTest.java
===================================================================
--- jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawtypes/RawTypesTest.java (rev 0)
+++ jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/rawtypes/RawTypesTest.java 2010-02-01 21:02:12 UTC (rev 18680)
@@ -0,0 +1,49 @@
+// $Id: RawTypesTest.java 18664 2010-01-28 16:56:51Z hardy.ferentschik $
+/*
+* 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.rawtypes;
+
+import java.util.Collections;
+import java.util.Map;
+
+import org.testng.annotations.Test;
+
+import org.hibernate.jpamodelgen.test.util.CompilationTest;
+
+import static org.hibernate.jpamodelgen.test.util.TestUtil.assertMetamodelClassGeneratedFor;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class RawTypesTest extends CompilationTest {
+
+ @Test
+ public void testGenerics() {
+ assertMetamodelClassGeneratedFor( DeskWithRawType.class );
+ assertMetamodelClassGeneratedFor( EmployeeWithRawType.class );
+ }
+
+ @Override
+ protected String getTestPackage() {
+ return DeskWithRawType.class.getPackage().getName();
+ }
+
+ @Override
+ protected Map<String, String> getProcessorOptions() {
+ return Collections.emptyMap();
+ }
+}
\ No newline at end of file
14 years, 12 months
Hibernate SVN: r18678 - jpamodelgen/trunk/src/test/resources.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-02-01 15:54:23 -0500 (Mon, 01 Feb 2010)
New Revision: 18678
Added:
jpamodelgen/trunk/src/test/resources/log4j.properties
Log:
METAGEN-9
Added: jpamodelgen/trunk/src/test/resources/log4j.properties
===================================================================
--- jpamodelgen/trunk/src/test/resources/log4j.properties (rev 0)
+++ jpamodelgen/trunk/src/test/resources/log4j.properties 2010-02-01 20:54:23 UTC (rev 18678)
@@ -0,0 +1,24 @@
+### direct log messages to stdout ###
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.Target=System.out
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
+
+### direct messages to file hibernate.log ###
+log4j.appender.file=org.apache.log4j.FileAppender
+log4j.appender.file.File=hibernate.log
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
+
+### direct messages to socket - chainsaw ###
+log4j.appender.socket=org.apache.log4j.net.SocketAppender
+log4j.appender.socket.remoteHost=localhost
+log4j.appender.socket.port=4560
+log4j.appender.socket.locationInfo=true
+
+
+### set log levels - for more verbose logging change 'info' to 'debug' ###
+log4j.rootLogger=debug, stdout
+
+#log4j.logger.org.hibernate.jpamodelgen.test.util.CompilationTest=trace
+
14 years, 12 months
Hibernate SVN: r18677 - in jpamodelgen/trunk: src/main/java/org/hibernate/jpamodelgen and 14 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-02-01 15:49:09 -0500 (Mon, 01 Feb 2010)
New Revision: 18677
Added:
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/mixedmode/
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/mixedmode/Person.java
jpamodelgen/trunk/src/test/resources/org/hibernate/jpamodelgen/test/mixedmode/
jpamodelgen/trunk/src/test/resources/org/hibernate/jpamodelgen/test/mixedmode/orm.xml
jpamodelgen/trunk/src/test/resources/org/hibernate/jpamodelgen/test/mixedmode/persistence.xml
Removed:
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/model/
jpamodelgen/trunk/src/test/resources/org/hibernate/jpamodelgen/test/model/
Modified:
jpamodelgen/trunk/pom.xml
jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/ClassWriter.java
jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/Context.java
jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/JPAMetaModelEntityProcessor.java
jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/MetaEntity.java
jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/AnnotationMetaEntity.java
jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/xml/XmlMetaEntity.java
jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/xml/XmlParser.java
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/accesstype/AccessTypeTest.java
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/arraytype/ArrayTest.java
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/elementcollection/ElementCollectionTest.java
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/generics/GenericsTest.java
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/inheritance/InheritanceTest.java
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/util/CompilationTest.java
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/util/TestUtil.java
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/xmlmapped/XmlMappingTest.java
jpamodelgen/trunk/src/test/suite/unit-tests.xml
Log:
METAGEN-9 - Extended infrastructure to allow the specification of persistence.xml
Modified: jpamodelgen/trunk/pom.xml
===================================================================
--- jpamodelgen/trunk/pom.xml 2010-02-01 19:49:40 UTC (rev 18676)
+++ jpamodelgen/trunk/pom.xml 2010-02-01 20:49:09 UTC (rev 18677)
@@ -24,6 +24,17 @@
<classifier>jdk15</classifier>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.5.6</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <scope>test</scope>
+ <version>1.5.6</version>
+ </dependency>
</dependencies>
<licenses>
@@ -150,6 +161,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.3</version>
<configuration>
+ <redirectTestOutputToFile>true</redirectTestOutputToFile>
<systemProperties>
<property>
<name>sourceBaseDir</name>
Modified: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/ClassWriter.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/ClassWriter.java 2010-02-01 19:49:40 UTC (rev 18676)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/ClassWriter.java 2010-02-01 20:49:09 UTC (rev 18677)
@@ -112,8 +112,8 @@
//F..king Ch...t Have those people used their horrible APIs even once?
final Element superClassElement = ( ( DeclaredType ) superClass ).asElement();
String superClassName = ( ( TypeElement ) superClassElement ).getQualifiedName().toString();
- if ( context.getMetaEntitiesToProcess().containsKey( superClassName )
- || context.getMetaSuperclassAndEmbeddableToProcess().containsKey( superClassName ) ) {
+ if ( context.getMetaEntities().containsKey( superClassName )
+ || context.getMetaSuperclassAndEmbeddable().containsKey( superClassName ) ) {
pw.print( " extends " + superClassName + "_" );
}
}
Modified: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/Context.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/Context.java 2010-02-01 19:49:40 UTC (rev 18676)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/Context.java 2010-02-01 20:49:09 UTC (rev 18677)
@@ -35,17 +35,22 @@
* @author Emmanuel Bernard
*/
public class Context {
+ private static final String PATH_SEPARATOR = System.getProperty( "file.separator" );
+ private static final String DEFAULT_PERSISTENCE_XML_LOCATION = "/META-INF/persistence.xml";
+ private final Map<String, MetaEntity> metaEntities = new HashMap<String, MetaEntity>();
+ private final Map<String, MetaEntity> metaSuperclassAndEmbeddable = new HashMap<String, MetaEntity>();
- private final Map<String, MetaEntity> metaEntitiesToProcess = new HashMap<String, MetaEntity>();
- private final Map<String, MetaEntity> metaSuperclassAndEmbeddableToProcess = new HashMap<String, MetaEntity>();
+ private final ProcessingEnvironment pe;
+ private final boolean logDebug;
+ private final String persistenceXmlLocation;
- private ProcessingEnvironment pe;
- private boolean logDebug = false;
//used to cache access types
private Map<TypeElement, AccessTypeHolder> accessTypes = new HashMap<TypeElement, AccessTypeHolder>();
private Set<String> elementsAlreadyProcessed = new HashSet<String>();
+ private boolean isPersistenceUnitCompletelyXmlConfigured;
+
private static class AccessTypeHolder {
public AccessType elementAccessType;
public AccessType hierarchyAccessType;
@@ -53,24 +58,38 @@
public Context(ProcessingEnvironment pe) {
this.pe = pe;
- String debugParam = pe.getOptions().get( JPAMetaModelEntityProcessor.DEBUG_OPTION );
- if ( debugParam != null && "true".equals( debugParam ) ) {
- logDebug = true;
+
+ if ( pe.getOptions().get( JPAMetaModelEntityProcessor.PERSISTENCE_XML_OPTION ) != null ) {
+ String tmp = pe.getOptions().get( JPAMetaModelEntityProcessor.PERSISTENCE_XML_OPTION );
+ if ( !tmp.startsWith( PATH_SEPARATOR ) ) {
+ tmp = PATH_SEPARATOR + tmp;
+ }
+ persistenceXmlLocation = tmp;
}
+ else {
+ persistenceXmlLocation = DEFAULT_PERSISTENCE_XML_LOCATION;
+ }
+
+ logDebug = Boolean.parseBoolean( pe.getOptions().get( JPAMetaModelEntityProcessor.DEBUG_OPTION ) );
+
}
public ProcessingEnvironment getProcessingEnvironment() {
return pe;
}
- public Map<String, MetaEntity> getMetaEntitiesToProcess() {
- return metaEntitiesToProcess;
+ public String getPersistenceXmlLocation() {
+ return persistenceXmlLocation;
}
- public Map<String, MetaEntity> getMetaSuperclassAndEmbeddableToProcess() {
- return metaSuperclassAndEmbeddableToProcess;
+ public Map<String, MetaEntity> getMetaEntities() {
+ return metaEntities;
}
+ public Map<String, MetaEntity> getMetaSuperclassAndEmbeddable() {
+ return metaSuperclassAndEmbeddable;
+ }
+
public void addAccessType(TypeElement element, AccessType accessType) {
AccessTypeHolder typeHolder = accessTypes.get( element );
if ( typeHolder == null ) {
@@ -94,7 +113,7 @@
return typeHolder != null ? typeHolder.elementAccessType : null;
}
- public AccessType getDefaultAccessTypeForHerarchy(TypeElement element) {
+ public AccessType getDefaultAccessTypeForHierarchy(TypeElement element) {
final AccessTypeHolder typeHolder = accessTypes.get( element );
return typeHolder != null ? typeHolder.hierarchyAccessType : null;
}
@@ -105,6 +124,7 @@
//only process Embeddable or Superclass
//does not work for Entity (risk of circularity)
+
public void processElement(TypeElement element, AccessType defaultAccessTypeForHierarchy) {
if ( elementsAlreadyProcessed.contains( element.getQualifiedName().toString() ) ) {
logMessage( Diagnostic.Kind.OTHER, "Element already processed (ignoring): " + element );
@@ -121,4 +141,12 @@
}
pe.getMessager().printMessage( type, message );
}
+
+ public boolean isPersistenceUnitCompletelyXmlConfigured() {
+ return isPersistenceUnitCompletelyXmlConfigured;
+ }
+
+ public void setPersistenceUnitCompletelyXmlConfigured(boolean persistenceUnitCompletelyXmlConfigured) {
+ isPersistenceUnitCompletelyXmlConfigured = persistenceUnitCompletelyXmlConfigured;
+ }
}
Modified: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/JPAMetaModelEntityProcessor.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/JPAMetaModelEntityProcessor.java 2010-02-01 19:49:40 UTC (rev 18676)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/JPAMetaModelEntityProcessor.java 2010-02-01 20:49:09 UTC (rev 18677)
@@ -52,6 +52,7 @@
@SupportedOptions({ JPAMetaModelEntityProcessor.DEBUG_OPTION })
public class JPAMetaModelEntityProcessor extends AbstractProcessor {
public static final String DEBUG_OPTION = "debug";
+ public static final String PERSISTENCE_XML_OPTION = "persistenceXml";
private static final Boolean ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS = Boolean.FALSE;
private boolean xmlProcessed = false;
@@ -87,6 +88,10 @@
return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
}
+ if ( context.isPersistenceUnitCompletelyXmlConfigured() ) {
+ return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
+ }
+
Set<? extends Element> elements = roundEnvironment.getRootElements();
for ( Element element : elements ) {
context.logMessage( Diagnostic.Kind.OTHER, "Processing " + element.toString() );
@@ -97,17 +102,17 @@
}
private void createMetaModelClasses() {
- for ( MetaEntity entity : context.getMetaEntitiesToProcess().values() ) {
+ for ( MetaEntity entity : context.getMetaEntities().values() ) {
context.logMessage( Diagnostic.Kind.OTHER, "Writing meta model for " + entity );
ClassWriter.writeFile( entity, context );
}
//process left over, in most cases is empty
for ( String className : context.getElementsAlreadyProcessed() ) {
- context.getMetaSuperclassAndEmbeddableToProcess().remove( className );
+ context.getMetaSuperclassAndEmbeddable().remove( className );
}
- for ( MetaEntity entity : context.getMetaSuperclassAndEmbeddableToProcess().values() ) {
+ for ( MetaEntity entity : context.getMetaSuperclassAndEmbeddable().values() ) {
context.logMessage( Diagnostic.Kind.OTHER, "Writing meta model for " + entity );
ClassWriter.writeFile( entity, context );
}
@@ -129,22 +134,23 @@
}
private void handleRootElementAnnotationMirrors(final Element element) {
-
List<? extends AnnotationMirror> annotationMirrors = element.getAnnotationMirrors();
-
for ( AnnotationMirror mirror : annotationMirrors ) {
if ( element.getKind() == ElementKind.CLASS ) {
if ( TypeUtils.isAnnotationMirrorOfType( mirror, Entity.class ) ) {
AnnotationMetaEntity metaEntity = new AnnotationMetaEntity( ( TypeElement ) element, context );
- // TODO instead of just adding the entity we have to do some merging.
- context.getMetaEntitiesToProcess().put( metaEntity.getQualifiedName(), metaEntity );
+ MetaEntity alreadyExistingMetaEntity = context.getMetaEntities()
+ .get( metaEntity.getQualifiedName() );
+ if ( alreadyExistingMetaEntity != null && alreadyExistingMetaEntity.isMetaComplete() ) {
+ continue;
+ }
+ context.getMetaEntities().put( metaEntity.getQualifiedName(), metaEntity );
}
else if ( TypeUtils.isAnnotationMirrorOfType( mirror, MappedSuperclass.class )
|| TypeUtils.isAnnotationMirrorOfType( mirror, Embeddable.class ) ) {
AnnotationMetaEntity metaEntity = new AnnotationMetaEntity( ( TypeElement ) element, context );
-
// TODO instead of just adding the entity we have to do some merging.
- context.getMetaSuperclassAndEmbeddableToProcess().put( metaEntity.getQualifiedName(), metaEntity );
+ context.getMetaSuperclassAndEmbeddable().put( metaEntity.getQualifiedName(), metaEntity );
}
}
}
Modified: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/MetaEntity.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/MetaEntity.java 2010-02-01 19:49:40 UTC (rev 18676)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/MetaEntity.java 2010-02-01 20:49:09 UTC (rev 18677)
@@ -42,4 +42,6 @@
String importType(Name qualifiedName);
TypeElement getTypeElement();
+
+ boolean isMetaComplete();
}
Modified: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/AnnotationMetaEntity.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/AnnotationMetaEntity.java 2010-02-01 19:49:40 UTC (rev 18676)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/AnnotationMetaEntity.java 2010-02-01 20:49:09 UTC (rev 18677)
@@ -139,6 +139,11 @@
return membersFound;
}
+ @Override
+ public boolean isMetaComplete() {
+ return false;
+ }
+
private void addPersistentMembers(
List<MetaAttribute> membersFound,
AccessType elementAccessType,
@@ -212,7 +217,7 @@
AccessType accessType = context.getAccessType( searchedElement );
if ( defaultAccessTypeForHierarchy == null ) {
- this.defaultAccessTypeForHierarchy = context.getDefaultAccessTypeForHerarchy( searchedElement );
+ this.defaultAccessTypeForHierarchy = context.getDefaultAccessTypeForHierarchy( searchedElement );
}
if ( accessType != null ) {
context.logMessage( Diagnostic.Kind.OTHER, "Found in cache" + searchedElement + ":" + accessType );
@@ -249,7 +254,7 @@
accessType = kind == ElementKind.FIELD ? AccessType.FIELD : AccessType.PROPERTY;
//FIXME enlever in niveau
if ( defaultAccessTypeForHierarchy == null ) {
- this.defaultAccessTypeForHierarchy = context.getDefaultAccessTypeForHerarchy(
+ this.defaultAccessTypeForHierarchy = context.getDefaultAccessTypeForHierarchy(
searchedElement
);
//we've discovered the class hierarchy, let's cache it
Modified: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/xml/XmlMetaEntity.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/xml/XmlMetaEntity.java 2010-02-01 19:49:40 UTC (rev 18676)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/xml/XmlMetaEntity.java 2010-02-01 20:49:09 UTC (rev 18677)
@@ -62,17 +62,15 @@
COLLECTIONS.put( "java.util.Map", "javax.persistence.metamodel.MapAttribute" );
}
- final private String clazzName;
+ private final String clazzName;
+ private final String packageName;
+ private final ImportContext importContext;
+ private final List<MetaAttribute> members = new ArrayList<MetaAttribute>();
+ private final TypeElement element;
+ private final Context context;
- final private String packageName;
+ private boolean isMetaComplete;
- final private ImportContext importContext;
-
- final private List<MetaAttribute> members = new ArrayList<MetaAttribute>();
-
- private TypeElement element;
- private Context context;
-
public XmlMetaEntity(Entity ormEntity, String packageName, TypeElement element, Context context) {
this.clazzName = ormEntity.getClazz();
this.packageName = packageName;
@@ -140,6 +138,11 @@
return element;
}
+ @Override
+ public boolean isMetaComplete() {
+ return isMetaComplete;
+ }
+
private String[] getCollectionType(String propertyName, String explicitTargetEntity) {
String types[] = new String[2];
for ( Element elem : element.getEnclosedElements() ) {
Modified: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/xml/XmlParser.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/xml/XmlParser.java 2010-02-01 19:49:40 UTC (rev 18676)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/xml/XmlParser.java 2010-02-01 20:49:09 UTC (rev 18677)
@@ -48,8 +48,6 @@
* @author Hardy Ferentschik
*/
public class XmlParser {
-
- private static final String PERSISTENCE_XML = "/META-INF/persistence.xml";
private static final String ORM_XML = "/META-INF/orm.xml";
private static final String PERSISTENCE_XML_XSD = "persistence_2_0.xsd";
private static final String ORM_XSD = "orm_2_0.xsd";
@@ -63,17 +61,24 @@
}
public void parsePersistenceXml() {
- Persistence persistence = parseXml( PERSISTENCE_XML, Persistence.class, PERSISTENCE_XML_XSD );
- if ( persistence != null ) {
- List<Persistence.PersistenceUnit> persistenceUnits = persistence.getPersistenceUnit();
- for ( Persistence.PersistenceUnit unit : persistenceUnits ) {
- List<String> mappingFiles = unit.getMappingFile();
- for ( String mappingFile : mappingFiles ) {
- parsingOrmXml( mappingFile );
- }
+ // /META-INF/orm.xml is implicit
+ parsingOrmXml( ORM_XML );
+
+ Persistence persistence = parseXml(
+ context.getPersistenceXmlLocation(), Persistence.class, PERSISTENCE_XML_XSD
+ );
+ if ( persistence == null ) {
+ return;
+ }
+
+ List<Persistence.PersistenceUnit> persistenceUnits = persistence.getPersistenceUnit();
+ for ( Persistence.PersistenceUnit unit : persistenceUnits ) {
+ List<String> mappingFiles = unit.getMappingFile();
+ for ( String mappingFile : mappingFiles ) {
+ parsingOrmXml( mappingFile );
}
}
- parsingOrmXml( ORM_XML ); // /META-INF/orm.xml is implicit
+
}
private void parsingOrmXml(String resource) {
@@ -83,6 +88,7 @@
}
AccessType accessType = determineGlobalAccessType( mappings );
+ context.setPersistenceUnitCompletelyXmlConfigured( determineGlobalXmlMetadataCompleteness( mappings ) );
parseEntities( mappings, accessType );
parseEmbeddable( mappings, accessType );
@@ -108,13 +114,13 @@
context
);
- if ( context.getMetaEntitiesToProcess().containsKey( fullyQualifiedClassName ) ) {
+ if ( context.getMetaEntities().containsKey( fullyQualifiedClassName ) ) {
context.logMessage(
Diagnostic.Kind.WARNING,
fullyQualifiedClassName + " was already processed once. Skipping second occurance."
);
}
- context.getMetaEntitiesToProcess().put( fullyQualifiedClassName, metaEntity );
+ context.getMetaEntities().put( fullyQualifiedClassName, metaEntity );
}
}
@@ -137,13 +143,13 @@
context
);
- if ( context.getMetaSuperclassAndEmbeddableToProcess().containsKey( fullyQualifiedClassName ) ) {
+ if ( context.getMetaSuperclassAndEmbeddable().containsKey( fullyQualifiedClassName ) ) {
context.logMessage(
Diagnostic.Kind.WARNING,
fullyQualifiedClassName + " was already processed once. Skipping second occurance."
);
}
- context.getMetaSuperclassAndEmbeddableToProcess().put( fullyQualifiedClassName, metaEntity );
+ context.getMetaSuperclassAndEmbeddable().put( fullyQualifiedClassName, metaEntity );
}
}
@@ -167,13 +173,13 @@
context
);
- if ( context.getMetaSuperclassAndEmbeddableToProcess().containsKey( fullyQualifiedClassName ) ) {
+ if ( context.getMetaSuperclassAndEmbeddable().containsKey( fullyQualifiedClassName ) ) {
context.logMessage(
Diagnostic.Kind.WARNING,
fullyQualifiedClassName + " was already processed once. Skipping second occurance."
);
}
- context.getMetaSuperclassAndEmbeddableToProcess().put( fullyQualifiedClassName, metaEntity );
+ context.getMetaSuperclassAndEmbeddable().put( fullyQualifiedClassName, metaEntity );
}
}
@@ -283,7 +289,6 @@
return utils.getTypeElement( fullyQualifiedClassName );
}
-
private AccessType determineGlobalAccessType(EntityMappings mappings) {
AccessType accessType = DEFAULT_XML_ACCESS_TYPE;
@@ -305,6 +310,15 @@
return accessType;
}
+ private boolean determineGlobalXmlMetadataCompleteness(EntityMappings mappings) {
+ boolean metadataComplete = false;
+ PersistenceUnitMetadata puMetadata = mappings.getPersistenceUnitMetadata();
+ if ( puMetadata != null && puMetadata.getXmlMappingMetadataComplete() != null ) {
+ metadataComplete = true;
+ }
+ return metadataComplete;
+ }
+
private AccessType mapXmlAccessTypeToJpaAccessType(org.hibernate.jpamodelgen.xml.jaxb.AccessType xmlAccessType) {
switch ( xmlAccessType ) {
case FIELD: {
Modified: jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/accesstype/AccessTypeTest.java
===================================================================
--- jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/accesstype/AccessTypeTest.java 2010-02-01 19:49:40 UTC (rev 18676)
+++ jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/accesstype/AccessTypeTest.java 2010-02-01 20:49:09 UTC (rev 18677)
@@ -17,6 +17,9 @@
*/
package org.hibernate.jpamodelgen.test.accesstype;
+import java.util.Collections;
+import java.util.Map;
+
import org.testng.annotations.Test;
import org.hibernate.jpamodelgen.test.util.CompilationTest;
@@ -91,4 +94,9 @@
protected String getTestPackage() {
return Product.class.getPackage().getName();
}
+
+ @Override
+ protected Map<String, String> getProcessorOptions() {
+ return Collections.emptyMap();
+ }
}
Modified: jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/arraytype/ArrayTest.java
===================================================================
--- jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/arraytype/ArrayTest.java 2010-02-01 19:49:40 UTC (rev 18676)
+++ jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/arraytype/ArrayTest.java 2010-02-01 20:49:09 UTC (rev 18677)
@@ -17,6 +17,9 @@
*/
package org.hibernate.jpamodelgen.test.arraytype;
+import java.util.Collections;
+import java.util.Map;
+
import org.testng.annotations.Test;
import org.hibernate.jpamodelgen.test.util.CompilationTest;
@@ -50,4 +53,9 @@
protected String getTestPackage() {
return Image.class.getPackage().getName();
}
+
+ @Override
+ protected Map<String, String> getProcessorOptions() {
+ return Collections.emptyMap();
+ }
}
\ No newline at end of file
Modified: jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/elementcollection/ElementCollectionTest.java
===================================================================
--- jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/elementcollection/ElementCollectionTest.java 2010-02-01 19:49:40 UTC (rev 18676)
+++ jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/elementcollection/ElementCollectionTest.java 2010-02-01 20:49:09 UTC (rev 18677)
@@ -17,6 +17,9 @@
*/
package org.hibernate.jpamodelgen.test.elementcollection;
+import java.util.Collections;
+import java.util.Map;
+
import org.testng.annotations.Test;
import org.hibernate.jpamodelgen.test.util.CompilationTest;
@@ -57,6 +60,11 @@
@Override
protected String getTestPackage() {
- return House.class.getPackage().getName();
+ return ElementCollectionTest.class.getPackage().getName();
}
+
+ @Override
+ protected Map<String, String> getProcessorOptions() {
+ return Collections.emptyMap();
+ }
}
\ No newline at end of file
Modified: jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/generics/GenericsTest.java
===================================================================
--- jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/generics/GenericsTest.java 2010-02-01 19:49:40 UTC (rev 18676)
+++ jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/generics/GenericsTest.java 2010-02-01 20:49:09 UTC (rev 18677)
@@ -17,6 +17,9 @@
*/
package org.hibernate.jpamodelgen.test.generics;
+import java.util.Collections;
+import java.util.Map;
+
import org.testng.annotations.Test;
import org.hibernate.jpamodelgen.test.util.CompilationTest;
@@ -36,6 +39,11 @@
@Override
protected String getTestPackage() {
- return Parent.class.getPackage().getName();
+ return GenericsTest.class.getPackage().getName();
}
+
+ @Override
+ protected Map<String, String> getProcessorOptions() {
+ return Collections.emptyMap();
+ }
}
\ No newline at end of file
Modified: jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/inheritance/InheritanceTest.java
===================================================================
--- jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/inheritance/InheritanceTest.java 2010-02-01 19:49:40 UTC (rev 18676)
+++ jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/inheritance/InheritanceTest.java 2010-02-01 20:49:09 UTC (rev 18677)
@@ -17,6 +17,9 @@
*/
package org.hibernate.jpamodelgen.test.inheritance;
+import java.util.Collections;
+import java.util.Map;
+
import org.testng.annotations.Test;
import org.hibernate.jpamodelgen.test.util.CompilationTest;
@@ -41,6 +44,11 @@
@Override
protected String getTestPackage() {
- return Customer.class.getPackage().getName();
+ return InheritanceTest.class.getPackage().getName();
}
+
+ @Override
+ protected Map<String, String> getProcessorOptions() {
+ return Collections.emptyMap();
+ }
}
Copied: jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/mixedmode/Person.java (from rev 18664, jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/accesstype/Human.java)
===================================================================
--- jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/mixedmode/Person.java (rev 0)
+++ jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/mixedmode/Person.java 2010-02-01 20:49:09 UTC (rev 18677)
@@ -0,0 +1,49 @@
+// $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.mixedmode;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Entity
+public class Person {
+ @Id
+ @GeneratedValue
+ private long id;
+ private String name;
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
\ No newline at end of file
Property changes on: jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/mixedmode/Person.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/util/CompilationTest.java
===================================================================
--- jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/util/CompilationTest.java 2010-02-01 19:49:40 UTC (rev 18676)
+++ jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/util/CompilationTest.java 2010-02-01 20:49:09 UTC (rev 18677)
@@ -21,32 +21,41 @@
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
+import java.util.Map;
+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 org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import static org.testng.FileAssert.fail;
/**
* @author Hardy Ferentschik
*/
public abstract class CompilationTest {
-
+ private static final Logger log = LoggerFactory.getLogger( CompilationTest.class );
private static final String PATH_SEPARATOR = System.getProperty( "file.separator" );
+ private static final String ANNOTATION_PROCESSOR_OPTION_PREFIX = "-A";
+ private static final String SOURCE_BASE_DIR_PROPERTY = "sourceBaseDir";
+ private static final String OUT_BASE_DIR_PROPERTY = "outBaseDir";
private static final String sourceBaseDir;
private static final String outBaseDir;
static {
- String tmp = System.getProperty( "sourceBaseDir" );
+ String tmp = System.getProperty( SOURCE_BASE_DIR_PROPERTY );
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" );
+ tmp = System.getProperty( OUT_BASE_DIR_PROPERTY );
if ( tmp == null ) {
fail( "The system property outBaseDir has to be set and point to the base directory of the test output directory." );
}
@@ -59,7 +68,7 @@
compile();
}
catch ( Exception e ) {
- e.printStackTrace( );
+ e.printStackTrace();
fail( "Unable to compile test sources. " + e.getMessage() );
}
}
@@ -91,18 +100,25 @@
null, fileManager, diagnostics, options, null, compilationUnits
);
task.call();
-// for ( Diagnostic diagnostic : diagnostics.getDiagnostics() ) {
-// System.out.println( diagnostic.getMessage( null ) );
-// }
+ for ( Diagnostic diagnostic : diagnostics.getDiagnostics() ) {
+ log.debug( 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 );
+
+ // add any additional options specified by the test
+ for ( Map.Entry<String, String> entry : getProcessorOptions().entrySet() ) {
+ StringBuilder builder = new StringBuilder();
+ builder.append( ANNOTATION_PROCESSOR_OPTION_PREFIX );
+ builder.append( entry.getKey() );
+ builder.append( "=" );
+ builder.append( entry.getValue() );
+ options.add( builder.toString() );
+ }
return options;
}
@@ -117,16 +133,16 @@
}
};
final File[] files = packageDir.listFiles( javaFileFilter );
- if (files == null) {
+ if ( files == null ) {
throw new RuntimeException( "Cannot find package directory (is your base dir correct?): " + packageDirName );
}
- for ( File file : files ) {
- javaFiles.add( file );
- }
+ javaFiles.addAll( Arrays.asList( files ) );
return javaFiles;
}
abstract protected String getTestPackage();
+
+ abstract protected Map<String, String> getProcessorOptions();
}
Modified: jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/util/TestUtil.java
===================================================================
--- jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/util/TestUtil.java 2010-02-01 19:49:40 UTC (rev 18676)
+++ jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/util/TestUtil.java 2010-02-01 20:49:09 UTC (rev 18677)
@@ -36,6 +36,7 @@
public class TestUtil {
private static final String PATH_SEPARATOR = System.getProperty( "file.separator" );
+ private static final String PACKAGE_SEPARATOR = ".";
private static final String META_MODEL_CLASS_POSTFIX = "_";
private static final String outBaseDir;
@@ -78,7 +79,7 @@
assertNotNull( clazz, "Class parameter cannot be null" );
String metaModelClassName = clazz.getName() + META_MODEL_CLASS_POSTFIX;
// generate the file name
- String fileName = metaModelClassName.replace( ".", PATH_SEPARATOR );
+ String fileName = metaModelClassName.replace( PACKAGE_SEPARATOR, PATH_SEPARATOR );
fileName = fileName.concat( ".java" );
File sourceFile = new File( outBaseDir + PATH_SEPARATOR + fileName );
assertFalse( sourceFile.exists(), "There should be no source file: " + fileName );
@@ -157,6 +158,10 @@
}
return field;
}
+
+ public static String fcnToPath(String fcn) {
+ return fcn.replace( PACKAGE_SEPARATOR, PATH_SEPARATOR );
+ }
}
Modified: jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/xmlmapped/XmlMappingTest.java
===================================================================
--- jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/xmlmapped/XmlMappingTest.java 2010-02-01 19:49:40 UTC (rev 18676)
+++ jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/xmlmapped/XmlMappingTest.java 2010-02-01 20:49:09 UTC (rev 18677)
@@ -17,6 +17,9 @@
*/
package org.hibernate.jpamodelgen.test.xmlmapped;
+import java.util.Collections;
+import java.util.Map;
+
import org.testng.annotations.Test;
import org.hibernate.jpamodelgen.test.util.CompilationTest;
@@ -99,6 +102,11 @@
@Override
protected String getTestPackage() {
- return Address.class.getPackage().getName();
+ return XmlMappingTest.class.getPackage().getName();
}
+
+ @Override
+ protected Map<String, String> getProcessorOptions() {
+ return Collections.emptyMap();
+ }
}
\ No newline at end of file
Copied: jpamodelgen/trunk/src/test/resources/org/hibernate/jpamodelgen/test/mixedmode/orm.xml (from rev 18664, jpamodelgen/trunk/src/test/resources/org/hibernate/jpamodelgen/test/xmlmapped/address.xml)
===================================================================
--- jpamodelgen/trunk/src/test/resources/org/hibernate/jpamodelgen/test/mixedmode/orm.xml (rev 0)
+++ jpamodelgen/trunk/src/test/resources/org/hibernate/jpamodelgen/test/mixedmode/orm.xml 2010-02-01 20:49:09 UTC (rev 18677)
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
+ version="2.0"
+ >
+ <persistence-unit-metadata>
+ <xml-mapping-metadata-complete/>
+ </persistence-unit-metadata>
+ <package>org.hibernate.jpamodelgen.test.mixedmode</package>
+</entity-mappings>
+
Copied: jpamodelgen/trunk/src/test/resources/org/hibernate/jpamodelgen/test/mixedmode/persistence.xml (from rev 18664, jpamodelgen/trunk/src/test/resources/META-INF/persistence.xml)
===================================================================
--- jpamodelgen/trunk/src/test/resources/org/hibernate/jpamodelgen/test/mixedmode/persistence.xml (rev 0)
+++ jpamodelgen/trunk/src/test/resources/org/hibernate/jpamodelgen/test/mixedmode/persistence.xml 2010-02-01 20:49:09 UTC (rev 18677)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence xmlns="http://java.sun.com/xml/ns/persistence"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/persistence persistence.xsd" version="2.0">
+ <persistence-unit name="annotation-processor">
+ <mapping-file>/org/hibernate/jpamodelgen/test/mixedmode/orm.xml</mapping-file>
+ </persistence-unit>
+</persistence>
Modified: jpamodelgen/trunk/src/test/suite/unit-tests.xml
===================================================================
--- jpamodelgen/trunk/src/test/suite/unit-tests.xml 2010-02-01 19:49:40 UTC (rev 18676)
+++ jpamodelgen/trunk/src/test/suite/unit-tests.xml 2010-02-01 20:49:09 UTC (rev 18677)
@@ -8,7 +8,8 @@
<package name="org.hibernate.jpamodelgen.test.elementcollection"/>
<package name="org.hibernate.jpamodelgen.test.generics"/>
<package name="org.hibernate.jpamodelgen.test.inheritance"/>
- <package name="org.hibernate.jpamodelgen.test.rawTypes"/>
+ <package name="org.hibernate.jpamodelgen.test.mixedmode"/>
+ <package name="org.hibernate.jpamodelgen.test.rawtypes"/>
<package name="org.hibernate.jpamodelgen.test.xmlmapped"/>
</packages>
</test>
14 years, 12 months
Hibernate SVN: r18676 - core/trunk/core/src/main/java/org/hibernate/impl.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-02-01 14:49:40 -0500 (Mon, 01 Feb 2010)
New Revision: 18676
Modified:
core/trunk/core/src/main/java/org/hibernate/impl/SQLQueryImpl.java
Log:
HHH-4661 - Properly propagate Query.setLockMode to Hibernate Core
Modified: core/trunk/core/src/main/java/org/hibernate/impl/SQLQueryImpl.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/impl/SQLQueryImpl.java 2010-02-01 19:42:16 UTC (rev 18675)
+++ core/trunk/core/src/main/java/org/hibernate/impl/SQLQueryImpl.java 2010-02-01 19:49:40 UTC (rev 18676)
@@ -261,7 +261,7 @@
throw new UnsupportedOperationException("cannot set lock options for a native SQL query");
}
- protected LockOptions getLockOptions() {
+ public LockOptions getLockOptions() {
//we never need to apply locks to the SQL
return null;
}
14 years, 12 months
Hibernate SVN: r18675 - in core/trunk: core/src/main/java/org/hibernate/hql/classic and 7 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-02-01 14:42:16 -0500 (Mon, 01 Feb 2010)
New Revision: 18675
Added:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/util/LockModeTypeHelper.java
Modified:
core/trunk/core/src/main/java/org/hibernate/LockOptions.java
core/trunk/core/src/main/java/org/hibernate/hql/classic/QueryTranslatorImpl.java
core/trunk/core/src/main/java/org/hibernate/id/enhanced/TableGenerator.java
core/trunk/core/src/main/java/org/hibernate/impl/AbstractQueryImpl.java
core/trunk/core/src/main/java/org/hibernate/impl/QueryImpl.java
core/trunk/core/src/main/java/org/hibernate/loader/criteria/CriteriaLoader.java
core/trunk/core/src/main/java/org/hibernate/loader/criteria/CriteriaQueryTranslator.java
core/trunk/core/src/main/java/org/hibernate/loader/hql/QueryLoader.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AbstractEntityManagerImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AbstractQueryImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AvailableSettings.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernateEntityManagerImplementor.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/QueryImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/util/CacheModeHelper.java
core/trunk/testsuite/src/test/java/org/hibernate/test/dialect/unit/lockhint/AbstractLockHintTest.java
Log:
HHH-4661 - Properly propagate Query.setLockMode to Hibernate Core
Modified: core/trunk/core/src/main/java/org/hibernate/LockOptions.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/LockOptions.java 2010-01-31 21:50:23 UTC (rev 18674)
+++ core/trunk/core/src/main/java/org/hibernate/LockOptions.java 2010-02-01 19:42:16 UTC (rev 18675)
@@ -35,17 +35,8 @@
*
* @author Scott Marlow
*/
-public class LockOptions implements Serializable
-{
+public class LockOptions implements Serializable {
/**
- * NO_WAIT timeout value will not block for pessimistic locking
- */
- public static final int NO_WAIT = 0;
- /**
- * WAIT_FOREVER timeout value will block until pessimistic lock is obtained
- */
- public static final int WAIT_FOREVER = -1;
- /**
* NONE represents LockMode.NONE (timeout + scope do not apply)
*/
public static final LockOptions NONE = new LockOptions(LockMode.NONE);
@@ -59,15 +50,6 @@
*/
public static final LockOptions UPGRADE = new LockOptions(LockMode.UPGRADE);
- private LockMode lockMode = LockMode.NONE;
-
- private int timeout = WAIT_FOREVER; // timeout in milliseconds, 0 = no wait, -1 = wait indefinitely
-
- private boolean scope=false;// if true, cascade (pessimistic only) lock to collections and relationships
- // owned by the entity.
-
- private Map /* <String, LockMode> */ lockModesByName = new HashMap();
-
public LockOptions() {
}
@@ -75,110 +57,173 @@
this.lockMode = lockMode;
}
+ private LockMode lockMode = LockMode.NONE;
+
/**
- * Get the lock mode.
- * @return the lock mode.
+ * Retrieve the overall lock mode in effect for this set of options.
+ * <p/>
+ * In certain contexts (hql and criteria), lock-modes can be defined in an
+ * even more granular {@link #setAliasSpecificLockMode(String, LockMode) per-alias} fashion
+ *
+ * @return The overall lock mode.
*/
public LockMode getLockMode() {
return lockMode;
}
/**
- * Specify the LockMode to be used. The default is LockMode.none.
+ * Set the overall {@link LockMode} to be used. The default is
+ * {@link LockMode#NONE}
*
- * @param lockMode
- * @return this LockRequest instance for operation chaining.
+ * @param lockMode The new overall lock mode to use.
+ *
+ * @return this (for method chaining).
*/
public LockOptions setLockMode(LockMode lockMode) {
this.lockMode = lockMode;
return this;
}
+ private Map aliasSpecificLockModes = new HashMap();
+
/**
- * Specify the LockMode to be used for the specified alias.
+ * Specify the {@link LockMode} to be used for a specific query alias.
*
- * The ability to set the lockMode for a table alias is intended
- * for internal Hibernate use.
- *
- * @param lockMode
* @param alias used to reference the LockMode.
+ * @param lockMode The lock mode to apply to the given alias
* @return this LockRequest instance for operation chaining.
+ *
+ * @see Query#setLockMode(String, LockMode)
+ * @see Criteria#setLockMode(LockMode)
+ * @see Criteria#setLockMode(String, LockMode)
*/
- public LockOptions setAliasLockMode(LockMode lockMode, String alias) {
- lockModesByName.put(alias, lockMode);
+ public LockOptions setAliasSpecificLockMode(String alias, LockMode lockMode) {
+ aliasSpecificLockModes.put( alias, lockMode );
return this;
}
/**
- * Get the lock mode for the specified alias.
+ * Get the {@link LockMode} explicitly specified for the given alias via
+ * {@link #setAliasSpecificLockMode}
+ * <p/>
+ * Differs from {@link #getEffectiveLockMode} in that here we only return
+ * explicitly specified alias-specific lock modes.
*
- * @param alias used to reference the LockMode.
- * @return the lock mode.
+ * @param alias The alias for which to locate the explicit lock mode.
+ *
+ * @return The explicit lock mode for that alias.
*/
- public LockMode getAliasLockMode(String alias) {
- return (LockMode)lockModesByName.get(alias);
+ public LockMode getAliasSpecificLockMode(String alias) {
+ return (LockMode) aliasSpecificLockModes.get( alias );
}
/**
- * Get the number of aliases that have LockModes specified
+ * Determine the {@link LockMode} to apply to the given alias. If no
+ * mode was explicitly {@link #setAliasSpecificLockMode set}, the
+ * {@link #getLockMode overall mode} is returned. If the overall lock mode is
+ * <tt>null</tt> as well, {@link LockMode#NONE} is returned.
+ * <p/>
+ * Differs from {@link #getAliasSpecificLockMode} in that here we fallback to we only return
+ * the overall lock mode.
*
- * @return the number of aliases
+ * @param alias The alias for which to locate the effective lock mode.
+ *
+ * @return The effective lock mode.
*/
+ public LockMode getEffectiveLockMode(String alias) {
+ LockMode lockMode = getAliasSpecificLockMode( alias );
+ if ( lockMode == null ) {
+ lockMode = this.lockMode;
+ }
+ return lockMode == null ? LockMode.NONE : lockMode;
+ }
+
+ /**
+ * Get the number of aliases that have specific lock modes defined.
+ *
+ * @return the number of explicitly defined alias lock modes.
+ */
public int getAliasLockCount() {
- return lockModesByName.size();
+ return aliasSpecificLockModes.size();
}
/**
* Iterator for accessing Alias (key) and LockMode (value) as Map.Entry
- *
+ *
* @return Iterator for accessing the Map.Entry's
*/
public Iterator getAliasLockIterator() {
- return lockModesByName.entrySet().iterator();
+ return aliasSpecificLockModes.entrySet().iterator();
}
/**
- * Get the timeout setting.
+ * Indicates that the database should not wait at all to acquire the pessimistic lock.
+ * @see #getTimeOut
+ */
+ public static final int NO_WAIT = 0;
+ /**
+ * Indicates that there is no timeout for the acquisition.
+ * @see #getTimeOut
+ */
+ public static final int WAIT_FOREVER = -1;
+
+ private int timeout = WAIT_FOREVER;
+
+ /**
+ * Retrieve the current timeout setting.
+ * <p/>
+ * The timeout is the amount of time, in milliseconds, we should instruct the database
+ * to wait for any requested pessimistic lock acquisition.
+ * <p/>
+ * {@link #NO_WAIT} and {@link #WAIT_FOREVER} represent 2 "magic" values.
*
- * @return timeout in milliseconds, -1 for indefinite wait and 0 for no wait.
+ * @return timeout in milliseconds, or {@link #NO_WAIT} or {@link #WAIT_FOREVER}
*/
public int getTimeOut() {
return timeout;
}
/**
- * Specify the pessimistic lock timeout (check if your dialect supports this option).
- * The default pessimistic lock behavior is to wait forever for the lock.
+ * Set the timeout setting.
+ * <p/>
+ * See {@link #getTimeOut} for a discussion of meaning.
*
- * @param timeout is time in milliseconds to wait for lock. -1 means wait forever and 0 means no wait.
- * @return this LockRequest instance for operation chaining.
+ * @param timeout The new timeout setting.
+ *
+ * @return this (for method chaining).
+ *
+ * @see #getTimeOut
*/
public LockOptions setTimeOut(int timeout) {
this.timeout = timeout;
return this;
}
+ private boolean scope=false;
+
/**
- * Check if locking is cascaded to owned collections and relationships.
- * @return true if locking will be extended to owned collections and relationships.
+ * Retrieve the current lock scope setting.
+ * <p/>
+ * "scope" is a JPA defined term. It is basically a cascading of the lock to associations.
+ *
+ * @return true if locking will be extended to owned associations
*/
public boolean getScope() {
return scope;
}
/**
- * Specify if LockMode should be cascaded to owned collections and relationships.
- * The association must be mapped with <tt>cascade="lock" for scope=true to work.
+ * Set the cope.
*
- * @param scope
- * @return
+ * @param scope The new scope setting
+ *
+ * @return this (for method chaining).
*/
public LockOptions setScope(boolean scope) {
this.scope = scope;
return this;
}
-
/**
* Shallow copy From to Dest
*
@@ -190,7 +235,7 @@
dest.setLockMode(from.getLockMode());
dest.setScope(from.getScope());
dest.setTimeOut(from.getTimeOut());
- dest.lockModesByName = new HashMap(from.lockModesByName);
+ dest.aliasSpecificLockModes = new HashMap(from.aliasSpecificLockModes );
return dest;
}
}
Modified: core/trunk/core/src/main/java/org/hibernate/hql/classic/QueryTranslatorImpl.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/hql/classic/QueryTranslatorImpl.java 2010-01-31 21:50:23 UTC (rev 18674)
+++ core/trunk/core/src/main/java/org/hibernate/hql/classic/QueryTranslatorImpl.java 2010-02-01 19:42:16 UTC (rev 18675)
@@ -1080,7 +1080,7 @@
Iterator iter = lockOptions.getAliasLockIterator();
while ( iter.hasNext() ) {
Map.Entry me = ( Map.Entry ) iter.next();
- locks.setAliasLockMode( (LockMode) me.getValue(), getAliasName( ( String ) me.getKey() ) );
+ locks.setAliasSpecificLockMode( getAliasName( ( String ) me.getKey() ), (LockMode) me.getValue() );
}
Map keyColumnNames = null;
if ( dialect.forUpdateOfColumns() ) {
Modified: core/trunk/core/src/main/java/org/hibernate/id/enhanced/TableGenerator.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/id/enhanced/TableGenerator.java 2010-01-31 21:50:23 UTC (rev 18674)
+++ core/trunk/core/src/main/java/org/hibernate/id/enhanced/TableGenerator.java 2010-02-01 19:42:16 UTC (rev 18675)
@@ -429,7 +429,7 @@
" from " + tableName + ' ' + alias +
" where " + StringHelper.qualify( alias, segmentColumnName ) + "=?";
LockOptions lockOptions = new LockOptions(LockMode.UPGRADE);
- lockOptions.setAliasLockMode(LockMode.UPGRADE, alias);
+ lockOptions.setAliasSpecificLockMode( alias, LockMode.UPGRADE );
Map updateTargetColumnsMap = Collections.singletonMap( alias, new String[] { valueColumnName } );
return dialect.applyLocksToSql( query, lockOptions, updateTargetColumnsMap );
}
Modified: core/trunk/core/src/main/java/org/hibernate/impl/AbstractQueryImpl.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/impl/AbstractQueryImpl.java 2010-01-31 21:50:23 UTC (rev 18674)
+++ core/trunk/core/src/main/java/org/hibernate/impl/AbstractQueryImpl.java 2010-02-01 19:42:16 UTC (rev 18675)
@@ -241,7 +241,7 @@
return session;
}
- protected abstract LockOptions getLockOptions();
+ public abstract LockOptions getLockOptions();
// Parameter handling code ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Modified: core/trunk/core/src/main/java/org/hibernate/impl/QueryImpl.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/impl/QueryImpl.java 2010-01-31 21:50:23 UTC (rev 18674)
+++ core/trunk/core/src/main/java/org/hibernate/impl/QueryImpl.java 2010-02-01 19:42:16 UTC (rev 18675)
@@ -125,7 +125,7 @@
}
public Query setLockMode(String alias, LockMode lockMode) {
- lockOptions.setAliasLockMode(lockMode, alias);
+ lockOptions.setAliasSpecificLockMode( alias, lockMode );
return this;
}
@@ -136,7 +136,7 @@
return this;
}
- protected LockOptions getLockOptions() {
+ public LockOptions getLockOptions() {
return lockOptions;
}
Modified: core/trunk/core/src/main/java/org/hibernate/loader/criteria/CriteriaLoader.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/loader/criteria/CriteriaLoader.java 2010-01-31 21:50:23 UTC (rev 18674)
+++ core/trunk/core/src/main/java/org/hibernate/loader/criteria/CriteriaLoader.java 2010-02-01 19:42:16 UTC (rev 18675)
@@ -157,11 +157,11 @@
final Map keyColumnNames = dialect.forUpdateOfColumns() ? new HashMap() : null;
final String[] drivingSqlAliases = getAliases();
for ( int i = 0; i < drivingSqlAliases.length; i++ ) {
- final LockMode lockMode = lockOptions.getAliasLockMode( drivingSqlAliases[i] );
+ final LockMode lockMode = lockOptions.getAliasSpecificLockMode( drivingSqlAliases[i] );
if ( lockMode != null ) {
final Lockable drivingPersister = ( Lockable ) getEntityPersisters()[i];
final String rootSqlAlias = drivingPersister.getRootTableAlias( drivingSqlAliases[i] );
- locks.setAliasLockMode(lockMode, rootSqlAlias);
+ locks.setAliasSpecificLockMode( rootSqlAlias, lockMode );
if ( keyColumnNames != null ) {
keyColumnNames.put( rootSqlAlias, drivingPersister.getRootTableIdentifierColumnNames() );
}
@@ -178,7 +178,7 @@
final int size = entityAliases.length;
LockMode[] lockModesArray = new LockMode[size];
for ( int i=0; i<size; i++ ) {
- LockMode lockMode = lockOptions.getAliasLockMode( entityAliases[i] );
+ LockMode lockMode = lockOptions.getAliasSpecificLockMode( entityAliases[i] );
lockModesArray[i] = lockMode==null ? lockOptions.getLockMode() : lockMode;
}
return lockModesArray;
Modified: core/trunk/core/src/main/java/org/hibernate/loader/criteria/CriteriaQueryTranslator.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/loader/criteria/CriteriaQueryTranslator.java 2010-01-31 21:50:23 UTC (rev 18674)
+++ core/trunk/core/src/main/java/org/hibernate/loader/criteria/CriteriaQueryTranslator.java 2010-02-01 19:42:16 UTC (rev 18675)
@@ -284,7 +284,7 @@
while ( iter.hasNext() ) {
Map.Entry me = ( Map.Entry ) iter.next();
final Criteria subcriteria = getAliasedCriteria( ( String ) me.getKey() );
- lockOptions.setAliasLockMode( (LockMode)me.getValue(), getSQLAlias( subcriteria ) );
+ lockOptions.setAliasSpecificLockMode( getSQLAlias( subcriteria ), (LockMode)me.getValue() );
}
List values = new ArrayList();
List types = new ArrayList();
@@ -293,7 +293,7 @@
CriteriaImpl.Subcriteria subcriteria = ( CriteriaImpl.Subcriteria ) iter.next();
LockMode lm = subcriteria.getLockMode();
if ( lm != null ) {
- lockOptions.setAliasLockMode( lm, getSQLAlias( subcriteria ) );
+ lockOptions.setAliasSpecificLockMode( getSQLAlias( subcriteria ), lm );
}
if ( subcriteria.getWithClause() != null )
{
Modified: core/trunk/core/src/main/java/org/hibernate/loader/hql/QueryLoader.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/loader/hql/QueryLoader.java 2010-01-31 21:50:23 UTC (rev 18674)
+++ core/trunk/core/src/main/java/org/hibernate/loader/hql/QueryLoader.java 2010-02-01 19:42:16 UTC (rev 18675)
@@ -28,6 +28,7 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -292,10 +293,10 @@
LockMode[] lockModesArray = new LockMode[entityAliases.length];
for ( int i = 0; i < entityAliases.length; i++ ) {
- LockMode lockMode = lockOptions.getAliasLockMode( entityAliases[i] );
+ LockMode lockMode = lockOptions.getEffectiveLockMode( entityAliases[i] );
if ( lockMode == null ) {
//NONE, because its the requested lock mode, not the actual!
- lockMode = lockOptions.getLockMode();
+ lockMode = LockMode.NONE;
}
lockModesArray[i] = lockMode;
}
@@ -312,16 +313,16 @@
// can't cache this stuff either (per-invocation)
// we are given a map of user-alias -> lock mode
// create a new map of sql-alias -> lock mode
- final LockOptions locks = new LockOptions(lockOptions.getLockMode());
- locks.setScope( lockOptions.getScope());
- locks.setTimeOut( lockOptions.getTimeOut());
+ final LockOptions locks = new LockOptions( lockOptions.getLockMode() );
+ locks.setScope( lockOptions.getScope() );
+ locks.setTimeOut( lockOptions.getTimeOut() );
final Map keyColumnNames = dialect.forUpdateOfColumns() ? new HashMap() : null;
- final Iterator iter = lockOptions.getAliasLockIterator();
- while ( iter.hasNext() ) {
- Map.Entry me = ( Map.Entry ) iter.next();
- final String userAlias = ( String ) me.getKey();
- final String drivingSqlAlias = ( String ) sqlAliasByEntityAlias.get( userAlias );
+ final Iterator itr = sqlAliasByEntityAlias.entrySet().iterator();
+ while ( itr.hasNext() ) {
+ final Map.Entry entry = (Map.Entry) itr.next();
+ final String userAlias = (String) entry.getKey();
+ final String drivingSqlAlias = (String) entry.getValue();
if ( drivingSqlAlias == null ) {
throw new IllegalArgumentException( "could not locate alias to apply lock mode : " + userAlias );
}
@@ -334,11 +335,15 @@
final QueryNode select = ( QueryNode ) queryTranslator.getSqlAST();
final Lockable drivingPersister = ( Lockable ) select.getFromClause().getFromElement( userAlias ).getQueryable();
final String sqlAlias = drivingPersister.getRootTableAlias( drivingSqlAlias );
- locks.setAliasLockMode( (LockMode)me.getValue(), sqlAlias);
+
+ final LockMode effectiveLockMode = lockOptions.getEffectiveLockMode( userAlias );
+ locks.setAliasSpecificLockMode( sqlAlias, effectiveLockMode );
+
if ( keyColumnNames != null ) {
keyColumnNames.put( sqlAlias, drivingPersister.getRootTableIdentifierColumnNames() );
}
}
+
return dialect.applyLocksToSql( sql, locks, keyColumnNames );
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AbstractEntityManagerImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AbstractEntityManagerImpl.java 2010-01-31 21:50:23 UTC (rev 18674)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AbstractEntityManagerImpl.java 2010-02-01 19:42:16 UTC (rev 18675)
@@ -92,6 +92,7 @@
import org.hibernate.ejb.transaction.JoinableCMTTransaction;
import org.hibernate.ejb.util.CacheModeHelper;
import org.hibernate.ejb.util.ConfigurationHelper;
+import org.hibernate.ejb.util.LockModeTypeHelper;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.proxy.HibernateProxy;
@@ -851,52 +852,13 @@
@SuppressWarnings("deprecation")
private static LockModeType getLockModeType(LockMode lockMode) {
- if ( lockMode == LockMode.NONE )
- return LockModeType.NONE;
- else if ( lockMode == LockMode.OPTIMISTIC || lockMode == LockMode.READ )
- return LockModeType.OPTIMISTIC;
- else if ( lockMode == LockMode.OPTIMISTIC_FORCE_INCREMENT || lockMode == LockMode.WRITE )
- return LockModeType.OPTIMISTIC_FORCE_INCREMENT;
- else if ( lockMode == LockMode.PESSIMISTIC_READ )
- return LockModeType.PESSIMISTIC_READ;
- else if ( lockMode == LockMode.PESSIMISTIC_WRITE
- || lockMode == LockMode.UPGRADE
- || lockMode == LockMode.UPGRADE_NOWAIT) //timeout of 0
- //TODO check that if we have UPGRADE_NOWAIT we have a timeout of zero?
- return LockModeType.PESSIMISTIC_WRITE;
- else if ( lockMode == LockMode.PESSIMISTIC_FORCE_INCREMENT
- || lockMode == LockMode.FORCE)
- return LockModeType.PESSIMISTIC_FORCE_INCREMENT;
- throw new AssertionFailure("unhandled lock mode " + lockMode );
+ //TODO check that if we have UPGRADE_NOWAIT we have a timeout of zero?
+ return LockModeTypeHelper.getLockModeType( lockMode );
}
private static LockMode getLockMode(LockModeType lockMode) {
- switch ( lockMode ) {
-
- case READ:
- case OPTIMISTIC:
- return LockMode.OPTIMISTIC;
-
- case OPTIMISTIC_FORCE_INCREMENT:
- case WRITE:
- return LockMode.OPTIMISTIC_FORCE_INCREMENT;
-
- case PESSIMISTIC_READ:
- return LockMode.PESSIMISTIC_READ;
-
- case PESSIMISTIC_WRITE:
- return LockMode.PESSIMISTIC_WRITE;
-
- case PESSIMISTIC_FORCE_INCREMENT:
- return LockMode.PESSIMISTIC_FORCE_INCREMENT;
-
- case NONE:
- return LockMode.NONE;
-
- default:
- throw new AssertionFailure( "Unknown LockModeType: " + lockMode );
- }
+ return LockModeTypeHelper.getLockMode( lockMode );
}
public boolean isTransactionInProgress() {
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AbstractQueryImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AbstractQueryImpl.java 2010-01-31 21:50:23 UTC (rev 18674)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AbstractQueryImpl.java 2010-02-01 19:42:16 UTC (rev 18675)
@@ -40,6 +40,7 @@
import org.hibernate.CacheMode;
import org.hibernate.FlushMode;
import org.hibernate.HibernateException;
+import org.hibernate.LockMode;
import org.hibernate.TypeMismatchException;
import static org.hibernate.ejb.QueryHints.HINT_CACHEABLE;
import static org.hibernate.ejb.QueryHints.HINT_CACHE_MODE;
@@ -52,6 +53,7 @@
import org.hibernate.ejb.util.CacheModeHelper;
import org.hibernate.ejb.util.ConfigurationHelper;
+import org.hibernate.ejb.util.LockModeTypeHelper;
import org.hibernate.hql.QueryExecutionRequestException;
/**
@@ -189,6 +191,10 @@
protected abstract void applyFlushMode(FlushMode flushMode);
+ protected abstract boolean canApplyLockModes();
+
+ protected abstract void applyAliasSpecificLockMode(String alias, LockMode lockMode);
+
/**
* {@inheritDoc}
*/
@@ -247,10 +253,24 @@
CacheModeHelper.interpretCacheMode( storeMode, retrieveMode )
);
}
- /* TODO:
- else if ( "org.hibernate.lockMode".equals( hintName ) ) {
- query.setAliasLockMode( alias, lockMode );
- }*/
+ else if ( hintName.startsWith( AvailableSettings.ALIAS_SPECIFIC_LOCK_MODE ) ) {
+ if ( ! canApplyLockModes() ) {
+ skipped = true;
+ }
+ else {
+ // extract the alias
+ final String alias = hintName.substring( AvailableSettings.ALIAS_SPECIFIC_LOCK_MODE.length() );
+ // determine the LockMode
+ try {
+ final LockMode lockMode = LockModeTypeHelper.interpretLockMode( value );
+ applyAliasSpecificLockMode( alias, lockMode );
+ }
+ catch ( Exception e ) {
+ log.info( "Unable to determine lock mode value : {} -> {}", hintName, value );
+ skipped = true;
+ }
+ }
+ }
else {
skipped = true;
log.info( "Ignoring unrecognized query hint [" + hintName + "]" );
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AvailableSettings.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AvailableSettings.java 2010-01-31 21:50:23 UTC (rev 18674)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AvailableSettings.java 2010-02-01 19:42:16 UTC (rev 18675)
@@ -192,6 +192,20 @@
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
+ * Query hint (aka {@link javax.persistence.Query#setHint}) for applying
+ * an alias specific lock mode (aka {@link org.hibernate.Query#setLockMode}).
+ * <p/>
+ * Either {@link org.hibernate.LockMode} or {@link javax.persistence.LockModeType}
+ * are accepted. Also the String names of either are accepted as well. <tt>null</tt>
+ * is additionally accepted as meaning {@link org.hibernate.LockMode#NONE}.
+ * <p/>
+ * Usage is to concatenate this setting name and the alias name together, separated
+ * by a dot. For example<code>Query.setHint( "org.hibernate.lockMode.a", someLockMode )</code>
+ * would apply <code>someLockMode</code> to the alias <code>"a"</code>.
+ */
+ public static final String ALIAS_SPECIFIC_LOCK_MODE = "org.hibernate.lockMode";
+
+ /**
* JAR autodetection artifacts class, hbm
*/
public static final String AUTODETECTION = "hibernate.archive.autodetection";
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernateEntityManagerImplementor.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernateEntityManagerImplementor.java 2010-01-31 21:50:23 UTC (rev 18674)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernateEntityManagerImplementor.java 2010-02-01 19:42:16 UTC (rev 18675)
@@ -107,7 +107,7 @@
public PersistenceException wrapStaleStateException(StaleStateException e);
/**
- * Convert from JPA-2 LockModeType & properties into LockOptions
+ * Convert from JPA 2 {@link LockModeType} & properties into {@link LockOptions}
*
* @param lockModeType is the requested lock type
* @param properties are the lock properties
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/QueryImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/QueryImpl.java 2010-01-31 21:50:23 UTC (rev 18674)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/QueryImpl.java 2010-02-01 19:42:16 UTC (rev 18675)
@@ -50,10 +50,11 @@
import org.hibernate.CacheMode;
import org.hibernate.FlushMode;
import org.hibernate.HibernateException;
+import org.hibernate.LockMode;
import org.hibernate.QueryParameterException;
import org.hibernate.TypeMismatchException;
import org.hibernate.SQLQuery;
-import org.hibernate.LockOptions;
+import org.hibernate.ejb.util.LockModeTypeHelper;
import org.hibernate.engine.query.NamedParameterDescriptor;
import org.hibernate.engine.query.OrdinalParameterDescriptor;
import org.hibernate.hql.QueryExecutionRequestException;
@@ -217,6 +218,15 @@
query.setFlushMode( flushMode );
}
+ protected boolean canApplyLockModes() {
+ return org.hibernate.impl.QueryImpl.class.isInstance( query );
+ }
+
+ @Override
+ protected void applyAliasSpecificLockMode(String alias, LockMode lockMode) {
+ ( (org.hibernate.impl.QueryImpl) query ).getLockOptions().setAliasSpecificLockMode( alias, lockMode );
+ }
+
/**
* {@inheritDoc}
*/
@@ -590,13 +600,16 @@
@SuppressWarnings({ "unchecked" })
public TypedQuery<X> setLockMode(javax.persistence.LockModeType lockModeType) {
-
if (! getEntityManager().isTransactionInProgress()) {
throw new TransactionRequiredException( "no transaction is in progress" );
}
-
+ if ( ! canApplyLockModes() ) {
+ throw new IllegalStateException( "Not a JPAQL/Criteria query" );
+ }
this.jpaLockMode = lockModeType;
- query.setLockOptions(getEntityManager().getLockRequest(lockModeType, null));
+ ( (org.hibernate.impl.QueryImpl) query ).getLockOptions().setLockMode(
+ LockModeTypeHelper.getLockMode( lockModeType )
+ );
return this;
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/util/CacheModeHelper.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/util/CacheModeHelper.java 2010-01-31 21:50:23 UTC (rev 18674)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/util/CacheModeHelper.java 2010-02-01 19:42:16 UTC (rev 18675)
@@ -29,7 +29,8 @@
import org.hibernate.CacheMode;
/**
- * TODO : javadoc
+ * Helper to deal with {@link CacheMode} <-> {@link CacheRetrieveMode}/{@link CacheStoreMode}
+ * conversions.
*
* @author Steve Ebersole
*/
Added: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/util/LockModeTypeHelper.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/util/LockModeTypeHelper.java (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/util/LockModeTypeHelper.java 2010-02-01 19:42:16 UTC (rev 18675)
@@ -0,0 +1,119 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.ejb.util;
+
+import javax.persistence.LockModeType;
+
+import org.hibernate.AssertionFailure;
+import org.hibernate.LockMode;
+
+/**
+ * Helper to deal with {@link LockModeType} <-> {@link LockMode} conversions.
+ *
+ * @author Steve Ebersole
+ */
+public class LockModeTypeHelper {
+ public static LockModeType getLockModeType(LockMode lockMode) {
+ if ( lockMode == LockMode.NONE ) {
+ return LockModeType.NONE;
+ }
+ else if ( lockMode == LockMode.OPTIMISTIC || lockMode == LockMode.READ ) {
+ return LockModeType.OPTIMISTIC;
+ }
+ else if ( lockMode == LockMode.OPTIMISTIC_FORCE_INCREMENT || lockMode == LockMode.WRITE ) {
+ return LockModeType.OPTIMISTIC_FORCE_INCREMENT;
+ }
+ else if ( lockMode == LockMode.PESSIMISTIC_READ ) {
+ return LockModeType.PESSIMISTIC_READ;
+ }
+ else if ( lockMode == LockMode.PESSIMISTIC_WRITE
+ || lockMode == LockMode.UPGRADE
+ || lockMode == LockMode.UPGRADE_NOWAIT ) {
+ return LockModeType.PESSIMISTIC_WRITE;
+ }
+ else if ( lockMode == LockMode.PESSIMISTIC_FORCE_INCREMENT
+ || lockMode == LockMode.FORCE ) {
+ return LockModeType.PESSIMISTIC_FORCE_INCREMENT;
+ }
+ throw new AssertionFailure( "unhandled lock mode " + lockMode );
+ }
+
+
+ public static LockMode getLockMode(LockModeType lockMode) {
+ switch ( lockMode ) {
+ case READ:
+ case OPTIMISTIC: {
+ return LockMode.OPTIMISTIC;
+ }
+ case OPTIMISTIC_FORCE_INCREMENT:
+ case WRITE: {
+ return LockMode.OPTIMISTIC_FORCE_INCREMENT;
+ }
+ case PESSIMISTIC_READ: {
+ return LockMode.PESSIMISTIC_READ;
+ }
+ case PESSIMISTIC_WRITE: {
+ return LockMode.PESSIMISTIC_WRITE;
+ }
+ case PESSIMISTIC_FORCE_INCREMENT: {
+ return LockMode.PESSIMISTIC_FORCE_INCREMENT;
+ }
+ case NONE: {
+ return LockMode.NONE;
+ }
+ default: {
+ throw new AssertionFailure( "Unknown LockModeType: " + lockMode );
+ }
+ }
+ }
+
+ public static LockMode interpretLockMode(Object value) {
+ if ( value == null ) {
+ return LockMode.NONE;
+ }
+ if ( LockMode.class.isInstance( value ) ) {
+ return (LockMode) value;
+ }
+ else if ( LockModeType.class.isInstance( value ) ) {
+ return getLockMode( (LockModeType) value );
+ }
+ else if ( String.class.isInstance( value ) ) {
+ // first try LockMode name
+ LockMode lockMode = LockMode.parse( (String) value );
+ if ( lockMode == null ) {
+ try {
+ lockMode = getLockMode( LockModeType.valueOf( (String) value ) );
+ }
+ catch ( Exception ignore ) {
+ }
+ }
+ if ( lockMode != null ) {
+ return lockMode;
+ }
+ }
+
+ throw new IllegalArgumentException( "Unknown lock mode source : " + value );
+ }
+
+}
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/dialect/unit/lockhint/AbstractLockHintTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/dialect/unit/lockhint/AbstractLockHintTest.java 2010-01-31 21:50:23 UTC (rev 18674)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/dialect/unit/lockhint/AbstractLockHintTest.java 2010-02-01 19:42:16 UTC (rev 18675)
@@ -56,7 +56,7 @@
public void verify() {
LockOptions lockOptions = new LockOptions(LockMode.UPGRADE);
- lockOptions.setAliasLockMode(LockMode.UPGRADE, aliasToLock);
+ lockOptions.setAliasSpecificLockMode( aliasToLock, LockMode.UPGRADE );
String actualProcessedSql = dialect.applyLocksToSql( rawSql, lockOptions, Collections.EMPTY_MAP );
assertEquals( expectedProcessedSql, actualProcessedSql );
}
14 years, 12 months