From fdf211fdd1d6e31bbdcd920eb95a6bd4f1d62d77 Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Thu, 7 Nov 2013 12:50:17 -0800 Subject: [PATCH] HHH-8629 : Integrate LoadPlans into collection initializers --- .../returns/AbstractCollectionReference.java | 42 +++-- .../returns/AbstractCompositeFetch.java | 8 +- .../returns/AbstractEntityReference.java | 21 +-- .../returns/AbstractExpandingFetchSource.java | 76 +++++---- .../internal/returns/CollectionFetchImpl.java | 14 +- ...lectionFetchableElementCompositeGraph.java | 9 +- ...CollectionFetchableElementEntityGraph.java | 8 +- ...ollectionFetchableIndexCompositeGraph.java | 10 +- .../CollectionFetchableIndexEntityGraph.java | 8 +- .../returns/CollectionReturnImpl.java | 12 +- .../internal/returns/EntityFetchImpl.java | 4 +- .../internal/returns/EntityReturnImpl.java | 7 +- .../AbstractExpandingSourceQuerySpace.java | 151 ++++++++++++++++++ .../spaces}/AbstractQuerySpace.java | 15 +- .../spaces/CollectionQuerySpaceImpl.java | 81 +++++----- .../spaces/CompositeQuerySpaceImpl.java | 120 +------------- .../internal/spaces/EntityQuerySpaceImpl.java | 114 +------------ .../internal/spaces/QuerySpacesImpl.java | 73 +++++++-- ...BuildingAssociationVisitationStrategy.java | 20 +-- .../spi/ExpandingCollectionQuerySpace.java | 44 +++++ .../spi/ExpandingCompositeQuerySpace.java | 2 +- .../build/spi/ExpandingEntityQuerySpace.java | 6 +- .../plan2/build/spi/ExpandingFetchSource.java | 12 +- .../plan2/build/spi/ExpandingQuerySpaces.java | 25 ++- ...ce.java => ExpandingSourceQuerySpace.java} | 20 ++- 25 files changed, 461 insertions(+), 441 deletions(-) create mode 100644 hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/spaces/AbstractExpandingSourceQuerySpace.java rename hibernate-core/src/main/java/org/hibernate/loader/plan2/build/{spi => internal/spaces}/AbstractQuerySpace.java (88%) create mode 100644 hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/ExpandingCollectionQuerySpace.java rename hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/{ExpandingQuerySpace.java => ExpandingSourceQuerySpace.java} (78%) diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/AbstractCollectionReference.java b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/AbstractCollectionReference.java index 8eb04d74f5..2fcfc0cca9 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/AbstractCollectionReference.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/AbstractCollectionReference.java @@ -24,12 +24,12 @@ package org.hibernate.loader.plan2.build.internal.returns; import org.hibernate.loader.PropertyPath; -import org.hibernate.loader.plan2.build.internal.spaces.CollectionQuerySpaceImpl; -import org.hibernate.loader.plan2.build.spi.LoadPlanBuildingContext; +import org.hibernate.loader.plan2.build.spi.ExpandingCollectionQuerySpace; +import org.hibernate.loader.plan2.build.spi.ExpandingCompositeQuerySpace; +import org.hibernate.loader.plan2.build.spi.ExpandingEntityQuerySpace; import org.hibernate.loader.plan2.spi.CollectionFetchableElement; import org.hibernate.loader.plan2.spi.CollectionFetchableIndex; import org.hibernate.loader.plan2.spi.CollectionReference; -import org.hibernate.loader.plan2.spi.Join; import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.type.CompositeType; @@ -40,26 +40,23 @@ import org.hibernate.type.Type; * @author Steve Ebersole */ public abstract class AbstractCollectionReference implements CollectionReference { - private final CollectionQuerySpaceImpl collectionQuerySpace; + private final ExpandingCollectionQuerySpace collectionQuerySpace; private final PropertyPath propertyPath; private final CollectionFetchableIndex index; private final CollectionFetchableElement element; protected AbstractCollectionReference( - CollectionQuerySpaceImpl collectionQuerySpace, - PropertyPath propertyPath, - LoadPlanBuildingContext loadPlanBuildingContext) { + ExpandingCollectionQuerySpace collectionQuerySpace, + PropertyPath propertyPath) { this.collectionQuerySpace = collectionQuerySpace; this.propertyPath = propertyPath; - this.index = buildIndexGraph( collectionQuerySpace, loadPlanBuildingContext ); - this.element = buildElementGraph( collectionQuerySpace, loadPlanBuildingContext ); + this.index = buildIndexGraph( collectionQuerySpace ); + this.element = buildElementGraph( collectionQuerySpace ); } - private CollectionFetchableIndex buildIndexGraph( - CollectionQuerySpaceImpl collectionQuerySpace, - LoadPlanBuildingContext loadPlanBuildingContext) { + private CollectionFetchableIndex buildIndexGraph(ExpandingCollectionQuerySpace collectionQuerySpace) { final CollectionPersister persister = collectionQuerySpace.getCollectionPersister(); if ( persister.hasIndex() ) { final Type type = persister.getIndexType(); @@ -69,17 +66,17 @@ public abstract class AbstractCollectionReference implements CollectionReference ( (EntityType) type ).getAssociatedEntityName() ); - final Join join = collectionQuerySpace.addIndexEntityJoin( + final ExpandingEntityQuerySpace entityQuerySpace = collectionQuerySpace.addIndexEntityQuerySpace( indexPersister ); - return new CollectionFetchableIndexEntityGraph( this, join ); + return new CollectionFetchableIndexEntityGraph( this, entityQuerySpace ); } } else if ( type.isComponentType() ) { - final Join join = collectionQuerySpace.addIndexCompositeJoin( + final ExpandingCompositeQuerySpace compositeQuerySpace = collectionQuerySpace.addIndexCompositeQuerySpace( (CompositeType) type ); - return new CollectionFetchableIndexCompositeGraph( this, join ); + return new CollectionFetchableIndexCompositeGraph( this, compositeQuerySpace ); } } @@ -87,8 +84,7 @@ public abstract class AbstractCollectionReference implements CollectionReference } private CollectionFetchableElement buildElementGraph( - CollectionQuerySpaceImpl collectionQuerySpace, - LoadPlanBuildingContext loadPlanBuildingContext) { + ExpandingCollectionQuerySpace collectionQuerySpace) { final CollectionPersister persister = collectionQuerySpace.getCollectionPersister(); final Type type = persister.getElementType(); if ( type.isAssociationType() ) { @@ -97,15 +93,17 @@ public abstract class AbstractCollectionReference implements CollectionReference ( (EntityType) type ).getAssociatedEntityName() ); - final Join join = collectionQuerySpace.addElementEntityJoin( elementPersister ); - return new CollectionFetchableElementEntityGraph( this, join ); + final ExpandingEntityQuerySpace entityQuerySpace = collectionQuerySpace.addElementEntityQuerySpace( + elementPersister + ); + return new CollectionFetchableElementEntityGraph( this, entityQuerySpace ); } } else if ( type.isComponentType() ) { - final Join join = collectionQuerySpace.addElementCompositeJoin( + final ExpandingCompositeQuerySpace compositeQuerySpace = collectionQuerySpace.addElementCompositeQuerySpace( (CompositeType) type ); - return new CollectionFetchableElementCompositeGraph( this, join ); + return new CollectionFetchableElementCompositeGraph( this, compositeQuerySpace ); } return null; diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/AbstractCompositeFetch.java b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/AbstractCompositeFetch.java index d07abfe2da..d4b39f347f 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/AbstractCompositeFetch.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/AbstractCompositeFetch.java @@ -28,7 +28,6 @@ import org.hibernate.engine.FetchStyle; import org.hibernate.engine.FetchTiming; import org.hibernate.loader.PropertyPath; import org.hibernate.loader.plan2.build.spi.ExpandingCompositeQuerySpace; -import org.hibernate.loader.plan2.build.spi.LoadPlanBuildingContext; import org.hibernate.loader.plan2.spi.CollectionFetch; import org.hibernate.loader.plan2.spi.CompositeFetch; import org.hibernate.loader.plan2.spi.EntityReference; @@ -45,7 +44,7 @@ import org.hibernate.type.Type; * @author Gail Badner */ public abstract class AbstractCompositeFetch extends AbstractExpandingFetchSource implements CompositeFetch { - private static final FetchStrategy FETCH_STRATEGY = new FetchStrategy( FetchTiming.IMMEDIATE, FetchStyle.JOIN ); + protected static final FetchStrategy FETCH_STRATEGY = new FetchStrategy( FetchTiming.IMMEDIATE, FetchStyle.JOIN ); private final CompositeType compositeType; private final boolean allowCollectionFetches; @@ -104,8 +103,7 @@ public abstract class AbstractCompositeFetch extends AbstractExpandingFetchSourc @Override public CollectionFetch buildCollectionFetch( AssociationAttributeDefinition attributeDefinition, - FetchStrategy fetchStrategy, - LoadPlanBuildingContext loadPlanBuildingContext) { + FetchStrategy fetchStrategy) { if ( !allowCollectionFetches ) { throw new WalkingException( String.format( @@ -114,7 +112,7 @@ public abstract class AbstractCompositeFetch extends AbstractExpandingFetchSourc ) ); } - return super.buildCollectionFetch( attributeDefinition, fetchStrategy, loadPlanBuildingContext ); + return super.buildCollectionFetch( attributeDefinition, fetchStrategy ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/AbstractEntityReference.java b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/AbstractEntityReference.java index 95aa81ecbe..dab4b44d05 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/AbstractEntityReference.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/AbstractEntityReference.java @@ -29,7 +29,6 @@ import org.hibernate.loader.plan2.build.spi.ExpandingEntityQuerySpace; import org.hibernate.loader.plan2.spi.CompositeFetch; import org.hibernate.loader.plan2.spi.EntityIdentifierDescription; import org.hibernate.loader.plan2.spi.EntityReference; -import org.hibernate.loader.plan2.spi.Join; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.walking.spi.CompositionDefinition; import org.hibernate.persister.walking.spi.EncapsulatedEntityIdentifierDefinition; @@ -73,27 +72,29 @@ public abstract class AbstractEntityReference extends AbstractExpandingFetchSour } // if we get here, we know we have a composite identifier... - final Join join = expandingEntityQuerySpace().makeCompositeIdentifierJoin(); + final ExpandingCompositeQuerySpace querySpace = expandingEntityQuerySpace().makeCompositeIdentifierQuerySpace(); return identifierDefinition.isEncapsulated() - ? buildEncapsulatedCompositeIdentifierDescription( join ) - : buildNonEncapsulatedCompositeIdentifierDescription( join ); + ? buildEncapsulatedCompositeIdentifierDescription( querySpace ) + : buildNonEncapsulatedCompositeIdentifierDescription( querySpace ); } - private NonEncapsulatedEntityIdentifierDescription buildNonEncapsulatedCompositeIdentifierDescription(Join compositeJoin) { + private NonEncapsulatedEntityIdentifierDescription buildNonEncapsulatedCompositeIdentifierDescription( + ExpandingCompositeQuerySpace compositeQuerySpace) { return new NonEncapsulatedEntityIdentifierDescription( this, - (ExpandingCompositeQuerySpace) compositeJoin.getRightHandSide(), + compositeQuerySpace, (CompositeType) getEntityPersister().getIdentifierType(), - getPropertyPath().append( "id" ) + getPropertyPath().append( EntityPersister.ENTITY_ID ) ); } - private EncapsulatedEntityIdentifierDescription buildEncapsulatedCompositeIdentifierDescription(Join compositeJoin) { + private EncapsulatedEntityIdentifierDescription buildEncapsulatedCompositeIdentifierDescription( + ExpandingCompositeQuerySpace compositeQuerySpace) { return new EncapsulatedEntityIdentifierDescription( this, - (ExpandingCompositeQuerySpace) compositeJoin.getRightHandSide(), + compositeQuerySpace, (CompositeType) getEntityPersister().getIdentifierType(), - getPropertyPath().append( "id" ) + getPropertyPath().append( EntityPersister.ENTITY_ID ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/AbstractExpandingFetchSource.java b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/AbstractExpandingFetchSource.java index 235e00f3b4..79c424d36f 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/AbstractExpandingFetchSource.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/AbstractExpandingFetchSource.java @@ -27,25 +27,27 @@ import java.util.ArrayList; import java.util.List; import org.hibernate.engine.FetchStrategy; +import org.hibernate.engine.FetchStyle; +import org.hibernate.engine.FetchTiming; import org.hibernate.loader.PropertyPath; +import org.hibernate.loader.plan2.build.spi.ExpandingCollectionQuerySpace; import org.hibernate.loader.plan2.build.spi.ExpandingCompositeQuerySpace; +import org.hibernate.loader.plan2.build.spi.ExpandingEntityQuerySpace; import org.hibernate.loader.plan2.build.spi.ExpandingFetchSource; -import org.hibernate.loader.plan2.build.spi.ExpandingQuerySpace; -import org.hibernate.loader.plan2.build.spi.LoadPlanBuildingContext; +import org.hibernate.loader.plan2.build.spi.ExpandingQuerySpaces; +import org.hibernate.loader.plan2.build.spi.ExpandingSourceQuerySpace; import org.hibernate.loader.plan2.spi.BidirectionalEntityReference; import org.hibernate.loader.plan2.spi.CollectionFetch; import org.hibernate.loader.plan2.spi.CompositeFetch; import org.hibernate.loader.plan2.spi.EntityFetch; import org.hibernate.loader.plan2.spi.EntityReference; import org.hibernate.loader.plan2.spi.Fetch; -import org.hibernate.loader.plan2.spi.Join; import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.walking.spi.AssociationAttributeDefinition; import org.hibernate.persister.walking.spi.CompositionDefinition; import org.hibernate.persister.walking.spi.WalkingException; import org.hibernate.type.CollectionType; -import org.hibernate.type.CompositeType; import org.hibernate.type.EntityType; /** @@ -63,12 +65,12 @@ public abstract class AbstractExpandingFetchSource implements ExpandingFetchSour private static final BidirectionalEntityReference[] NO_BIDIRECTIONAL_ENTITY_REFERENCES = new BidirectionalEntityReference[0]; - private final ExpandingQuerySpace querySpace; + private final ExpandingSourceQuerySpace querySpace; private final PropertyPath propertyPath; private List fetches; private List bidirectionalEntityReferences; - public AbstractExpandingFetchSource(ExpandingQuerySpace querySpace, PropertyPath propertyPath) { + public AbstractExpandingFetchSource(ExpandingSourceQuerySpace querySpace, PropertyPath propertyPath) { this.querySpace = querySpace; this.propertyPath = propertyPath; } @@ -78,7 +80,7 @@ public abstract class AbstractExpandingFetchSource implements ExpandingFetchSour return querySpace.getUid(); } - protected final ExpandingQuerySpace expandingQuerySpace() { + protected final ExpandingSourceQuerySpace expandingQuerySpace() { return querySpace; } @@ -118,12 +120,9 @@ public abstract class AbstractExpandingFetchSource implements ExpandingFetchSour @Override public EntityFetch buildEntityFetch( AssociationAttributeDefinition attributeDefinition, - FetchStrategy fetchStrategy, - LoadPlanBuildingContext loadPlanBuildingContext) { + FetchStrategy fetchStrategy) { final EntityType fetchedType = (EntityType) attributeDefinition.getType(); - final EntityPersister fetchedPersister = loadPlanBuildingContext.getSessionFactory().getEntityPersister( - fetchedType.getAssociatedEntityName() - ); + final EntityPersister fetchedPersister = attributeDefinition.toEntityDefinition().getEntityPersister(); if ( fetchedPersister == null ) { throw new WalkingException( @@ -135,13 +134,14 @@ public abstract class AbstractExpandingFetchSource implements ExpandingFetchSour ); } - final Join join = querySpace.addEntityJoin( + final ExpandingEntityQuerySpace entityQuerySpace = querySpace.addEntityQuerySpace( attributeDefinition, fetchedPersister, - loadPlanBuildingContext.getQuerySpaces().generateImplicitUid(), - attributeDefinition.isNullable() + getQuerySpaces().generateImplicitUid(), + attributeDefinition.isNullable(), + shouldIncludeJoin( fetchStrategy ) ); - final EntityFetch fetch = new EntityFetchImpl( this, attributeDefinition, fetchStrategy, join ); + final EntityFetch fetch = new EntityFetchImpl( this, attributeDefinition, fetchStrategy, entityQuerySpace ); addFetch( fetch ); return fetch; } @@ -150,12 +150,9 @@ public abstract class AbstractExpandingFetchSource implements ExpandingFetchSour public BidirectionalEntityReference buildBidirectionalEntityReference( AssociationAttributeDefinition attributeDefinition, FetchStrategy fetchStrategy, - EntityReference targetEntityReference, - LoadPlanBuildingContext loadPlanBuildingContext) { + EntityReference targetEntityReference) { final EntityType fetchedType = (EntityType) attributeDefinition.getType(); - final EntityPersister fetchedPersister = loadPlanBuildingContext.getSessionFactory().getEntityPersister( - fetchedType.getAssociatedEntityName() - ); + final EntityPersister fetchedPersister = attributeDefinition.toEntityDefinition().getEntityPersister(); if ( fetchedPersister == null ) { throw new WalkingException( @@ -177,19 +174,20 @@ public abstract class AbstractExpandingFetchSource implements ExpandingFetchSour CompositionDefinition compositeType, ExpandingCompositeQuerySpace compositeQuerySpace); + protected ExpandingQuerySpaces getQuerySpaces() { + return querySpace.getExpandingQuerySpaces(); + } + @Override public CompositeFetch buildCompositeFetch( - CompositionDefinition attributeDefinition, - LoadPlanBuildingContext loadPlanBuildingContext) { - final ExpandingQuerySpace leftHandSide = expandingQuerySpace(); - final Join join = leftHandSide.addCompositeJoin( + CompositionDefinition attributeDefinition) { + final ExpandingSourceQuerySpace leftHandSide = expandingQuerySpace(); + final ExpandingCompositeQuerySpace compositeQuerySpace = leftHandSide.addCompositeQuerySpace( attributeDefinition, - loadPlanBuildingContext.getQuerySpaces().generateImplicitUid() - ); - final CompositeFetch fetch = createCompositeFetch( - attributeDefinition, - (ExpandingCompositeQuerySpace) join.getRightHandSide() + getQuerySpaces().generateImplicitUid(), + shouldIncludeJoin( AbstractCompositeFetch.FETCH_STRATEGY ) ); + final CompositeFetch fetch = createCompositeFetch( attributeDefinition, compositeQuerySpace ); addFetch( fetch ); return fetch; } @@ -197,16 +195,13 @@ public abstract class AbstractExpandingFetchSource implements ExpandingFetchSour @Override public CollectionFetch buildCollectionFetch( AssociationAttributeDefinition attributeDefinition, - FetchStrategy fetchStrategy, - LoadPlanBuildingContext loadPlanBuildingContext) { + FetchStrategy fetchStrategy) { // general question here wrt Joins and collection fetches... do we create multiple Joins for many-to-many, // for example, or do we allow the Collection QuerySpace to handle that? final CollectionType fetchedType = (CollectionType) attributeDefinition.getType(); - final CollectionPersister fetchedPersister = loadPlanBuildingContext.getSessionFactory().getCollectionPersister( - fetchedType.getRole() - ); + final CollectionPersister fetchedPersister = attributeDefinition.toCollectionDefinition().getCollectionPersister(); if ( fetchedPersister == null ) { throw new WalkingException( @@ -217,20 +212,23 @@ public abstract class AbstractExpandingFetchSource implements ExpandingFetchSour ) ); } - final Join join = querySpace.addCollectionJoin( + final ExpandingCollectionQuerySpace collectionQuerySpace = querySpace.addCollectionQuerySpace( attributeDefinition, fetchedPersister, - loadPlanBuildingContext.getQuerySpaces().generateImplicitUid() + getQuerySpaces().generateImplicitUid(), + shouldIncludeJoin( fetchStrategy ) ); final CollectionFetch fetch = new CollectionFetchImpl( this, attributeDefinition, fetchStrategy, - join, - loadPlanBuildingContext + collectionQuerySpace ); addFetch( fetch ); return fetch; } + private boolean shouldIncludeJoin(FetchStrategy fetchStrategy) { + return fetchStrategy.getTiming() == FetchTiming.IMMEDIATE && fetchStrategy.getStyle() == FetchStyle.JOIN; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/CollectionFetchImpl.java b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/CollectionFetchImpl.java index cca7444144..15ab2b7030 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/CollectionFetchImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/CollectionFetchImpl.java @@ -24,12 +24,10 @@ package org.hibernate.loader.plan2.build.internal.returns; import org.hibernate.engine.FetchStrategy; -import org.hibernate.loader.plan2.build.internal.spaces.CollectionQuerySpaceImpl; +import org.hibernate.loader.plan2.build.spi.ExpandingCollectionQuerySpace; import org.hibernate.loader.plan2.build.spi.ExpandingFetchSource; -import org.hibernate.loader.plan2.build.spi.LoadPlanBuildingContext; import org.hibernate.loader.plan2.spi.CollectionFetch; import org.hibernate.loader.plan2.spi.FetchSource; -import org.hibernate.loader.plan2.spi.Join; import org.hibernate.persister.walking.spi.AssociationAttributeDefinition; import org.hibernate.persister.walking.spi.AttributeDefinition; import org.hibernate.type.CollectionType; @@ -41,24 +39,20 @@ public class CollectionFetchImpl extends AbstractCollectionReference implements private final ExpandingFetchSource fetchSource; private final AttributeDefinition fetchedAttribute; private final FetchStrategy fetchStrategy; - private final Join fetchedJoin; public CollectionFetchImpl( ExpandingFetchSource fetchSource, AssociationAttributeDefinition fetchedAttribute, FetchStrategy fetchStrategy, - Join fetchedJoin, - LoadPlanBuildingContext loadPlanBuildingContext) { + ExpandingCollectionQuerySpace collectionQuerySpace) { super( - (CollectionQuerySpaceImpl) fetchedJoin.getRightHandSide(), - fetchSource.getPropertyPath().append( fetchedAttribute.getName() ), - loadPlanBuildingContext + collectionQuerySpace, + fetchSource.getPropertyPath().append( fetchedAttribute.getName() ) ); this.fetchSource = fetchSource; this.fetchedAttribute = fetchedAttribute; this.fetchStrategy = fetchStrategy; - this.fetchedJoin = fetchedJoin; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/CollectionFetchableElementCompositeGraph.java b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/CollectionFetchableElementCompositeGraph.java index fec985b1b9..8be85a5386 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/CollectionFetchableElementCompositeGraph.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/CollectionFetchableElementCompositeGraph.java @@ -28,7 +28,6 @@ import org.hibernate.loader.plan2.spi.CollectionFetchableElement; import org.hibernate.loader.plan2.spi.CollectionReference; import org.hibernate.loader.plan2.spi.CompositeFetch; import org.hibernate.loader.plan2.spi.FetchSource; -import org.hibernate.loader.plan2.spi.Join; import org.hibernate.type.CompositeType; /** @@ -42,10 +41,12 @@ public class CollectionFetchableElementCompositeGraph private final CollectionReference collectionReference; - public CollectionFetchableElementCompositeGraph(CollectionReference collectionReference, Join compositeJoin) { + public CollectionFetchableElementCompositeGraph( + CollectionReference collectionReference, + ExpandingCompositeQuerySpace compositeQuerySpace) { super( - (CompositeType) compositeJoin.getRightHandSide().getPropertyMapping().getType(), - (ExpandingCompositeQuerySpace) compositeJoin.getRightHandSide(), + (CompositeType) compositeQuerySpace.getPropertyMapping().getType(), + compositeQuerySpace, false, // these property paths are just informational... collectionReference.getPropertyPath().append( "" ) diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/CollectionFetchableElementEntityGraph.java b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/CollectionFetchableElementEntityGraph.java index fb582d26be..d0b185c617 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/CollectionFetchableElementEntityGraph.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/CollectionFetchableElementEntityGraph.java @@ -27,8 +27,6 @@ import org.hibernate.engine.FetchStrategy; import org.hibernate.loader.plan2.build.spi.ExpandingEntityQuerySpace; import org.hibernate.loader.plan2.spi.CollectionFetchableElement; import org.hibernate.loader.plan2.spi.CollectionReference; -import org.hibernate.loader.plan2.spi.EntityQuerySpace; -import org.hibernate.loader.plan2.spi.Join; import org.hibernate.persister.walking.spi.AttributeDefinition; /** @@ -36,18 +34,16 @@ import org.hibernate.persister.walking.spi.AttributeDefinition; */ public class CollectionFetchableElementEntityGraph extends AbstractEntityReference implements CollectionFetchableElement { private final CollectionReference collectionReference; - private final EntityQuerySpace entityQuerySpace; public CollectionFetchableElementEntityGraph( CollectionReference collectionReference, - Join entityJoin) { + ExpandingEntityQuerySpace entityQuerySpace) { super( - (ExpandingEntityQuerySpace) entityJoin.getRightHandSide(), + entityQuerySpace, collectionReference.getPropertyPath().append( "" ) ); this.collectionReference = collectionReference; - this.entityQuerySpace = (EntityQuerySpace) entityJoin.getRightHandSide(); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/CollectionFetchableIndexCompositeGraph.java b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/CollectionFetchableIndexCompositeGraph.java index a0946929ee..e4b6f550bb 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/CollectionFetchableIndexCompositeGraph.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/CollectionFetchableIndexCompositeGraph.java @@ -46,18 +46,18 @@ public class CollectionFetchableIndexCompositeGraph public CollectionFetchableIndexCompositeGraph( CollectionReference collectionReference, - Join compositeJoin) { + ExpandingCompositeQuerySpace compositeQuerySpace) { super( - extractIndexType( compositeJoin ), - (ExpandingCompositeQuerySpace) compositeJoin.getRightHandSide(), + extractIndexType( compositeQuerySpace ), + compositeQuerySpace, false, collectionReference.getPropertyPath().append( "" ) ); this.collectionReference = collectionReference; } - private static CompositeType extractIndexType(Join compositeJoin) { - final Type type = compositeJoin.getRightHandSide().getPropertyMapping().getType(); + private static CompositeType extractIndexType(ExpandingCompositeQuerySpace compositeQuerySpace) { + final Type type = compositeQuerySpace.getPropertyMapping().getType(); if ( CompositeType.class.isInstance( type ) ) { return (CompositeType) type; } diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/CollectionFetchableIndexEntityGraph.java b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/CollectionFetchableIndexEntityGraph.java index a92ff7c167..38cdba0c99 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/CollectionFetchableIndexEntityGraph.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/CollectionFetchableIndexEntityGraph.java @@ -27,8 +27,6 @@ import org.hibernate.engine.FetchStrategy; import org.hibernate.loader.plan2.build.spi.ExpandingEntityQuerySpace; import org.hibernate.loader.plan2.spi.CollectionFetchableIndex; import org.hibernate.loader.plan2.spi.CollectionReference; -import org.hibernate.loader.plan2.spi.EntityQuerySpace; -import org.hibernate.loader.plan2.spi.Join; import org.hibernate.persister.walking.spi.AttributeDefinition; /** @@ -36,18 +34,16 @@ import org.hibernate.persister.walking.spi.AttributeDefinition; */ public class CollectionFetchableIndexEntityGraph extends AbstractEntityReference implements CollectionFetchableIndex { private final CollectionReference collectionReference; - private final EntityQuerySpace entityQuerySpace; public CollectionFetchableIndexEntityGraph( CollectionReference collectionReference, - Join entityJoin) { + ExpandingEntityQuerySpace entityQuerySpace) { super( - (ExpandingEntityQuerySpace) entityJoin.getRightHandSide(), + entityQuerySpace, collectionReference.getPropertyPath().append( "" ) ); this.collectionReference = collectionReference; - this.entityQuerySpace = (EntityQuerySpace) entityJoin.getRightHandSide(); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/CollectionReturnImpl.java b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/CollectionReturnImpl.java index d4ed1d648c..210273643a 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/CollectionReturnImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/CollectionReturnImpl.java @@ -24,8 +24,7 @@ package org.hibernate.loader.plan2.build.internal.returns; import org.hibernate.loader.PropertyPath; -import org.hibernate.loader.plan2.build.internal.spaces.CollectionQuerySpaceImpl; -import org.hibernate.loader.plan2.build.spi.LoadPlanBuildingContext; +import org.hibernate.loader.plan2.build.spi.ExpandingQuerySpaces; import org.hibernate.loader.plan2.spi.CollectionReturn; import org.hibernate.persister.walking.spi.CollectionDefinition; @@ -34,14 +33,13 @@ import org.hibernate.persister.walking.spi.CollectionDefinition; */ public class CollectionReturnImpl extends AbstractCollectionReference implements CollectionReturn { - public CollectionReturnImpl(CollectionDefinition collectionDefinition, LoadPlanBuildingContext context) { + public CollectionReturnImpl(CollectionDefinition collectionDefinition, ExpandingQuerySpaces querySpaces) { super( - (CollectionQuerySpaceImpl) context.getQuerySpaces().makeCollectionQuerySpace( - context.getQuerySpaces().generateImplicitUid(), + querySpaces.makeRootCollectionQuerySpace( + querySpaces.generateImplicitUid(), collectionDefinition.getCollectionPersister() ), - new PropertyPath( "[" + collectionDefinition.getCollectionPersister().getRole() + "]" ), - context + new PropertyPath( "[" + collectionDefinition.getCollectionPersister().getRole() + "]" ) ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/EntityFetchImpl.java b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/EntityFetchImpl.java index 883ec88044..0e066c4001 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/EntityFetchImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/EntityFetchImpl.java @@ -45,9 +45,9 @@ public class EntityFetchImpl extends AbstractEntityReference implements EntityFe ExpandingFetchSource fetchSource, AssociationAttributeDefinition fetchedAttribute, FetchStrategy fetchStrategy, - Join fetchedJoin) { + ExpandingEntityQuerySpace entityQuerySpace) { super( - (ExpandingEntityQuerySpace) fetchedJoin.getRightHandSide(), + entityQuerySpace, fetchSource.getPropertyPath().append( fetchedAttribute.getName() ) ); diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/EntityReturnImpl.java b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/EntityReturnImpl.java index 1e29b0de6e..a75dfe6285 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/EntityReturnImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/returns/EntityReturnImpl.java @@ -26,6 +26,7 @@ package org.hibernate.loader.plan2.build.internal.returns; import org.hibernate.engine.FetchStrategy; import org.hibernate.loader.PropertyPath; import org.hibernate.loader.plan2.build.spi.ExpandingFetchSource; +import org.hibernate.loader.plan2.build.spi.ExpandingQuerySpaces; import org.hibernate.loader.plan2.build.spi.LoadPlanBuildingContext; import org.hibernate.loader.plan2.spi.EntityReturn; import org.hibernate.persister.walking.spi.AttributeDefinition; @@ -35,10 +36,10 @@ import org.hibernate.persister.walking.spi.EntityDefinition; * @author Steve Ebersole */ public class EntityReturnImpl extends AbstractEntityReference implements EntityReturn, ExpandingFetchSource { - public EntityReturnImpl(EntityDefinition entityDefinition, LoadPlanBuildingContext loadPlanBuildingContext) { + public EntityReturnImpl(EntityDefinition entityDefinition, ExpandingQuerySpaces querySpaces) { super( - loadPlanBuildingContext.getQuerySpaces().makeEntityQuerySpace( - loadPlanBuildingContext.getQuerySpaces().generateImplicitUid(), + querySpaces.makeRootEntityQuerySpace( + querySpaces.generateImplicitUid(), entityDefinition.getEntityPersister() ), new PropertyPath( entityDefinition.getEntityPersister().getEntityName() ) diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/spaces/AbstractExpandingSourceQuerySpace.java b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/spaces/AbstractExpandingSourceQuerySpace.java new file mode 100644 index 0000000000..4618f3e7ae --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/spaces/AbstractExpandingSourceQuerySpace.java @@ -0,0 +1,151 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2013, 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.loader.plan2.build.internal.spaces; + +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.loader.plan2.build.spi.ExpandingCollectionQuerySpace; +import org.hibernate.loader.plan2.build.spi.ExpandingCompositeQuerySpace; +import org.hibernate.loader.plan2.build.spi.ExpandingEntityQuerySpace; +import org.hibernate.loader.plan2.build.spi.ExpandingQuerySpaces; +import org.hibernate.loader.plan2.build.spi.ExpandingSourceQuerySpace; +import org.hibernate.loader.plan2.spi.JoinDefinedByMetadata; +import org.hibernate.persister.collection.CollectionPersister; +import org.hibernate.persister.entity.EntityPersister; +import org.hibernate.persister.entity.Queryable; +import org.hibernate.persister.walking.spi.AttributeDefinition; +import org.hibernate.persister.walking.spi.CompositionDefinition; +import org.hibernate.type.CollectionType; +import org.hibernate.type.EntityType; + +/** + * @author Gail Badner + */ +public abstract class AbstractExpandingSourceQuerySpace extends AbstractQuerySpace implements ExpandingSourceQuerySpace { + + public AbstractExpandingSourceQuerySpace( + String uid, + Disposition disposition, + ExpandingQuerySpaces querySpaces, + boolean canJoinsBeRequired, + SessionFactoryImplementor sessionFactory) { + super( uid, disposition, querySpaces, canJoinsBeRequired, sessionFactory ); + } + + @Override + public ExpandingCompositeQuerySpace addCompositeQuerySpace( + CompositionDefinition compositionDefinition, + String querySpaceUid, + boolean shouldIncludeJoin) { + final boolean required = canJoinsBeRequired() && !compositionDefinition.isNullable(); + + final ExpandingCompositeQuerySpace rhs = getExpandingQuerySpaces().makeCompositeQuerySpace( + querySpaceUid, + new CompositePropertyMapping( + compositionDefinition.getType(), + getPropertyMapping(), + compositionDefinition.getName() + ), + required + ); + + if ( shouldIncludeJoin ) { + final JoinDefinedByMetadata join = JoinHelper.INSTANCE.createCompositeJoin( + this, + compositionDefinition.getName(), + rhs, + required, + compositionDefinition.getType() + ); + internalGetJoins().add( join ); + } + + return rhs; + } + + @Override + public ExpandingEntityQuerySpace addEntityQuerySpace( + AttributeDefinition attribute, + EntityPersister persister, + String querySpaceUid, + boolean optional, + boolean shouldIncludeJoin) { + // TODO: Queryable.isMultiTable() may be more broad than it needs to be... + final boolean isMultiTable = Queryable.class.cast( persister ).isMultiTable(); + final boolean required = canJoinsBeRequired() && !isMultiTable && !optional; + + final ExpandingEntityQuerySpace rhs = getExpandingQuerySpaces().makeEntityQuerySpace( + querySpaceUid, + persister, + required + ); + + if ( shouldIncludeJoin ) { + final JoinDefinedByMetadata join = JoinHelper.INSTANCE.createEntityJoin( + this, + attribute.getName(), + rhs, + required, + (EntityType) attribute.getType(), + sessionFactory() + ); + internalGetJoins().add( join ); + } + + return rhs; + } + + @Override + public ExpandingCollectionQuerySpace addCollectionQuerySpace( + AttributeDefinition attributeDefinition, + CollectionPersister collectionPersister, + String querySpaceUid, + boolean shouldIncludeJoin) { + final boolean required = canJoinsBeRequired() && !attributeDefinition.isNullable(); + + final ExpandingCollectionQuerySpace rhs = getExpandingQuerySpaces().makeCollectionQuerySpace( + querySpaceUid, + collectionPersister, + required + ); + + if ( shouldIncludeJoin ) { + final JoinDefinedByMetadata join = JoinHelper.INSTANCE.createCollectionJoin( + this, + attributeDefinition.getName(), + rhs, + required, + (CollectionType) attributeDefinition.getType(), + sessionFactory() + ); + internalGetJoins().add( join ); + } + + return rhs; + } + + @Override + public ExpandingQuerySpaces getExpandingQuerySpaces() { + return super.getExpandingQuerySpaces(); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/AbstractQuerySpace.java b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/spaces/AbstractQuerySpace.java similarity index 88% rename from hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/AbstractQuerySpace.java rename to hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/spaces/AbstractQuerySpace.java index 182cea7c0e..75639fa0db 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/AbstractQuerySpace.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/spaces/AbstractQuerySpace.java @@ -21,17 +21,18 @@ * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ -package org.hibernate.loader.plan2.build.spi; +package org.hibernate.loader.plan2.build.internal.spaces; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.loader.plan2.build.spi.ExpandingQuerySpaces; import org.hibernate.loader.plan2.spi.AbstractPlanNode; -import org.hibernate.loader.plan2.build.internal.spaces.QuerySpacesImpl; import org.hibernate.loader.plan2.spi.Join; import org.hibernate.loader.plan2.spi.QuerySpace; +import org.hibernate.loader.plan2.spi.QuerySpaces; /** * Convenience base class for QuerySpace implementations. @@ -41,7 +42,7 @@ import org.hibernate.loader.plan2.spi.QuerySpace; public abstract class AbstractQuerySpace extends AbstractPlanNode implements QuerySpace { private final String uid; private final Disposition disposition; - private final QuerySpacesImpl querySpaces; + private final ExpandingQuerySpaces querySpaces; private final boolean canJoinsBeRequired; private List joins; @@ -49,7 +50,7 @@ public abstract class AbstractQuerySpace extends AbstractPlanNode implements Que public AbstractQuerySpace( String uid, Disposition disposition, - QuerySpacesImpl querySpaces, + ExpandingQuerySpaces querySpaces, boolean canJoinsBeRequired, SessionFactoryImplementor sessionFactory) { super( sessionFactory ); @@ -80,7 +81,11 @@ public abstract class AbstractQuerySpace extends AbstractPlanNode implements Que * * @return The query spaces */ - public QuerySpacesImpl getQuerySpaces() { + public QuerySpaces getQuerySpaces() { + return querySpaces; + } + + protected ExpandingQuerySpaces getExpandingQuerySpaces() { return querySpaces; } diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/spaces/CollectionQuerySpaceImpl.java b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/spaces/CollectionQuerySpaceImpl.java index ba90ee2fb0..e8dd0501a8 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/spaces/CollectionQuerySpaceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/spaces/CollectionQuerySpaceImpl.java @@ -24,9 +24,10 @@ package org.hibernate.loader.plan2.build.internal.spaces; import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.hibernate.loader.plan2.build.spi.AbstractQuerySpace; -import org.hibernate.loader.plan2.spi.CollectionQuerySpace; -import org.hibernate.loader.plan2.spi.Join; +import org.hibernate.loader.plan2.build.spi.ExpandingCollectionQuerySpace; +import org.hibernate.loader.plan2.build.spi.ExpandingCompositeQuerySpace; +import org.hibernate.loader.plan2.build.spi.ExpandingEntityQuerySpace; +import org.hibernate.loader.plan2.build.spi.ExpandingQuerySpaces; import org.hibernate.loader.plan2.spi.JoinDefinedByMetadata; import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.collection.CollectionPropertyMapping; @@ -40,14 +41,14 @@ import org.hibernate.type.EntityType; /** * @author Steve Ebersole */ -public class CollectionQuerySpaceImpl extends AbstractQuerySpace implements CollectionQuerySpace { +public class CollectionQuerySpaceImpl extends AbstractQuerySpace implements ExpandingCollectionQuerySpace { private final CollectionPersister persister; private final CollectionPropertyMapping propertyMapping; public CollectionQuerySpaceImpl( CollectionPersister persister, String uid, - QuerySpacesImpl querySpaces, + ExpandingQuerySpaces querySpaces, boolean canJoinsBeRequired, SessionFactoryImplementor sessionFactory) { super( uid, Disposition.COLLECTION, querySpaces, canJoinsBeRequired, sessionFactory ); @@ -65,47 +66,44 @@ public class CollectionQuerySpaceImpl extends AbstractQuerySpace implements Coll return propertyMapping; } - public JoinDefinedByMetadata addIndexEntityJoin(final EntityPersister indexPersister) { + @Override + public ExpandingEntityQuerySpace addIndexEntityQuerySpace( + final EntityPersister indexPersister) { final boolean required = canJoinsBeRequired(); - final String entityQuerySpaceUid = getQuerySpaces().generateImplicitUid(); - final EntityQuerySpaceImpl entityQuerySpace = new EntityQuerySpaceImpl( - indexPersister, + final String entityQuerySpaceUid = getExpandingQuerySpaces().generateImplicitUid(); + final ExpandingEntityQuerySpace entityQuerySpace = getExpandingQuerySpaces().makeEntityQuerySpace( entityQuerySpaceUid, - getQuerySpaces(), - required, - sessionFactory() + indexPersister, + required ); - getQuerySpaces().registerQuerySpace( entityQuerySpace ); final JoinDefinedByMetadata join = JoinHelper.INSTANCE.createEntityJoin( this, // collection persister maps its index (through its PropertyMapping contract) as non-prefixed CollectionPropertyNames.COLLECTION_INDICES, entityQuerySpace, - canJoinsBeRequired(), + required, (EntityType) persister.getIndexType(), sessionFactory() ); - internalGetJoins().add( join ); - return join; + return entityQuerySpace; } - public JoinDefinedByMetadata addIndexCompositeJoin(CompositeType compositeType) { - final String compositeQuerySpaceUid = getQuerySpaces().generateImplicitUid(); - final CompositeQuerySpaceImpl compositeQuerySpace = new CompositeQuerySpaceImpl( + @Override + public ExpandingCompositeQuerySpace addIndexCompositeQuerySpace( + CompositeType compositeType) { + final String compositeQuerySpaceUid = getExpandingQuerySpaces().generateImplicitUid(); + final ExpandingCompositeQuerySpace compositeQuerySpace = getExpandingQuerySpaces().makeCompositeQuerySpace( + compositeQuerySpaceUid, new CompositePropertyMapping( compositeType, (PropertyMapping) getCollectionPersister(), "index" ), - compositeQuerySpaceUid, - getQuerySpaces(), - canJoinsBeRequired(), - sessionFactory() + canJoinsBeRequired() ); - getQuerySpaces().registerQuerySpace( compositeQuerySpace ); final JoinDefinedByMetadata join = JoinHelper.INSTANCE.createCompositeJoin( this, @@ -116,19 +114,18 @@ public class CollectionQuerySpaceImpl extends AbstractQuerySpace implements Coll ); internalGetJoins().add( join ); - return join; + return compositeQuerySpace; } - public JoinDefinedByMetadata addElementEntityJoin(final EntityPersister elementPersister) { - final String entityQuerySpaceUid = getQuerySpaces().generateImplicitUid(); - final EntityQuerySpaceImpl entityQuerySpace = new EntityQuerySpaceImpl( - elementPersister, + @Override + public ExpandingEntityQuerySpace addElementEntityQuerySpace( + final EntityPersister elementPersister) { + final String entityQuerySpaceUid = getExpandingQuerySpaces().generateImplicitUid(); + final ExpandingEntityQuerySpace entityQuerySpace = getExpandingQuerySpaces().makeEntityQuerySpace( entityQuerySpaceUid, - getQuerySpaces(), - canJoinsBeRequired(), - sessionFactory() + elementPersister, + canJoinsBeRequired() ); - getQuerySpaces().registerQuerySpace( entityQuerySpace ); final JoinDefinedByMetadata join = JoinHelper.INSTANCE.createEntityJoin( this, @@ -141,25 +138,23 @@ public class CollectionQuerySpaceImpl extends AbstractQuerySpace implements Coll ); internalGetJoins().add( join ); - return join; + return entityQuerySpace; } - public JoinDefinedByMetadata addElementCompositeJoin( + @Override + public ExpandingCompositeQuerySpace addElementCompositeQuerySpace( CompositeType compositeType) { - final String compositeQuerySpaceUid = getQuerySpaces().generateImplicitUid(); + final String compositeQuerySpaceUid = getExpandingQuerySpaces().generateImplicitUid(); - final CompositeQuerySpaceImpl compositeQuerySpace = new CompositeQuerySpaceImpl( + final ExpandingCompositeQuerySpace compositeQuerySpace = getExpandingQuerySpaces().makeCompositeQuerySpace( + compositeQuerySpaceUid, new CompositePropertyMapping( compositeType, (PropertyMapping) getCollectionPersister(), "" ), - compositeQuerySpaceUid, - getQuerySpaces(), - canJoinsBeRequired(), - sessionFactory() + canJoinsBeRequired() ); - getQuerySpaces().registerQuerySpace( compositeQuerySpace ); final JoinDefinedByMetadata join = JoinHelper.INSTANCE.createCompositeJoin( this, // collection persister maps its elements (through its PropertyMapping contract) as non-prefixed @@ -170,6 +165,6 @@ public class CollectionQuerySpaceImpl extends AbstractQuerySpace implements Coll ); internalGetJoins().add( join ); - return join; + return compositeQuerySpace; } } diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/spaces/CompositeQuerySpaceImpl.java b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/spaces/CompositeQuerySpaceImpl.java index f631c45daa..a6b81c58b5 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/spaces/CompositeQuerySpaceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/spaces/CompositeQuerySpaceImpl.java @@ -24,142 +24,28 @@ package org.hibernate.loader.plan2.build.internal.spaces; import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.hibernate.loader.plan2.build.spi.AbstractQuerySpace; import org.hibernate.loader.plan2.build.spi.ExpandingCompositeQuerySpace; -import org.hibernate.loader.plan2.spi.JoinDefinedByMetadata; -import org.hibernate.persister.collection.CollectionPersister; -import org.hibernate.persister.entity.EntityPersister; +import org.hibernate.loader.plan2.build.spi.ExpandingQuerySpaces; import org.hibernate.persister.entity.PropertyMapping; -import org.hibernate.persister.entity.Queryable; -import org.hibernate.persister.walking.spi.AttributeDefinition; -import org.hibernate.persister.walking.spi.CompositionDefinition; -import org.hibernate.type.CollectionType; -import org.hibernate.type.EntityType; /** * @author Steve Ebersole */ -public class CompositeQuerySpaceImpl extends AbstractQuerySpace implements ExpandingCompositeQuerySpace { +public class CompositeQuerySpaceImpl extends AbstractExpandingSourceQuerySpace implements ExpandingCompositeQuerySpace { private final CompositePropertyMapping compositeSubPropertyMapping; public CompositeQuerySpaceImpl( CompositePropertyMapping compositeSubPropertyMapping, String uid, - QuerySpacesImpl querySpaces, + ExpandingQuerySpaces querySpaces, boolean canJoinsBeRequired, SessionFactoryImplementor sessionFactory) { super( uid, Disposition.COMPOSITE, querySpaces, canJoinsBeRequired, sessionFactory ); this.compositeSubPropertyMapping = compositeSubPropertyMapping; } - public CompositeQuerySpaceImpl( - EntityQuerySpaceImpl entityQuerySpace, - CompositePropertyMapping compositePropertyMapping, - String uid, - boolean canJoinsBeRequired) { - // todo : we may need to keep around the owning entity query space to be able to properly handle circularity... - this( - compositePropertyMapping, - uid, - entityQuerySpace.getQuerySpaces(), - canJoinsBeRequired, - entityQuerySpace.sessionFactory() - ); - } - @Override public PropertyMapping getPropertyMapping() { return compositeSubPropertyMapping; } - - @Override - public JoinDefinedByMetadata addCompositeJoin(CompositionDefinition compositionDefinition, String querySpaceUid) { - final boolean required = canJoinsBeRequired() && !compositionDefinition.isNullable(); - - final CompositeQuerySpaceImpl rhs = new CompositeQuerySpaceImpl( - new CompositePropertyMapping( - compositionDefinition.getType(), - compositeSubPropertyMapping, - compositionDefinition.getName() - ), - querySpaceUid, - getQuerySpaces(), - required, - sessionFactory() - ); - getQuerySpaces().registerQuerySpace( rhs ); - - final JoinDefinedByMetadata join = JoinHelper.INSTANCE.createCompositeJoin( - this, - compositionDefinition.getName(), - rhs, - required, - compositionDefinition.getType() - ); - internalGetJoins().add( join ); - - return join; - } - - @Override - public JoinDefinedByMetadata addEntityJoin( - AttributeDefinition attributeDefinition, - EntityPersister persister, - String querySpaceUid, - boolean optional) { - // TODO: Queryable.isMultiTable() may be more broad than it needs to be... - final boolean isMultiTable = Queryable.class.cast( persister ).isMultiTable(); - final boolean required = canJoinsBeRequired() && !isMultiTable && !optional; - - final EntityQuerySpaceImpl rhs = new EntityQuerySpaceImpl( - persister, - querySpaceUid, - getQuerySpaces(), - required, - sessionFactory() - ); - getQuerySpaces().registerQuerySpace( rhs ); - - final JoinDefinedByMetadata join = JoinHelper.INSTANCE.createEntityJoin( - this, - attributeDefinition.getName(), - rhs, - required, - (EntityType) attributeDefinition.getType(), - sessionFactory() - ); - - internalGetJoins().add( join ); - - return join; - } - - @Override - public JoinDefinedByMetadata addCollectionJoin( - AttributeDefinition attributeDefinition, - CollectionPersister collectionPersister, - String querySpaceUid) { - final boolean required = canJoinsBeRequired() && ! attributeDefinition.isNullable(); - - final CollectionQuerySpaceImpl rhs = new CollectionQuerySpaceImpl( - collectionPersister, - querySpaceUid, - getQuerySpaces(), - required, - sessionFactory() - ); - getQuerySpaces().registerQuerySpace( rhs ); - - final JoinDefinedByMetadata join = JoinHelper.INSTANCE.createCollectionJoin( - this, - attributeDefinition.getName(), - rhs, required, - (CollectionType) attributeDefinition.getType(), - sessionFactory() - ); - - internalGetJoins().add( join ); - - return join; - } } diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/spaces/EntityQuerySpaceImpl.java b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/spaces/EntityQuerySpaceImpl.java index ff55d69dd7..af6aec6c3b 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/spaces/EntityQuerySpaceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/spaces/EntityQuerySpaceImpl.java @@ -24,30 +24,24 @@ package org.hibernate.loader.plan2.build.internal.spaces; import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.hibernate.loader.plan2.build.spi.AbstractQuerySpace; +import org.hibernate.loader.plan2.build.spi.ExpandingCompositeQuerySpace; import org.hibernate.loader.plan2.build.spi.ExpandingEntityQuerySpace; -import org.hibernate.loader.plan2.spi.Join; +import org.hibernate.loader.plan2.build.spi.ExpandingQuerySpaces; import org.hibernate.loader.plan2.spi.JoinDefinedByMetadata; -import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.PropertyMapping; -import org.hibernate.persister.entity.Queryable; -import org.hibernate.persister.walking.spi.AttributeDefinition; -import org.hibernate.persister.walking.spi.CompositionDefinition; -import org.hibernate.type.CollectionType; import org.hibernate.type.CompositeType; -import org.hibernate.type.EntityType; /** * @author Steve Ebersole */ -public class EntityQuerySpaceImpl extends AbstractQuerySpace implements ExpandingEntityQuerySpace { +public class EntityQuerySpaceImpl extends AbstractExpandingSourceQuerySpace implements ExpandingEntityQuerySpace { private final EntityPersister persister; public EntityQuerySpaceImpl( EntityPersister persister, String uid, - QuerySpacesImpl querySpaces, + ExpandingQuerySpaces querySpaces, boolean canJoinsBeRequired, SessionFactoryImplementor sessionFactory) { super( uid, Disposition.ENTITY, querySpaces, canJoinsBeRequired, sessionFactory ); @@ -72,109 +66,17 @@ public class EntityQuerySpaceImpl extends AbstractQuerySpace implements Expandin } @Override - public JoinDefinedByMetadata addCompositeJoin(CompositionDefinition compositionDefinition, String querySpaceUid) { - final boolean required = canJoinsBeRequired() && !compositionDefinition.isNullable(); - - final CompositeQuerySpaceImpl rhs = new CompositeQuerySpaceImpl( - new CompositePropertyMapping( - compositionDefinition.getType(), - (PropertyMapping) this.getEntityPersister(), - compositionDefinition.getName() - ), - querySpaceUid, - getQuerySpaces(), - required, - sessionFactory() - ); - getQuerySpaces().registerQuerySpace( rhs ); - - final JoinDefinedByMetadata join = JoinHelper.INSTANCE.createCompositeJoin( - this, - compositionDefinition.getName(), - rhs, - required, - compositionDefinition.getType() - ); - internalGetJoins().add( join ); - - return join; - } - - public JoinDefinedByMetadata addEntityJoin( - AttributeDefinition attribute, - EntityPersister persister, - String querySpaceUid, - boolean optional) { - // TODO: Queryable.isMultiTable() may be more broad than it needs to be... - final boolean isMultiTable = Queryable.class.cast( persister ).isMultiTable(); - final boolean required = canJoinsBeRequired() && !isMultiTable && !optional; - - final EntityQuerySpaceImpl rhs = new EntityQuerySpaceImpl( - persister, - querySpaceUid, - getQuerySpaces(), - required, - sessionFactory() - ); - getQuerySpaces().registerQuerySpace( rhs ); - - final JoinDefinedByMetadata join = JoinHelper.INSTANCE.createEntityJoin( - this, - attribute.getName(), - rhs, - required, - (EntityType) attribute.getType(), - sessionFactory() - ); - - internalGetJoins().add( join ); - - return join; - } - - @Override - public JoinDefinedByMetadata addCollectionJoin( - AttributeDefinition attributeDefinition, - CollectionPersister collectionPersister, - String querySpaceUid) { - final boolean required = canJoinsBeRequired() && !attributeDefinition.isNullable(); - - final CollectionQuerySpaceImpl rhs = new CollectionQuerySpaceImpl( - collectionPersister, - querySpaceUid, - getQuerySpaces(), - required, - sessionFactory() - ); - getQuerySpaces().registerQuerySpace( rhs ); - final JoinDefinedByMetadata join = JoinHelper.INSTANCE.createCollectionJoin( - this, - attributeDefinition.getName(), - rhs, - required, - (CollectionType) attributeDefinition.getType(), - sessionFactory() - ); - internalGetJoins().add( join ); - - return join; - } - - @Override - public JoinDefinedByMetadata makeCompositeIdentifierJoin() { + public ExpandingCompositeQuerySpace makeCompositeIdentifierQuerySpace() { final String compositeQuerySpaceUid = getUid() + "-id"; - final CompositeQuerySpaceImpl rhs = new CompositeQuerySpaceImpl( - this, + final ExpandingCompositeQuerySpace rhs = getExpandingQuerySpaces().makeCompositeQuerySpace( + compositeQuerySpaceUid, new CompositePropertyMapping( (CompositeType) getEntityPersister().getIdentifierType(), (PropertyMapping) getEntityPersister(), getEntityPersister().getIdentifierPropertyName() ), - compositeQuerySpaceUid, canJoinsBeRequired() ); - getQuerySpaces().registerQuerySpace( rhs ); - final JoinDefinedByMetadata join = JoinHelper.INSTANCE.createCompositeJoin( this, EntityPersister.ENTITY_ID, @@ -184,6 +86,6 @@ public class EntityQuerySpaceImpl extends AbstractQuerySpace implements Expandin ); internalGetJoins().add( join ); - return join; + return rhs; } } diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/spaces/QuerySpacesImpl.java b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/spaces/QuerySpacesImpl.java index e162f4c806..77f6e0f076 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/spaces/QuerySpacesImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/internal/spaces/QuerySpacesImpl.java @@ -32,9 +32,10 @@ import org.jboss.logging.Logger; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.internal.CoreLogging; +import org.hibernate.loader.plan2.build.spi.ExpandingCollectionQuerySpace; +import org.hibernate.loader.plan2.build.spi.ExpandingCompositeQuerySpace; import org.hibernate.loader.plan2.build.spi.ExpandingEntityQuerySpace; import org.hibernate.loader.plan2.build.spi.ExpandingQuerySpaces; -import org.hibernate.loader.plan2.spi.CollectionQuerySpace; import org.hibernate.loader.plan2.spi.QuerySpace; import org.hibernate.loader.plan2.spi.QuerySpaceUidNotRegisteredException; import org.hibernate.persister.collection.CollectionPersister; @@ -86,49 +87,91 @@ public class QuerySpacesImpl implements ExpandingQuerySpaces { } @Override - public ExpandingEntityQuerySpace makeEntityQuerySpace(String uid, EntityPersister entityPersister) { - if ( querySpaceByUid.containsKey( uid ) ) { - throw new IllegalStateException( "Encountered duplicate QuerySpace uid : " + uid ); - } + public ExpandingEntityQuerySpace makeRootEntityQuerySpace(String uid, EntityPersister entityPersister) { + final ExpandingEntityQuerySpace space = makeEntityQuerySpace( uid, entityPersister, true ); + roots.add( space ); + return space; + } + + @Override + public ExpandingEntityQuerySpace makeEntityQuerySpace( + String uid, + EntityPersister entityPersister, + boolean canJoinsBeRequired) { + + checkQuerySpaceDoesNotExist( uid ); final EntityQuerySpaceImpl space = new EntityQuerySpaceImpl( entityPersister, uid, this, - true, + canJoinsBeRequired, sessionFactory ); registerQuerySpace( space ); - roots.add( space ); return space; } @Override - public CollectionQuerySpace makeCollectionQuerySpace(String uid, CollectionPersister collectionPersister) { - if ( querySpaceByUid.containsKey( uid ) ) { - throw new IllegalStateException( "Encountered duplicate QuerySpace uid : " + uid ); - } + public ExpandingCollectionQuerySpace makeRootCollectionQuerySpace(String uid, CollectionPersister collectionPersister) { + final ExpandingCollectionQuerySpace space = makeCollectionQuerySpace( uid, collectionPersister, true ); + roots.add( space ); + return space; + } - final CollectionQuerySpaceImpl space = new CollectionQuerySpaceImpl( + @Override + public ExpandingCollectionQuerySpace makeCollectionQuerySpace( + String uid, + CollectionPersister collectionPersister, + boolean canJoinsBeRequired) { + + checkQuerySpaceDoesNotExist( uid ); + + final ExpandingCollectionQuerySpace space = new CollectionQuerySpaceImpl( collectionPersister, uid, this, - true, + canJoinsBeRequired, sessionFactory ); registerQuerySpace( space ); - roots.add( space ); return space; } + @Override + public ExpandingCompositeQuerySpace makeCompositeQuerySpace( + String uid, + CompositePropertyMapping compositePropertyMapping, + boolean canJoinsBeRequired) { + + checkQuerySpaceDoesNotExist( uid ); + + final ExpandingCompositeQuerySpace space = new CompositeQuerySpaceImpl( + compositePropertyMapping, + uid, + this, + canJoinsBeRequired, + sessionFactory + ); + registerQuerySpace( space ); + + return space; + } + + private void checkQuerySpaceDoesNotExist(String uid) { + if ( querySpaceByUid.containsKey( uid ) ) { + throw new IllegalStateException( "Encountered duplicate QuerySpace uid : " + uid ); + } + } + /** * Feeds a QuerySpace into this spaces group. * * @param querySpace The space */ - public void registerQuerySpace(QuerySpace querySpace) { + private void registerQuerySpace(QuerySpace querySpace) { log.debugf( "Adding QuerySpace : uid = %s -> %s]", querySpace.getUid(), diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/AbstractLoadPlanBuildingAssociationVisitationStrategy.java b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/AbstractLoadPlanBuildingAssociationVisitationStrategy.java index 708ce97319..964ec42c08 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/AbstractLoadPlanBuildingAssociationVisitationStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/AbstractLoadPlanBuildingAssociationVisitationStrategy.java @@ -33,6 +33,7 @@ import org.jboss.logging.MDC; import org.hibernate.HibernateException; import org.hibernate.engine.FetchStrategy; import org.hibernate.engine.FetchStyle; +import org.hibernate.engine.FetchTiming; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.internal.util.StringHelper; import org.hibernate.loader.PropertyPath; @@ -184,7 +185,7 @@ public abstract class AbstractLoadPlanBuildingAssociationVisitationStrategy throw new HibernateException( "This strategy does not support root entity returns" ); } - final EntityReturnImpl entityReturn = new EntityReturnImpl( entityDefinition, this ); + final EntityReturnImpl entityReturn = new EntityReturnImpl( entityDefinition, querySpaces ); addRootReturn( entityReturn ); pushToStack( entityReturn ); @@ -335,7 +336,7 @@ public abstract class AbstractLoadPlanBuildingAssociationVisitationStrategy throw new HibernateException( "This strategy does not support root collection returns" ); } - final CollectionReturn collectionReturn = new CollectionReturnImpl( collectionDefinition, this ); + final CollectionReturn collectionReturn = new CollectionReturnImpl( collectionDefinition, querySpaces ); pushToCollectionStack( collectionReturn ); addRootReturn( collectionReturn ); @@ -515,7 +516,7 @@ public abstract class AbstractLoadPlanBuildingAssociationVisitationStrategy throw new HibernateException( "A component cannot be the root of a walk nor a graph" ); } - final CompositeFetch compositeFetch = currentSource().buildCompositeFetch( compositionDefinition, this ); + final CompositeFetch compositeFetch = currentSource().buildCompositeFetch( compositionDefinition ); pushToStack( (ExpandingFetchSource) compositeFetch ); } @@ -622,8 +623,7 @@ public abstract class AbstractLoadPlanBuildingAssociationVisitationStrategy currentSource().buildBidirectionalEntityReference( attributeDefinition, fetchStrategy, - registeredFetchSource( associationKey ).resolveEntityReference(), - this + registeredFetchSource( associationKey ).resolveEntityReference() ); } } @@ -786,12 +786,9 @@ public abstract class AbstractLoadPlanBuildingAssociationVisitationStrategy protected boolean handleAssociationAttribute(AssociationAttributeDefinition attributeDefinition) { // todo : this seems to not be correct for one-to-one final FetchStrategy fetchStrategy = determineFetchStrategy( attributeDefinition ); - if ( fetchStrategy.getStyle() != FetchStyle.JOIN ) { + if ( fetchStrategy.getTiming() != FetchTiming.IMMEDIATE ) { return false; } -// if ( fetchStrategy.getTiming() != FetchTiming.IMMEDIATE ) { -// return false; -// } final ExpandingFetchSource currentSource = currentSource(); currentSource.validateFetchPlan( fetchStrategy, attributeDefinition ); @@ -804,14 +801,13 @@ public abstract class AbstractLoadPlanBuildingAssociationVisitationStrategy if ( nature == AssociationAttributeDefinition.AssociationNature.ENTITY ) { EntityFetch fetch = currentSource.buildEntityFetch( attributeDefinition, - fetchStrategy, - this + fetchStrategy ); pushToStack( (ExpandingFetchSource) fetch ); } else { // Collection - CollectionFetch fetch = currentSource.buildCollectionFetch( attributeDefinition, fetchStrategy, this ); + CollectionFetch fetch = currentSource.buildCollectionFetch( attributeDefinition, fetchStrategy ); pushToCollectionStack( fetch ); } return true; diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/ExpandingCollectionQuerySpace.java b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/ExpandingCollectionQuerySpace.java new file mode 100644 index 0000000000..e15c79c397 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/ExpandingCollectionQuerySpace.java @@ -0,0 +1,44 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2013, 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.loader.plan2.build.spi; + +import org.hibernate.loader.plan2.spi.CollectionQuerySpace; +import org.hibernate.persister.entity.EntityPersister; +import org.hibernate.type.CompositeType; + +/** + * @author Gail Badner + */ +public interface ExpandingCollectionQuerySpace extends CollectionQuerySpace { + + public ExpandingEntityQuerySpace addIndexEntityQuerySpace(final EntityPersister elementPersister); + + public ExpandingCompositeQuerySpace addIndexCompositeQuerySpace(CompositeType compositeType); + + public ExpandingEntityQuerySpace addElementEntityQuerySpace( + final EntityPersister elementPersister); + + public ExpandingCompositeQuerySpace addElementCompositeQuerySpace( + CompositeType compositeType); +} \ No newline at end of file diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/ExpandingCompositeQuerySpace.java b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/ExpandingCompositeQuerySpace.java index 9bf2599610..8c7f1deedd 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/ExpandingCompositeQuerySpace.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/ExpandingCompositeQuerySpace.java @@ -28,5 +28,5 @@ import org.hibernate.loader.plan2.spi.CompositeQuerySpace; /** * @author Gail Badner */ -public interface ExpandingCompositeQuerySpace extends CompositeQuerySpace, ExpandingQuerySpace { +public interface ExpandingCompositeQuerySpace extends CompositeQuerySpace, ExpandingSourceQuerySpace { } diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/ExpandingEntityQuerySpace.java b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/ExpandingEntityQuerySpace.java index f2bf3b8787..95e1ace617 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/ExpandingEntityQuerySpace.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/ExpandingEntityQuerySpace.java @@ -24,12 +24,10 @@ package org.hibernate.loader.plan2.build.spi; import org.hibernate.loader.plan2.spi.EntityQuerySpace; -import org.hibernate.loader.plan2.spi.Join; -import org.hibernate.loader.plan2.spi.JoinDefinedByMetadata; /** * @author Steve Ebersole */ -public interface ExpandingEntityQuerySpace extends EntityQuerySpace, ExpandingQuerySpace { - public JoinDefinedByMetadata makeCompositeIdentifierJoin(); +public interface ExpandingEntityQuerySpace extends EntityQuerySpace, ExpandingSourceQuerySpace { + public ExpandingCompositeQuerySpace makeCompositeIdentifierQuerySpace(); } diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/ExpandingFetchSource.java b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/ExpandingFetchSource.java index 8efcdc25c9..505f7dd99d 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/ExpandingFetchSource.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/ExpandingFetchSource.java @@ -51,22 +51,18 @@ public interface ExpandingFetchSource extends FetchSource { public EntityFetch buildEntityFetch( AssociationAttributeDefinition attributeDefinition, - FetchStrategy fetchStrategy, - LoadPlanBuildingContext loadPlanBuildingContext); + FetchStrategy fetchStrategy); public BidirectionalEntityReference buildBidirectionalEntityReference( AssociationAttributeDefinition attributeDefinition, FetchStrategy fetchStrategy, - EntityReference targetEntityReference, - LoadPlanBuildingContext loadPlanBuildingContext); + EntityReference targetEntityReference); public CompositeFetch buildCompositeFetch( - CompositionDefinition attributeDefinition, - LoadPlanBuildingContext loadPlanBuildingContext); + CompositionDefinition attributeDefinition); public CollectionFetch buildCollectionFetch( AssociationAttributeDefinition attributeDefinition, - FetchStrategy fetchStrategy, - LoadPlanBuildingContext loadPlanBuildingContext); + FetchStrategy fetchStrategy); } diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/ExpandingQuerySpaces.java b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/ExpandingQuerySpaces.java index 836f12984f..1279f7dbff 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/ExpandingQuerySpaces.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/ExpandingQuerySpaces.java @@ -23,7 +23,7 @@ */ package org.hibernate.loader.plan2.build.spi; -import org.hibernate.loader.plan2.spi.CollectionQuerySpace; +import org.hibernate.loader.plan2.build.internal.spaces.CompositePropertyMapping; import org.hibernate.loader.plan2.spi.QuerySpaces; import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.entity.EntityPersister; @@ -34,7 +34,26 @@ import org.hibernate.persister.entity.EntityPersister; public interface ExpandingQuerySpaces extends QuerySpaces { public String generateImplicitUid(); - public ExpandingEntityQuerySpace makeEntityQuerySpace(String uid, EntityPersister entityPersister); + public ExpandingEntityQuerySpace makeRootEntityQuerySpace( + String uid, + EntityPersister entityPersister); - public CollectionQuerySpace makeCollectionQuerySpace(String uid, CollectionPersister collectionPersister); + public ExpandingEntityQuerySpace makeEntityQuerySpace( + String uid, + EntityPersister entityPersister, + boolean canJoinsBeRequired); + + public ExpandingCollectionQuerySpace makeRootCollectionQuerySpace( + String uid, + CollectionPersister collectionPersister); + + public ExpandingCollectionQuerySpace makeCollectionQuerySpace( + String uid, + CollectionPersister collectionPersister, + boolean canJoinsBeRequired); + + public ExpandingCompositeQuerySpace makeCompositeQuerySpace( + String uid, + CompositePropertyMapping compositePropertyMapping, + boolean canJoinsBeRequired); } diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/ExpandingQuerySpace.java b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/ExpandingSourceQuerySpace.java similarity index 78% rename from hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/ExpandingQuerySpace.java rename to hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/ExpandingSourceQuerySpace.java index e98b5ef138..6cedc16c92 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/ExpandingQuerySpace.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan2/build/spi/ExpandingSourceQuerySpace.java @@ -23,7 +23,6 @@ */ package org.hibernate.loader.plan2.build.spi; -import org.hibernate.loader.plan2.spi.JoinDefinedByMetadata; import org.hibernate.loader.plan2.spi.QuerySpace; import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.entity.EntityPersister; @@ -33,20 +32,25 @@ import org.hibernate.persister.walking.spi.CompositionDefinition; /** * @author Steve Ebersole */ -public interface ExpandingQuerySpace extends QuerySpace { +public interface ExpandingSourceQuerySpace extends QuerySpace { - public JoinDefinedByMetadata addCompositeJoin( + public ExpandingCompositeQuerySpace addCompositeQuerySpace( CompositionDefinition compositionDefinition, - String querySpaceUid); + String querySpaceUid, + boolean shouldIncludeJoin); - public JoinDefinedByMetadata addEntityJoin( + public ExpandingEntityQuerySpace addEntityQuerySpace( AttributeDefinition attributeDefinition, EntityPersister persister, String querySpaceUid, - boolean optional); + boolean optional, + boolean shouldIncludeJoin); - public JoinDefinedByMetadata addCollectionJoin( + public ExpandingCollectionQuerySpace addCollectionQuerySpace( AttributeDefinition attributeDefinition, CollectionPersister collectionPersister, - String querySpaceUid); + String querySpaceUid, + boolean shouldIncludeJoin); + + public ExpandingQuerySpaces getExpandingQuerySpaces(); }