Author: hardy.ferentschik
Date: 2010-05-31 06:48:08 -0400 (Mon, 31 May 2010)
New Revision: 19634
Modified:
core/trunk/annotations/pom.xml
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/ExtendedMappings.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/VerifyFetchProfileReferenceSecondPass.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/MoreFetchProfileTest.java
Log:
HHH-5233 Fixed implementation for multiple fetch profiles overrides. Cleaned up pom.
Modified: core/trunk/annotations/pom.xml
===================================================================
--- core/trunk/annotations/pom.xml 2010-05-30 20:47:31 UTC (rev 19633)
+++ core/trunk/annotations/pom.xml 2010-05-31 10:48:08 UTC (rev 19634)
@@ -22,7 +22,9 @@
~ 51 Franklin Street, Fifth Floor
~ Boston, MA 02110-1301 USA
-->
-<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
@@ -44,7 +46,7 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
- <version>${version}</version>
+ <version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
@@ -54,12 +56,12 @@
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
</dependency>
- <dependency>
- <groupId>${groupId}</groupId>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
<artifactId>hibernate-testing</artifactId>
- <version>${version}</version>
- <scope>test</scope>
- </dependency>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
@@ -85,13 +87,6 @@
<build>
<testResources>
<testResource>
- <filtering>false</filtering>
- <directory>src/test/java</directory>
- <includes>
- <include>**/*.xml</include>
- </includes>
- </testResource>
- <testResource>
<filtering>true</filtering>
<directory>src/test/resources</directory>
</testResource>
@@ -116,17 +111,17 @@
<configuration>
<bytecodeInjections>
<bytecodeInjection>
- <expression>${pom.version}</expression>
+ <expression>${project.version}</expression>
<targetMembers>
- <methodBodyReturn>
-
<className>org.hibernate.cfg.annotations.Version</className>
- <methodName>getVersionString</methodName>
- </methodBodyReturn>
+ <methodBodyReturn>
+
<className>org.hibernate.cfg.annotations.Version</className>
+
<methodName>getVersionString</methodName>
+ </methodBodyReturn>
</targetMembers>
</bytecodeInjection>
</bytecodeInjections>
</configuration>
- </plugin>
+ </plugin>
<plugin>
<groupId>org.twdata.maven</groupId>
<artifactId>maven-cli-plugin</artifactId>
Modified:
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java
===================================================================
---
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java 2010-05-30
20:47:31 UTC (rev 19633)
+++
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java 2010-05-31
10:48:08 UTC (rev 19634)
@@ -163,6 +163,7 @@
private boolean isValidatorNotPresentLogged;
private Map<XClass, Map<String, PropertyData>>
propertiesAnnotatedWithMapsId;
private Map<XClass, Map<String, PropertyData>>
propertiesAnnotatedWithIdAndToOne;
+ private Collection<FetchProfile> annotationConfiguredProfiles;
public AnnotationConfiguration() {
super();
@@ -268,7 +269,7 @@
}
public ExtendedMappings createExtendedMappings() {
- return new ExtendedMappingsImpl();
+ return new ExtendedMappingsImpl( annotationConfiguredProfiles );
}
@Override
@@ -311,6 +312,7 @@
reflectionManager = new JavaReflectionManager();
( ( MetadataProviderInjector ) reflectionManager ).setMetadataProvider( new
JPAMetadataProvider() );
configurationArtefactPrecedence = Collections.emptyList();
+ annotationConfiguredProfiles = new HashSet<FetchProfile>();
}
@Override
@@ -1255,8 +1257,8 @@
private Boolean useNewGeneratorMappings;
private Collection<FetchProfile> annotationConfiguredProfile;
- public ExtendedMappingsImpl() {
- annotationConfiguredProfile = new ArrayList<FetchProfile>();
+ public ExtendedMappingsImpl(Collection<FetchProfile> fetchProfiles) {
+ annotationConfiguredProfile = fetchProfiles;
}
public void addDefaultGenerator(IdGenerator generator) {
@@ -1528,11 +1530,15 @@
return anyMetaDefs.get( name );
}
- public void addAnnotationConfiguredFetchProfile(FetchProfile fetchProfile) {
- annotationConfiguredProfile.add( fetchProfile );
+ public FetchProfile findOrCreateFetchProfile(String name) {
+ FetchProfile profile = super.findOrCreateFetchProfile( name );
+ if ( profile.getFetches().isEmpty() ) {
+ annotationConfiguredProfile.add( profile );
+ }
+ return profile;
}
- public boolean containsAnnotationConfiguredFetchProfile(FetchProfile fetchProfile) {
+ public boolean isAnnotationConfiguredFetchProfile(FetchProfile fetchProfile) {
for ( FetchProfile profile : annotationConfiguredProfile ) {
// we need reference equality there!!
if ( profile == fetchProfile ) {
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/ExtendedMappings.java
===================================================================
---
core/trunk/annotations/src/main/java/org/hibernate/cfg/ExtendedMappings.java 2010-05-30
20:47:31 UTC (rev 19633)
+++
core/trunk/annotations/src/main/java/org/hibernate/cfg/ExtendedMappings.java 2010-05-31
10:48:08 UTC (rev 19634)
@@ -1,4 +1,4 @@
-// $Id:$
+// $Id$
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
@@ -207,14 +207,8 @@
void addToOneAndIdProperty(XClass entity, PropertyData property);
/**
- * Add the specified profile to the list of fetch profiles configured via annotations.
- *
- * @param fetchProfile the fetch profile
+ * @param fetchProfile The fetch profile to test.
+ * @return {@code true} if the provided fetch profile has been configured via
annotations, {@code false} otherwise.
*/
- void addAnnotationConfiguredFetchProfile(FetchProfile fetchProfile);
-
- /**
- * @return {@true} if the provided fetch profile has been configured via xml, {@false
otherwise}.
- */
- boolean containsAnnotationConfiguredFetchProfile(FetchProfile fetchProfile);
+ boolean isAnnotationConfiguredFetchProfile(FetchProfile fetchProfile);
}
\ No newline at end of file
Modified:
core/trunk/annotations/src/main/java/org/hibernate/cfg/VerifyFetchProfileReferenceSecondPass.java
===================================================================
---
core/trunk/annotations/src/main/java/org/hibernate/cfg/VerifyFetchProfileReferenceSecondPass.java 2010-05-30
20:47:31 UTC (rev 19633)
+++
core/trunk/annotations/src/main/java/org/hibernate/cfg/VerifyFetchProfileReferenceSecondPass.java 2010-05-31
10:48:08 UTC (rev 19634)
@@ -1,4 +1,4 @@
-// $Id:$
+// $Id$
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
@@ -47,7 +47,7 @@
public void doSecondPass(Map persistentClasses) throws MappingException {
org.hibernate.mapping.FetchProfile profile = mappings.findOrCreateFetchProfile(
fetchProfileName );
- if ( skipProfile( profile ) ) {
+ if ( !mappings.isAnnotationConfiguredFetchProfile( profile ) ) {
return;
}
@@ -59,15 +59,6 @@
fetch.entity().getName(), fetch.association(), fetch.mode().toString().toLowerCase()
);
}
-
- private boolean skipProfile(org.hibernate.mapping.FetchProfile profile) {
- if ( mappings.containsAnnotationConfiguredFetchProfile( profile ) ) {
- return false;
- }
-
- // if there are fetches they must come from xml. If there are xml profiles the
annotations get ignored
- return !profile.getFetches().isEmpty();
- }
}
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/MoreFetchProfileTest.java
===================================================================
---
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/MoreFetchProfileTest.java 2010-05-30
20:47:31 UTC (rev 19633)
+++
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/fetchprofile/MoreFetchProfileTest.java 2010-05-31
10:48:08 UTC (rev 19634)
@@ -1,3 +1,28 @@
+// $Id: FetchProfileTest.java 19528 2010-05-17 14:28:55Z epbernard $
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Middleware LLC 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 Middleware LLC.
+ *
+ * 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.test.annotations.fetchprofile;
import java.util.Date;
@@ -5,17 +30,16 @@
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.Transaction;
-import org.hibernate.junit.FailureExpected;
import org.hibernate.test.annotations.TestCase;
/**
* @author Emmanuel Bernard
+ * @author Hardy Ferentschik
*/
-public class MoreFetchProfileTest extends TestCase{
+public class MoreFetchProfileTest extends TestCase {
- @FailureExpected( jiraKey = "HHH-5233")
public void testFetchWithTwoOverrides() throws Exception {
- Session s = openSession( );
+ Session s = openSession();
s.enableFetchProfile( "customer-with-orders-and-country" );
final Transaction transaction = s.beginTransaction();
Country ctry = new Country();
@@ -43,10 +67,10 @@
s.clear();
- c = (Customer) s.get( Customer.class, c.getId() );
+ c = ( Customer ) s.get( Customer.class, c.getId() );
assertTrue( Hibernate.isInitialized( c.getLastOrder() ) );
assertTrue( Hibernate.isInitialized( c.getOrders() ) );
- for(Order so : c.getOrders() ) {
+ for ( Order so : c.getOrders() ) {
assertTrue( Hibernate.isInitialized( so.getCountry() ) );
}
final Order order = c.getOrders().iterator().next();
@@ -62,7 +86,7 @@
s.close();
}
-
+
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {