HHH-13059 Partially revert HHH-12594

The first commit was on the safe side, we decided to go the extra mile
and that was a mistake as we missed all the consequences.

The new issue is about having a shared ReaderCollector: we add the info
there for each batch which leads to collecting the elements several
times.

This reverts commit a19fc84320.

HHH-13059 : Correct Javadoc
(cherry picked from commit e6286e04f4)
This commit is contained in:
Guillaume Smet 2019-01-09 12:51:43 +01:00 committed by Gail Badner
parent 7047119061
commit 4a564ab45a
3 changed files with 37 additions and 96 deletions

View File

@ -40,7 +40,6 @@ public abstract class AbstractLoadQueryDetails implements LoadQueryDetails {
private final String[] keyColumnNames;
private final Return rootReturn;
private final LoadQueryJoinAndFetchProcessor queryProcessor;
private final QueryBuildingParameters buildingParameters;
private String sqlStatement;
private ResultSetProcessor resultSetProcessor;
@ -59,30 +58,7 @@ public abstract class AbstractLoadQueryDetails implements LoadQueryDetails {
this.keyColumnNames = keyColumnNames;
this.rootReturn = rootReturn;
this.loadPlan = loadPlan;
this.queryProcessor = new LoadQueryJoinAndFetchProcessor(
aliasResolutionContext, buildingParameters.getQueryInfluencers(), factory
);
this.buildingParameters = buildingParameters;
}
/**
* Constructs an AbstractLoadQueryDetails object from an initial object and new building parameters,
* with the guarantee that only batch size changed between the initial parameters and the new ones.
*
* @param initialLoadQueryDetails The initial object to be copied
* @param buildingParameters The new building parameters, with only the batch size being different
* from the parameters used in the initial object.
*/
protected AbstractLoadQueryDetails(
AbstractLoadQueryDetails initialLoadQueryDetails,
QueryBuildingParameters buildingParameters) {
this.keyColumnNames = initialLoadQueryDetails.keyColumnNames;
this.rootReturn = initialLoadQueryDetails.rootReturn;
this.loadPlan = initialLoadQueryDetails.loadPlan;
this.queryProcessor = new LoadQueryJoinAndFetchProcessor(
initialLoadQueryDetails.queryProcessor, buildingParameters.getQueryInfluencers()
);
this.buildingParameters = buildingParameters;
this.queryProcessor = new LoadQueryJoinAndFetchProcessor( aliasResolutionContext, buildingParameters, factory );
}
protected QuerySpace getQuerySpace(String querySpaceUid) {
@ -108,7 +84,7 @@ public abstract class AbstractLoadQueryDetails implements LoadQueryDetails {
}
protected final QueryBuildingParameters getQueryBuildingParameters() {
return buildingParameters;
return queryProcessor.getQueryBuildingParameters();
}
protected final SessionFactoryImplementor getSessionFactory() {

View File

@ -85,24 +85,17 @@ public class EntityLoadQueryDetails extends AbstractLoadQueryDetails {
generate();
}
/**
* Constructs an EntityLoadQueryDetails object from an initial object and new building parameters,
* with the guarantee that only batch size changed between the initial parameters and the new ones.
*
* @param initialEntityLoadQueryDetails The initial object to be copied
* @param buildingParameters The new building parameters, with only the batch size being different
* from the parameters used in the initial object.
*/
protected EntityLoadQueryDetails(
EntityLoadQueryDetails initialEntityLoadQueryDetails,
QueryBuildingParameters buildingParameters) {
super(
initialEntityLoadQueryDetails,
buildingParameters
this(
initialEntityLoadQueryDetails.getLoadPlan(),
initialEntityLoadQueryDetails.getKeyColumnNames(),
new AliasResolutionContextImpl( initialEntityLoadQueryDetails.getSessionFactory() ),
(EntityReturn) initialEntityLoadQueryDetails.getRootReturn(),
buildingParameters,
initialEntityLoadQueryDetails.getSessionFactory()
);
this.entityReferenceAliases = initialEntityLoadQueryDetails.entityReferenceAliases;
this.readerCollector = initialEntityLoadQueryDetails.readerCollector;
generate();
}
public boolean hasCollectionInitializers() {

View File

@ -13,7 +13,6 @@ import java.util.Set;
import org.hibernate.AssertionFailure;
import org.hibernate.engine.FetchStyle;
import org.hibernate.engine.FetchTiming;
import org.hibernate.engine.spi.LoadQueryInfluencers;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.util.StringHelper;
@ -21,6 +20,7 @@ import org.hibernate.loader.plan.exec.process.internal.CollectionReferenceInitia
import org.hibernate.loader.plan.exec.process.internal.EntityReferenceInitializerImpl;
import org.hibernate.loader.plan.exec.process.spi.ReaderCollector;
import org.hibernate.loader.plan.exec.query.internal.SelectStatementBuilder;
import org.hibernate.loader.plan.exec.query.spi.QueryBuildingParameters;
import org.hibernate.loader.plan.exec.spi.AliasResolutionContext;
import org.hibernate.loader.plan.exec.spi.CollectionReferenceAliases;
import org.hibernate.loader.plan.exec.spi.EntityReferenceAliases;
@ -66,51 +66,34 @@ import org.jboss.logging.Logger;
public class LoadQueryJoinAndFetchProcessor {
private static final Logger LOG = CoreLogging.logger( LoadQueryJoinAndFetchProcessor.class );
private final AliasResolutionContext aliasResolutionContext;
private final AliasResolutionContextImpl mutableAliasResolutionContext;
private final LoadQueryInfluencers queryInfluencers;
private final AliasResolutionContextImpl aliasResolutionContext;
private final QueryBuildingParameters buildingParameters;
private final SessionFactoryImplementor factory;
/**
* Instantiates a LoadQueryJoinAndFetchProcessor with the given information
*
* @param mutableAliasResolutionContext
* @param queryInfluencers
* @param aliasResolutionContext
* @param buildingParameters
* @param factory
*/
public LoadQueryJoinAndFetchProcessor(
AliasResolutionContextImpl mutableAliasResolutionContext,
LoadQueryInfluencers queryInfluencers,
AliasResolutionContextImpl aliasResolutionContext,
QueryBuildingParameters buildingParameters,
SessionFactoryImplementor factory) {
this.aliasResolutionContext = mutableAliasResolutionContext;
this.mutableAliasResolutionContext = mutableAliasResolutionContext;
this.queryInfluencers = queryInfluencers;
this.aliasResolutionContext = aliasResolutionContext;
this.buildingParameters = buildingParameters;
this.factory = factory;
}
/**
* Instantiates a LoadQueryJoinAndFetchProcessor from an initial object and new query influencers.
*
* Aliases are considered already contributed to the initial objects alias resolution context
* and won't be added again.
*
* @param initialLoadQueryJoinAndFetchProcessor The initial object to be copied
* @param queryInfluencers The new query influencers
*/
public LoadQueryJoinAndFetchProcessor(
LoadQueryJoinAndFetchProcessor initialLoadQueryJoinAndFetchProcessor,
LoadQueryInfluencers queryInfluencers) {
this.aliasResolutionContext = initialLoadQueryJoinAndFetchProcessor.aliasResolutionContext;
// Do not change the alias resolution context, it should be pre-populated
this.mutableAliasResolutionContext = null;
this.queryInfluencers = queryInfluencers;
this.factory = initialLoadQueryJoinAndFetchProcessor.factory;
}
public AliasResolutionContext getAliasResolutionContext() {
return aliasResolutionContext;
}
public QueryBuildingParameters getQueryBuildingParameters() {
return buildingParameters;
}
public SessionFactoryImplementor getSessionFactory() {
return factory;
}
@ -182,12 +165,7 @@ public class LoadQueryJoinAndFetchProcessor {
);
}
if ( mutableAliasResolutionContext != null ) {
mutableAliasResolutionContext.registerCompositeQuerySpaceUidResolution(
rightHandSideUid,
leftHandSideTableAlias
);
}
aliasResolutionContext.registerCompositeQuerySpaceUidResolution( rightHandSideUid, leftHandSideTableAlias );
}
private void renderEntityJoin(Join join, JoinFragment joinFragment) {
@ -195,8 +173,8 @@ public class LoadQueryJoinAndFetchProcessor {
// see if there is already aliases registered for this entity query space (collection joins)
EntityReferenceAliases aliases = aliasResolutionContext.resolveEntityReferenceAliases( rightHandSide.getUid() );
if ( aliases == null && mutableAliasResolutionContext != null ) {
mutableAliasResolutionContext.generateEntityReferenceAliases(
if ( aliases == null ) {
aliasResolutionContext.generateEntityReferenceAliases(
rightHandSide.getUid(),
rightHandSide.getEntityPersister()
);
@ -227,10 +205,10 @@ public class LoadQueryJoinAndFetchProcessor {
// calls to the Joinable.filterFragment() method where the Joinable is either the entity or
// collection persister
final String filter = associationType!=null?
associationType.getOnCondition( rhsTableAlias, factory, queryInfluencers.getEnabledFilters() ):
associationType.getOnCondition( rhsTableAlias, factory, buildingParameters.getQueryInfluencers().getEnabledFilters() ):
joinable.filterFragment(
rhsTableAlias,
queryInfluencers.getEnabledFilters()
buildingParameters.getQueryInfluencers().getEnabledFilters()
);
if ( StringHelper.isEmpty( withClause ) && StringHelper.isEmpty( filter ) ) {
@ -317,19 +295,7 @@ public class LoadQueryJoinAndFetchProcessor {
private void renderCollectionJoin(Join join, JoinFragment joinFragment) {
final CollectionQuerySpace rightHandSide = (CollectionQuerySpace) join.getRightHandSide();
if ( mutableAliasResolutionContext != null ) {
registerCollectionJoinAliases( mutableAliasResolutionContext, rightHandSide );
}
addJoins(
join,
joinFragment,
(Joinable) rightHandSide.getCollectionPersister(),
null
);
}
private void registerCollectionJoinAliases(AliasResolutionContextImpl mutableAliasResolutionContext,
CollectionQuerySpace rightHandSide) {
// The SQL join to the "collection table" needs to be rendered.
//
// In the case of a basic collection, that's the only join needed.
@ -385,14 +351,14 @@ public class LoadQueryJoinAndFetchProcessor {
)
);
}
mutableAliasResolutionContext.generateCollectionReferenceAliases(
aliasResolutionContext.generateCollectionReferenceAliases(
rightHandSide.getUid(),
rightHandSide.getCollectionPersister(),
collectionElementJoin.getRightHandSide().getUid()
);
}
else {
mutableAliasResolutionContext.generateCollectionReferenceAliases(
aliasResolutionContext.generateCollectionReferenceAliases(
rightHandSide.getUid(),
rightHandSide.getCollectionPersister(),
null
@ -412,11 +378,17 @@ public class LoadQueryJoinAndFetchProcessor {
)
);
}
mutableAliasResolutionContext.generateEntityReferenceAliases(
aliasResolutionContext.generateEntityReferenceAliases(
collectionIndexJoin.getRightHandSide().getUid(),
rightHandSide.getCollectionPersister().getIndexDefinition().toEntityDefinition().getEntityPersister()
);
}
addJoins(
join,
joinFragment,
(Joinable) rightHandSide.getCollectionPersister(),
null
);
}
private void renderManyToManyJoin(
@ -447,7 +419,7 @@ public class LoadQueryJoinAndFetchProcessor {
final CollectionPersister persister = leftHandSide.getCollectionPersister();
manyToManyFilter = persister.getManyToManyFilterFragment(
entityTableAlias,
queryInfluencers.getEnabledFilters()
buildingParameters.getQueryInfluencers().getEnabledFilters()
);
}
else {