[hibernate-commits] Hibernate SVN: r19944 - in core/trunk/core/src/main/java/org/hibernate: engine/profile and 1 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Tue Jul 13 12:53:47 EDT 2010


Author: steve.ebersole at jboss.com
Date: 2010-07-13 12:53:46 -0400 (Tue, 13 Jul 2010)
New Revision: 19944

Added:
   core/trunk/core/src/main/java/org/hibernate/mapping/MetadataSource.java
Modified:
   core/trunk/core/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java
   core/trunk/core/src/main/java/org/hibernate/cfg/Configuration.java
   core/trunk/core/src/main/java/org/hibernate/cfg/ExtendedMappings.java
   core/trunk/core/src/main/java/org/hibernate/cfg/HbmBinder.java
   core/trunk/core/src/main/java/org/hibernate/cfg/Mappings.java
   core/trunk/core/src/main/java/org/hibernate/cfg/VerifyFetchProfileReferenceSecondPass.java
   core/trunk/core/src/main/java/org/hibernate/engine/profile/Association.java
   core/trunk/core/src/main/java/org/hibernate/engine/profile/Fetch.java
   core/trunk/core/src/main/java/org/hibernate/engine/profile/FetchProfile.java
   core/trunk/core/src/main/java/org/hibernate/mapping/FetchProfile.java
Log:
HHH-5375 - Move AnnotationConfiguration-added methods to Configuration and deprecate AnnotationConfiguration


Modified: core/trunk/core/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java	2010-07-13 15:06:59 UTC (rev 19943)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java	2010-07-13 16:53:46 UTC (rev 19944)
@@ -87,7 +87,6 @@
 import org.hibernate.event.PreInsertEventListener;
 import org.hibernate.event.PreUpdateEventListener;
 import org.hibernate.mapping.Column;
-import org.hibernate.mapping.FetchProfile;
 import org.hibernate.mapping.IdGenerator;
 import org.hibernate.mapping.Join;
 import org.hibernate.mapping.PersistentClass;
@@ -160,7 +159,6 @@
 	private boolean isValidatorNotPresentLogged;
 	private Map<XClass, Map<String, PropertyData>> propertiesAnnotatedWithMapsId;
 	private Map<XClass, Map<String, PropertyData>> propertiesAnnotatedWithIdAndToOne;
-	private Collection<FetchProfile> annotationConfiguredProfiles;
 
 	public AnnotationConfiguration() {
 		super();
@@ -267,7 +265,7 @@
 	}
 
 	public ExtendedMappings createExtendedMappings() {
-		return new ExtendedMappingsImpl( annotationConfiguredProfiles );
+		return new ExtendedMappingsImpl();
 	}
 
 	@Override
@@ -310,7 +308,6 @@
 		reflectionManager = new JavaReflectionManager();
 		( ( MetadataProviderInjector ) reflectionManager ).setMetadataProvider( new JPAMetadataProvider() );
 		configurationArtefactPrecedence = Collections.emptyList();
-		annotationConfiguredProfiles = new HashSet<FetchProfile>();
 	}
 
 	@Override
@@ -1257,12 +1254,7 @@
 
 	protected class ExtendedMappingsImpl extends MappingsImpl implements ExtendedMappings {
 		private Boolean useNewGeneratorMappings;
-		private Collection<FetchProfile> annotationConfiguredProfile;
 
-		public ExtendedMappingsImpl(Collection<FetchProfile> fetchProfiles) {
-			annotationConfiguredProfile = fetchProfiles;
-		}
-
 		public void addDefaultGenerator(IdGenerator generator) {
 			this.addGenerator( generator );
 			defaultNamedGenerators.add( generator.getName() );
@@ -1531,24 +1523,6 @@
 		public AnyMetaDef getAnyMetaDef(String name) {
 			return anyMetaDefs.get( name );
 		}
-
-		public FetchProfile findOrCreateFetchProfile(String name) {
-			FetchProfile profile = super.findOrCreateFetchProfile( name );
-			if ( profile.getFetches().isEmpty() ) {
-				annotationConfiguredProfile.add( profile );
-			}
-			return profile;
-		}
-
-		public boolean isAnnotationConfiguredFetchProfile(FetchProfile fetchProfile) {
-			for ( FetchProfile profile : annotationConfiguredProfile ) {
-				// we need reference equality there!!
-				if ( profile == fetchProfile ) {
-					return true;
-				}
-			}
-			return false;
-		}
 	}
 
 	private static class CacheHolder {

Modified: core/trunk/core/src/main/java/org/hibernate/cfg/Configuration.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cfg/Configuration.java	2010-07-13 15:06:59 UTC (rev 19943)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/Configuration.java	2010-07-13 16:53:46 UTC (rev 19944)
@@ -118,6 +118,7 @@
 import org.hibernate.mapping.IdentifierCollection;
 import org.hibernate.mapping.Index;
 import org.hibernate.mapping.MappedSuperclass;
+import org.hibernate.mapping.MetadataSource;
 import org.hibernate.mapping.PersistentClass;
 import org.hibernate.mapping.Property;
 import org.hibernate.mapping.RootClass;
@@ -2598,10 +2599,10 @@
 			filterDefinitions.put( definition.getFilterName(), definition );
 		}
 
-		public FetchProfile findOrCreateFetchProfile(String name) {
+		public FetchProfile findOrCreateFetchProfile(String name, MetadataSource source) {
 			FetchProfile profile = ( FetchProfile ) fetchProfiles.get( name );
 			if ( profile == null ) {
-				profile = new FetchProfile( name );
+				profile = new FetchProfile( name, source );
 				fetchProfiles.put( name, profile );
 			}
 			return profile;

Modified: core/trunk/core/src/main/java/org/hibernate/cfg/ExtendedMappings.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cfg/ExtendedMappings.java	2010-07-13 15:06:59 UTC (rev 19943)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/ExtendedMappings.java	2010-07-13 16:53:46 UTC (rev 19944)
@@ -208,9 +208,4 @@
 
 	void addToOneAndIdProperty(XClass entity, PropertyData property);
 
-	/**
-	 * @param fetchProfile The fetch profile to test.
-	 * @return {@code true} if the provided fetch profile has been configured via annotations, {@code false} otherwise.
-	 */
-	boolean isAnnotationConfiguredFetchProfile(FetchProfile fetchProfile);
 }
\ No newline at end of file

Modified: core/trunk/core/src/main/java/org/hibernate/cfg/HbmBinder.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cfg/HbmBinder.java	2010-07-13 15:06:59 UTC (rev 19943)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/HbmBinder.java	2010-07-13 16:53:46 UTC (rev 19944)
@@ -66,6 +66,7 @@
 import org.hibernate.mapping.ManyToOne;
 import org.hibernate.mapping.Map;
 import org.hibernate.mapping.MetaAttribute;
+import org.hibernate.mapping.MetadataSource;
 import org.hibernate.mapping.OneToMany;
 import org.hibernate.mapping.OneToOne;
 import org.hibernate.mapping.PersistentClass;
@@ -3033,7 +3034,7 @@
 
 	private static void parseFetchProfile(Element element, Mappings mappings, String containingEntityName) {
 		String profileName = element.attributeValue( "name" );
-		FetchProfile profile = mappings.findOrCreateFetchProfile( profileName );
+		FetchProfile profile = mappings.findOrCreateFetchProfile( profileName, MetadataSource.HBM );
 		Iterator itr = element.elementIterator( "fetch" );
 		while ( itr.hasNext() ) {
 			final Element fetchElement = ( Element ) itr.next();

Modified: core/trunk/core/src/main/java/org/hibernate/cfg/Mappings.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cfg/Mappings.java	2010-07-13 15:06:59 UTC (rev 19943)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/Mappings.java	2010-07-13 16:53:46 UTC (rev 19944)
@@ -37,6 +37,7 @@
 import org.hibernate.engine.NamedSQLQueryDefinition;
 import org.hibernate.engine.ResultSetMappingDefinition;
 import org.hibernate.mapping.Collection;
+import org.hibernate.mapping.MetadataSource;
 import org.hibernate.mapping.PersistentClass;
 import org.hibernate.mapping.Table;
 import org.hibernate.mapping.TypeDef;
@@ -390,9 +391,10 @@
 	 * or by creating one (and adding it).
 	 *
 	 * @param name The name of the profile.
+	 * @param source The source from which this profile is named.
 	 * @return The fetch profile metadata.
 	 */
-	public FetchProfile findOrCreateFetchProfile(String name);
+	public FetchProfile findOrCreateFetchProfile(String name, MetadataSource source);
 
 	/**
 	 * Retrieves an iterator over the metadata pertaining to all auxilary database objects int this repository.

Modified: core/trunk/core/src/main/java/org/hibernate/cfg/VerifyFetchProfileReferenceSecondPass.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cfg/VerifyFetchProfileReferenceSecondPass.java	2010-07-13 15:06:59 UTC (rev 19943)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/VerifyFetchProfileReferenceSecondPass.java	2010-07-13 16:53:46 UTC (rev 19944)
@@ -21,15 +21,13 @@
  * 51 Franklin Street, Fifth Floor
  * Boston, MA  02110-1301  USA
  */
-
-// $Id$
-
 package org.hibernate.cfg;
 
 import java.util.Map;
 
 import org.hibernate.MappingException;
 import org.hibernate.annotations.FetchProfile;
+import org.hibernate.mapping.MetadataSource;
 import org.hibernate.mapping.PersistentClass;
 
 /**
@@ -48,8 +46,11 @@
 	}
 
 	public void doSecondPass(Map persistentClasses) throws MappingException {
-		org.hibernate.mapping.FetchProfile profile = mappings.findOrCreateFetchProfile( fetchProfileName );
-		if ( !mappings.isAnnotationConfiguredFetchProfile( profile ) ) {
+		org.hibernate.mapping.FetchProfile profile = mappings.findOrCreateFetchProfile(
+				fetchProfileName,
+				MetadataSource.ANNOTATIONS
+		);
+		if ( MetadataSource.ANNOTATIONS != profile.getSource() ) {
 			return;
 		}
 

Modified: core/trunk/core/src/main/java/org/hibernate/engine/profile/Association.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/profile/Association.java	2010-07-13 15:06:59 UTC (rev 19943)
+++ core/trunk/core/src/main/java/org/hibernate/engine/profile/Association.java	2010-07-13 16:53:46 UTC (rev 19944)
@@ -1,10 +1,10 @@
 /*
  * Hibernate, Relational Persistence for Idiomatic Java
  *
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * 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 Middleware LLC.
+ * 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
@@ -20,7 +20,6 @@
  * Free Software Foundation, Inc.
  * 51 Franklin Street, Fifth Floor
  * Boston, MA  02110-1301  USA
- *
  */
 package org.hibernate.engine.profile;
 

Modified: core/trunk/core/src/main/java/org/hibernate/engine/profile/Fetch.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/profile/Fetch.java	2010-07-13 15:06:59 UTC (rev 19943)
+++ core/trunk/core/src/main/java/org/hibernate/engine/profile/Fetch.java	2010-07-13 16:53:46 UTC (rev 19944)
@@ -1,10 +1,10 @@
 /*
  * Hibernate, Relational Persistence for Idiomatic Java
  *
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * 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 Middleware LLC.
+ * 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
@@ -20,7 +20,6 @@
  * Free Software Foundation, Inc.
  * 51 Franklin Street, Fifth Floor
  * Boston, MA  02110-1301  USA
- *
  */
 package org.hibernate.engine.profile;
 

Modified: core/trunk/core/src/main/java/org/hibernate/engine/profile/FetchProfile.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/profile/FetchProfile.java	2010-07-13 15:06:59 UTC (rev 19943)
+++ core/trunk/core/src/main/java/org/hibernate/engine/profile/FetchProfile.java	2010-07-13 16:53:46 UTC (rev 19944)
@@ -1,10 +1,10 @@
 /*
  * Hibernate, Relational Persistence for Idiomatic Java
  *
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * 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 Middleware LLC.
+ * 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
@@ -20,7 +20,6 @@
  * Free Software Foundation, Inc.
  * 51 Franklin Street, Fifth Floor
  * Boston, MA  02110-1301  USA
- *
  */
 package org.hibernate.engine.profile;
 
@@ -33,12 +32,12 @@
 import org.hibernate.engine.SessionFactoryImplementor;
 import org.hibernate.type.Type;
 import org.hibernate.type.BagType;
-import org.hibernate.type.AssociationType;
 
 /**
- * A 'fetch profile' allows a user to dynamically modify the fetching
- * strategy used for particular associations at runtime, whereas that
- * information was historically only statically defined in the metadata.
+ * A 'fetch profile' allows a user to dynamically modify the fetching strategy used for particular associations at
+ * runtime, whereas that information was historically only statically defined in the metadata.
+ * <p/>
+ * This class defines the runtime representation of this data.
  *
  * @author Steve Ebersole
  */
@@ -46,7 +45,7 @@
 	private static final Logger log = LoggerFactory.getLogger( FetchProfile.class );
 
 	private final String name;
-	private Map fetches = new HashMap();
+	private Map<String,Fetch> fetches = new HashMap<String,Fetch>();
 
 	private boolean containsJoinFetchedCollection = false;
 	private boolean containsJoinFetchedBag = false;
@@ -70,6 +69,7 @@
 	 * @param association The association to be fetched
 	 * @param fetchStyleName The name of the fetch style to apply
 	 */
+	@SuppressWarnings({ "UnusedDeclaration" })
 	public void addFetch(Association association, String fetchStyleName) {
 		addFetch( association, Fetch.Style.parse( fetchStyleName ) );
 	}
@@ -94,7 +94,7 @@
 		if ( associationType.isCollectionType() ) {
 			log.trace( "handling request to add collection fetch [{}]", fetch.getAssociation().getRole() );
 
-			// couple of things for whcih to account in the case of collection
+			// couple of things for which to account in the case of collection
 			// join fetches
 			if ( Fetch.Style.JOIN == fetch.getStyle() ) {
 				// first, if this is a bag we need to ignore it if we previously
@@ -134,17 +134,17 @@
 	}
 
 	/**
-	 * Getter for property 'fetches'.  Map of {@link Fetch} instances,
-	 * keyed by associaion <tt>role</tt>
+	 * Getter for property 'fetches'.  Map of {@link Fetch} instances, keyed by association <tt>role</tt>
 	 *
 	 * @return Value for property 'fetches'.
 	 */
-	public Map getFetches() {
+	@SuppressWarnings({ "UnusedDeclaration" })
+	public Map<String,Fetch> getFetches() {
 		return fetches;
 	}
 
 	public Fetch getFetchByRole(String role) {
-		return ( Fetch ) fetches.get( role );
+		return fetches.get( role );
 	}
 
 	/**
@@ -153,6 +153,7 @@
 	 *
 	 * @return Value for property 'containsJoinFetchedCollection'.
 	 */
+	@SuppressWarnings({ "UnusedDeclaration" })
 	public boolean isContainsJoinFetchedCollection() {
 		return containsJoinFetchedCollection;
 	}
@@ -163,6 +164,7 @@
 	 *
 	 * @return Value for property 'containsJoinFetchedBag'.
 	 */
+	@SuppressWarnings({ "UnusedDeclaration" })
 	public boolean isContainsJoinFetchedBag() {
 		return containsJoinFetchedBag;
 	}

Modified: core/trunk/core/src/main/java/org/hibernate/mapping/FetchProfile.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/mapping/FetchProfile.java	2010-07-13 15:06:59 UTC (rev 19943)
+++ core/trunk/core/src/main/java/org/hibernate/mapping/FetchProfile.java	2010-07-13 16:53:46 UTC (rev 19944)
@@ -26,32 +26,72 @@
 import java.util.LinkedHashSet;
 
 /**
- * A fetch profile allows a user to dynamically modify the fetching
- * strategy used for particular associations at runtime, whereas that
- * information was historically only statically defined in the metadata.
+ * A fetch profile allows a user to dynamically modify the fetching strategy used for particular associations at
+ * runtime, whereas that information was historically only statically defined in the metadata.
+ * <p/>
+ * This class represent the data as it is defined in their metadata.
  *
  * @author Steve Ebersole
+ *
+ * @see org.hibernate.engine.profile.FetchProfile
  */
 public class FetchProfile {
 	private final String name;
-	private LinkedHashSet fetches = new LinkedHashSet();
+	private final MetadataSource source;
+	private LinkedHashSet<Fetch> fetches = new LinkedHashSet<Fetch>();
 
-	public FetchProfile(String name) {
+	/**
+	 * Create a fetch profile representation.
+	 *
+	 * @param name The name of the fetch profile.
+	 * @param source The source of the fetch profile (where was it defined).
+	 */
+	public FetchProfile(String name, MetadataSource source) {
 		this.name = name;
+		this.source = source;
 	}
 
+	/**
+	 * Retrieve the name of the fetch profile.
+	 *
+	 * @return The profile name
+	 */
 	public String getName() {
 		return name;
 	}
 
-	public LinkedHashSet getFetches() {
+	/**
+	 * Retrieve the fetch profile source.
+	 *
+	 * @return The profile source.
+	 */
+	public MetadataSource getSource() {
+		return source;
+	}
+
+	/**
+	 * Retrieve the fetches associated with this profile
+	 *
+	 * @return The fetches associated with this profile.
+	 */
+	public LinkedHashSet<Fetch> getFetches() {
 		return fetches;
 	}
 
+	/**
+	 * Adds a fetch to this profile.
+	 *
+	 * @param entity The entity which contains the association to be fetched
+	 * @param association The association to fetch
+	 * @param style The style of fetch t apply
+	 */
 	public void addFetch(String entity, String association, String style) {
 		fetches.add( new Fetch( entity, association, style ) );
 	}
 
+	/**
+	 * {@inheritDoc}
+	 */
 	public boolean equals(Object o) {
 		if ( this == o ) {
 			return true;
@@ -63,9 +103,11 @@
 		FetchProfile that = ( FetchProfile ) o;
 
 		return name.equals( that.name );
-
 	}
 
+	/**
+	 * {@inheritDoc}
+	 */
 	public int hashCode() {
 		return name.hashCode();
 	}

Added: core/trunk/core/src/main/java/org/hibernate/mapping/MetadataSource.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/mapping/MetadataSource.java	                        (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/mapping/MetadataSource.java	2010-07-13 16:53:46 UTC (rev 19944)
@@ -0,0 +1,35 @@
+/*
+ * 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.mapping;
+
+/**
+ * Enumeration of the known places from which a piece of metadata may come.
+ *
+ * @author Steve Ebersole
+ */
+public enum MetadataSource {
+	HBM,
+	ANNOTATIONS,
+	OTHER
+}



More information about the hibernate-commits mailing list