HHH-8722 HHH-8723 : Reorg AbstractLoadPlanBuildingAssociationVisitationStrategy and add Any support
This commit is contained in:
parent
9d8fa394e3
commit
ed4fafeb50
|
@ -89,6 +89,7 @@ public abstract class AbstractLoadPlanBuildingAssociationVisitationStrategy
|
|||
private final SessionFactoryImplementor sessionFactory;
|
||||
private final QuerySpacesImpl querySpaces;
|
||||
|
||||
//TODO: I don't see propertyPathStack used anywhere. Can it be deleted?
|
||||
private final PropertyPathStack propertyPathStack = new PropertyPathStack();
|
||||
|
||||
private final ArrayDeque<ExpandingFetchSource> fetchSourceStack = new ArrayDeque<ExpandingFetchSource>();
|
||||
|
@ -935,6 +936,8 @@ public abstract class AbstractLoadPlanBuildingAssociationVisitationStrategy
|
|||
* Maintains stack information for the property paths we are processing for logging purposes. Because of the
|
||||
* recursive calls it is often useful (while debugging) to be able to see the "property path" as part of the
|
||||
* logging output.
|
||||
*
|
||||
* TODO: I don't see PropertyPathStack used anywhere. Can it be deleted?
|
||||
*/
|
||||
public static class PropertyPathStack {
|
||||
private ArrayDeque<PropertyPath> pathStack = new ArrayDeque<PropertyPath>();
|
||||
|
|
|
@ -2012,8 +2012,8 @@ public abstract class AbstractCollectionPersister
|
|||
|
||||
@Override
|
||||
public EntityDefinition toEntityDefinition() {
|
||||
if ( getType().isComponentType() ) {
|
||||
throw new IllegalStateException( "Cannot treat composite collection index type as entity" );
|
||||
if ( !getType().isEntityType() ) {
|
||||
throw new IllegalStateException( "Cannot treat collection index type as entity" );
|
||||
}
|
||||
return (EntityPersister) ( (AssociationType) getIndexType() ).getAssociatedJoinable( getFactory() );
|
||||
}
|
||||
|
@ -2021,7 +2021,7 @@ public abstract class AbstractCollectionPersister
|
|||
@Override
|
||||
public CompositionDefinition toCompositeDefinition() {
|
||||
if ( ! getType().isComponentType() ) {
|
||||
throw new IllegalStateException( "Cannot treat entity collection index type as composite" );
|
||||
throw new IllegalStateException( "Cannot treat collection index type as composite" );
|
||||
}
|
||||
return new CompositeCollectionElementDefinition() {
|
||||
@Override
|
||||
|
@ -2056,6 +2056,15 @@ public abstract class AbstractCollectionPersister
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnyMappingDefinition toAnyMappingDefinition() {
|
||||
final Type type = getType();
|
||||
if ( ! type.isAnyType() ) {
|
||||
throw new IllegalStateException( "Cannot treat collection index type as ManyToAny" );
|
||||
}
|
||||
return new StandardAnyTypeDefinition( (AnyType) type, isLazy() || isExtraLazy() );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -2076,15 +2085,15 @@ public abstract class AbstractCollectionPersister
|
|||
public AnyMappingDefinition toAnyMappingDefinition() {
|
||||
final Type type = getType();
|
||||
if ( ! type.isAnyType() ) {
|
||||
throw new WalkingException( "Cannot treat collection element type as ManyToAny" );
|
||||
throw new IllegalStateException( "Cannot treat collection element type as ManyToAny" );
|
||||
}
|
||||
return new StandardAnyTypeDefinition( (AnyType) type, isLazy() || isExtraLazy() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityDefinition toEntityDefinition() {
|
||||
if ( getType().isComponentType() ) {
|
||||
throw new WalkingException( "Cannot treat composite collection element type as entity" );
|
||||
if ( !getType().isEntityType() ) {
|
||||
throw new IllegalStateException( "Cannot treat collection element type as entity" );
|
||||
}
|
||||
return getElementPersister();
|
||||
}
|
||||
|
@ -2093,7 +2102,7 @@ public abstract class AbstractCollectionPersister
|
|||
public CompositeCollectionElementDefinition toCompositeElementDefinition() {
|
||||
|
||||
if ( ! getType().isComponentType() ) {
|
||||
throw new WalkingException( "Cannot treat entity collection element type as composite" );
|
||||
throw new IllegalStateException( "Cannot treat entity collection element type as composite" );
|
||||
}
|
||||
|
||||
return new CompositeCollectionElementDefinition() {
|
||||
|
|
|
@ -46,15 +46,15 @@ public interface CollectionElementDefinition {
|
|||
|
||||
/**
|
||||
* If the element type returned by {@link #getType()} is an
|
||||
* {@link org.hibernate.type.EntityType}, then the entity
|
||||
* {@link org.hibernate.type.AnyType}, then the any mapping
|
||||
* definition for the collection element is returned;
|
||||
* otherwise, IllegalStateException is thrown.
|
||||
*
|
||||
* @return the entity definition for the collection element.
|
||||
* @return the any mapping definition for the collection element.
|
||||
*
|
||||
* @throws IllegalStateException if the collection element type
|
||||
* returned by {@link #getType()} is not of type
|
||||
* {@link org.hibernate.type.EntityType}.
|
||||
* {@link org.hibernate.type.AnyType}.
|
||||
*/
|
||||
public AnyMappingDefinition toAnyMappingDefinition();
|
||||
|
||||
|
|
|
@ -65,4 +65,18 @@ public interface CollectionIndexDefinition {
|
|||
* {@link org.hibernate.type.CompositeType}.
|
||||
*/
|
||||
public CompositionDefinition toCompositeDefinition();
|
||||
|
||||
/**
|
||||
* If the index type returned by {@link #getType()} is an
|
||||
* {@link org.hibernate.type.AnyType}, then the any mapping
|
||||
* definition for the collection index is returned;
|
||||
* otherwise, IllegalStateException is thrown.
|
||||
*
|
||||
* @return the any mapping definition for the collection index.
|
||||
*
|
||||
* @throws IllegalStateException if the collection index type
|
||||
* returned by {@link #getType()} is not of type
|
||||
* {@link org.hibernate.type.AnyType}.
|
||||
*/
|
||||
public AnyMappingDefinition toAnyMappingDefinition();
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ import org.hibernate.type.Type;
|
|||
* Implements metamodel graph walking. In layman terms, we are walking the graph of the users domain model as
|
||||
* defined/understood by mapped associations.
|
||||
* <p/>
|
||||
* Initially grew as a part of the re-implementation of the legacy JoinWalker functional to instead build LoadPlans.
|
||||
* Initially grew as a part of the re-implementation of the legacy JoinWalker functionality to instead build LoadPlans.
|
||||
* But this is really quite simple walking. Interesting events are handled by calling out to
|
||||
* implementations of {@link AssociationVisitationStrategy} which really provide the real functionality of what we do
|
||||
* as we walk.
|
||||
|
@ -240,7 +240,10 @@ public class MetamodelGraphWalker {
|
|||
|
||||
try {
|
||||
final Type collectionIndexType = collectionIndexDefinition.getType();
|
||||
if ( collectionIndexType.isComponentType() ) {
|
||||
if ( collectionIndexType.isAnyType() ) {
|
||||
visitAnyDefinition( collectionIndexDefinition.toAnyMappingDefinition() );
|
||||
}
|
||||
else if ( collectionIndexType.isComponentType() ) {
|
||||
visitCompositeDefinition( collectionIndexDefinition.toCompositeDefinition() );
|
||||
}
|
||||
else if ( collectionIndexType.isAssociationType() ) {
|
||||
|
@ -258,10 +261,14 @@ public class MetamodelGraphWalker {
|
|||
final CollectionElementDefinition elementDefinition = collectionDefinition.getElementDefinition();
|
||||
strategy.startingCollectionElements( elementDefinition );
|
||||
|
||||
if ( elementDefinition.getType().isComponentType() ) {
|
||||
final Type collectionElementType = elementDefinition.getType();
|
||||
if ( collectionElementType.isAnyType() ) {
|
||||
visitAnyDefinition( elementDefinition.toAnyMappingDefinition() );
|
||||
}
|
||||
else if ( collectionElementType.isComponentType() ) {
|
||||
visitCompositeDefinition( elementDefinition.toCompositeElementDefinition() );
|
||||
}
|
||||
else if ( elementDefinition.getType().isEntityType() ) {
|
||||
else if ( collectionElementType.isEntityType() ) {
|
||||
if ( ! collectionDefinition.getCollectionPersister().isOneToMany() ) {
|
||||
final QueryableCollection queryableCollection = (QueryableCollection) collectionDefinition.getCollectionPersister();
|
||||
addAssociationKey(
|
||||
|
|
|
@ -204,31 +204,6 @@ public class LoggingAssociationVisitationStrategy implements AssociationVisitati
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
// why do we have these + startingCollectionElements/finishingCollectionElements ???
|
||||
//
|
||||
// @Override
|
||||
// public void startingCompositeCollectionElement(CompositeCollectionElementDefinition compositionElementDefinition) {
|
||||
// System.out.println(
|
||||
// String.format(
|
||||
// "%s Starting composite (%s)",
|
||||
// StringHelper.repeat( ">>", ++depth ),
|
||||
// compositionElementDefinition.getCollectionDefinition().getCollectionPersister().getRole()
|
||||
// )
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void finishingCompositeCollectionElement(CompositeCollectionElementDefinition compositionElementDefinition) {
|
||||
// System.out.println(
|
||||
// String.format(
|
||||
// "%s Finishing composite (%s)",
|
||||
// StringHelper.repeat( "<<", depth-- ),
|
||||
// compositionElementDefinition.getCollectionDefinition().getCollectionPersister().getRole()
|
||||
// )
|
||||
// );
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void foundAny(AnyMappingDefinition anyDefinition) {
|
||||
// nothing to do
|
||||
|
|
Loading…
Reference in New Issue