HHH-5375 - Move AnnotationConfiguration-added methods to Configuration and deprecate AnnotationConfiguration
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@19944 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
29c16a5ff3
commit
f49096641f
|
@ -87,7 +87,6 @@ import org.hibernate.event.EventListeners;
|
|||
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 @@ public class AnnotationConfiguration extends Configuration {
|
|||
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 class AnnotationConfiguration extends Configuration {
|
|||
}
|
||||
|
||||
public ExtendedMappings createExtendedMappings() {
|
||||
return new ExtendedMappingsImpl( annotationConfiguredProfiles );
|
||||
return new ExtendedMappingsImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -310,7 +308,6 @@ public class AnnotationConfiguration extends Configuration {
|
|||
reflectionManager = new JavaReflectionManager();
|
||||
( ( MetadataProviderInjector ) reflectionManager ).setMetadataProvider( new JPAMetadataProvider() );
|
||||
configurationArtefactPrecedence = Collections.emptyList();
|
||||
annotationConfiguredProfiles = new HashSet<FetchProfile>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1257,11 +1254,6 @@ public class AnnotationConfiguration extends Configuration {
|
|||
|
||||
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 );
|
||||
|
@ -1531,24 +1523,6 @@ public class AnnotationConfiguration extends Configuration {
|
|||
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 {
|
||||
|
|
|
@ -118,6 +118,7 @@ import org.hibernate.mapping.ForeignKey;
|
|||
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 @@ public class Configuration implements Serializable {
|
|||
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;
|
||||
|
|
|
@ -208,9 +208,4 @@ public interface ExtendedMappings extends Mappings {
|
|||
|
||||
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);
|
||||
}
|
|
@ -66,6 +66,7 @@ import org.hibernate.mapping.List;
|
|||
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 @@ public final class HbmBinder {
|
|||
|
||||
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();
|
||||
|
|
|
@ -37,6 +37,7 @@ import org.hibernate.engine.NamedQueryDefinition;
|
|||
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 @@ public interface Mappings {
|
|||
* 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.
|
||||
|
|
|
@ -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 class VerifyFetchProfileReferenceSecondPass implements SecondPass {
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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.slf4j.LoggerFactory;
|
|||
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 @@ public class FetchProfile {
|
|||
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 @@ public class FetchProfile {
|
|||
* @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 @@ public class FetchProfile {
|
|||
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 @@ public class FetchProfile {
|
|||
}
|
||||
|
||||
/**
|
||||
* 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 @@ public class FetchProfile {
|
|||
*
|
||||
* @return Value for property 'containsJoinFetchedCollection'.
|
||||
*/
|
||||
@SuppressWarnings({ "UnusedDeclaration" })
|
||||
public boolean isContainsJoinFetchedCollection() {
|
||||
return containsJoinFetchedCollection;
|
||||
}
|
||||
|
@ -163,6 +164,7 @@ public class FetchProfile {
|
|||
*
|
||||
* @return Value for property 'containsJoinFetchedBag'.
|
||||
*/
|
||||
@SuppressWarnings({ "UnusedDeclaration" })
|
||||
public boolean isContainsJoinFetchedBag() {
|
||||
return containsJoinFetchedBag;
|
||||
}
|
||||
|
|
|
@ -26,32 +26,72 @@ package org.hibernate.mapping;
|
|||
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 @@ public class FetchProfile {
|
|||
FetchProfile that = ( FetchProfile ) o;
|
||||
|
||||
return name.equals( that.name );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public int hashCode() {
|
||||
return name.hashCode();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue