HHH-8750 : Move load plan implementations from spi to internal
This commit is contained in:
parent
c188767510
commit
ebedc75e0f
|
@ -150,7 +150,7 @@ public class QuerySpaceTreePrinter {
|
|||
+ StringHelper.join( ", ", collectionReferenceAliases.getCollectionColumnAliases().getSuffixedKeyAliases() )
|
||||
+ "}"
|
||||
);
|
||||
final EntityAliases elementAliases = collectionReferenceAliases.getEntityElementColumnAliases();
|
||||
final EntityAliases elementAliases = collectionReferenceAliases.getEntityElementAliases().getColumnAliases();
|
||||
if ( elementAliases != null ) {
|
||||
printWriter.println(
|
||||
TreePrinterHelper.INSTANCE.generateNodePrefix( depth + detailDepthOffset )
|
||||
|
|
|
@ -175,14 +175,27 @@ public class AliasResolutionContextImpl implements AliasResolutionContext {
|
|||
* </li>
|
||||
* </ul>
|
||||
*
|
||||
* @param uid The query space UID for the collection reference.
|
||||
* @param collectionQuerySpaceUid The query space UID for the collection reference.
|
||||
* @param persister The collection persister for collection reference.
|
||||
* @param elementQuerySpaceUid The query space UID for the collection element if
|
||||
* the element is an entity type; null, otherwise.
|
||||
* @return the generated collection reference aliases.
|
||||
* @throws IllegalArgumentException if the collection element is an entity type and
|
||||
* {@code elementQuerySpaceUid} is null.
|
||||
*
|
||||
* @see org.hibernate.loader.plan.spi.CollectionReference#getQuerySpaceUid()
|
||||
* @see org.hibernate.loader.plan.spi.CollectionReference#getCollectionPersister()
|
||||
*/
|
||||
public CollectionReferenceAliases generateCollectionReferenceAliases(String uid, CollectionPersister persister) {
|
||||
public CollectionReferenceAliases generateCollectionReferenceAliases(
|
||||
String collectionQuerySpaceUid,
|
||||
CollectionPersister persister,
|
||||
String elementQuerySpaceUid) {
|
||||
if ( persister.getElementType().isEntityType() && elementQuerySpaceUid == null ) {
|
||||
throw new IllegalArgumentException(
|
||||
"elementQuerySpaceUid must be non-null for one-to-many or many-to-many associations."
|
||||
);
|
||||
}
|
||||
|
||||
final String manyToManyTableAlias;
|
||||
final String tableAlias;
|
||||
if ( persister.isManyToMany() ) {
|
||||
|
@ -194,15 +207,18 @@ public class AliasResolutionContextImpl implements AliasResolutionContext {
|
|||
tableAlias = createTableAlias( persister.getRole() );
|
||||
}
|
||||
|
||||
final CollectionReferenceAliasesImpl aliases = new CollectionReferenceAliasesImpl(
|
||||
final CollectionReferenceAliases collectionAliases = new CollectionReferenceAliasesImpl(
|
||||
tableAlias,
|
||||
manyToManyTableAlias,
|
||||
createCollectionAliases( persister ),
|
||||
createCollectionElementAliases( persister )
|
||||
);
|
||||
|
||||
registerQuerySpaceAliases( uid, aliases );
|
||||
return aliases;
|
||||
registerQuerySpaceAliases( collectionQuerySpaceUid, collectionAliases );
|
||||
if ( collectionAliases.getEntityElementAliases() != null ) {
|
||||
registerQuerySpaceAliases( elementQuerySpaceUid, collectionAliases.getEntityElementAliases() );
|
||||
}
|
||||
return collectionAliases;
|
||||
}
|
||||
|
||||
private CollectionAliases createCollectionAliases(CollectionPersister collectionPersister) {
|
||||
|
@ -219,7 +235,7 @@ public class AliasResolutionContextImpl implements AliasResolutionContext {
|
|||
}
|
||||
}
|
||||
|
||||
public void registerQuerySpaceAliases(String querySpaceUid, EntityReferenceAliases entityReferenceAliases) {
|
||||
private void registerQuerySpaceAliases(String querySpaceUid, EntityReferenceAliases entityReferenceAliases) {
|
||||
if ( entityReferenceAliasesMap == null ) {
|
||||
entityReferenceAliasesMap = new HashMap<String, EntityReferenceAliases>();
|
||||
}
|
||||
|
@ -227,7 +243,7 @@ public class AliasResolutionContextImpl implements AliasResolutionContext {
|
|||
registerSqlTableAliasMapping( querySpaceUid, entityReferenceAliases.getTableAlias() );
|
||||
}
|
||||
|
||||
public void registerSqlTableAliasMapping(String querySpaceUid, String sqlTableAlias) {
|
||||
private void registerSqlTableAliasMapping(String querySpaceUid, String sqlTableAlias) {
|
||||
if ( querySpaceUidToSqlTableAliasMap == null ) {
|
||||
querySpaceUidToSqlTableAliasMap = new HashMap<String, String>();
|
||||
}
|
||||
|
@ -270,7 +286,7 @@ public class AliasResolutionContextImpl implements AliasResolutionContext {
|
|||
return entityReferenceAliasesMap == null ? null : entityReferenceAliasesMap.get( querySpaceUid );
|
||||
}
|
||||
|
||||
public void registerQuerySpaceAliases(String querySpaceUid, CollectionReferenceAliases collectionReferenceAliases) {
|
||||
private void registerQuerySpaceAliases(String querySpaceUid, CollectionReferenceAliases collectionReferenceAliases) {
|
||||
if ( collectionReferenceAliasesMap == null ) {
|
||||
collectionReferenceAliasesMap = new HashMap<String, CollectionReferenceAliases>();
|
||||
}
|
||||
|
@ -354,17 +370,17 @@ public class AliasResolutionContextImpl implements AliasResolutionContext {
|
|||
+ "suffixed key columns - "
|
||||
+ StringHelper.join( ", ", collectionReferenceAliases.getCollectionColumnAliases().getSuffixedKeyAliases() )
|
||||
);
|
||||
final EntityAliases elementAliases = collectionReferenceAliases.getEntityElementColumnAliases();
|
||||
final EntityReferenceAliases elementAliases = collectionReferenceAliases.getEntityElementAliases();
|
||||
if ( elementAliases != null ) {
|
||||
printWriter.println(
|
||||
TreePrinterHelper.INSTANCE.generateNodePrefix( depth+3 )
|
||||
+ "entity-element alias suffix - " + elementAliases.getSuffix()
|
||||
+ "entity-element alias suffix - " + elementAliases.getColumnAliases().getSuffix()
|
||||
);
|
||||
printWriter.println(
|
||||
TreePrinterHelper.INSTANCE.generateNodePrefix( depth+3 )
|
||||
+ elementAliases.getSuffix()
|
||||
+ elementAliases.getColumnAliases().getSuffix()
|
||||
+ "entity-element suffixed key columns - "
|
||||
+ StringHelper.join( ", ", elementAliases.getSuffixedKeyAliases() )
|
||||
+ StringHelper.join( ", ", elementAliases.getColumnAliases().getSuffixedKeyAliases() )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.hibernate.internal.util.StringHelper;
|
|||
import org.hibernate.loader.CollectionAliases;
|
||||
import org.hibernate.loader.EntityAliases;
|
||||
import org.hibernate.loader.plan.exec.spi.CollectionReferenceAliases;
|
||||
import org.hibernate.loader.plan.exec.spi.EntityReferenceAliases;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
|
@ -35,7 +36,7 @@ public class CollectionReferenceAliasesImpl implements CollectionReferenceAliase
|
|||
private final String tableAlias;
|
||||
private final String manyToManyAssociationTableAlias;
|
||||
private final CollectionAliases collectionAliases;
|
||||
private final EntityAliases entityElementAliases;
|
||||
private final EntityReferenceAliases entityElementAliases;
|
||||
|
||||
public CollectionReferenceAliasesImpl(
|
||||
String tableAlias,
|
||||
|
@ -45,7 +46,9 @@ public class CollectionReferenceAliasesImpl implements CollectionReferenceAliase
|
|||
this.tableAlias = tableAlias;
|
||||
this.manyToManyAssociationTableAlias = manyToManyAssociationTableAlias;
|
||||
this.collectionAliases = collectionAliases;
|
||||
this.entityElementAliases = entityElementAliases;
|
||||
this.entityElementAliases = entityElementAliases == null ?
|
||||
null :
|
||||
new EntityReferenceAliasesImpl( tableAlias, entityElementAliases );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -66,7 +69,7 @@ public class CollectionReferenceAliasesImpl implements CollectionReferenceAliase
|
|||
}
|
||||
|
||||
@Override
|
||||
public EntityAliases getEntityElementColumnAliases() {
|
||||
public EntityReferenceAliases getEntityElementAliases() {
|
||||
return entityElementAliases;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -274,10 +274,6 @@ public class LoadQueryJoinAndFetchProcessor {
|
|||
|
||||
private void renderCollectionJoin(Join join, JoinFragment joinFragment) {
|
||||
final CollectionQuerySpace rightHandSide = (CollectionQuerySpace) join.getRightHandSide();
|
||||
final CollectionReferenceAliases aliases = aliasResolutionContext.generateCollectionReferenceAliases(
|
||||
rightHandSide.getUid(),
|
||||
rightHandSide.getCollectionPersister()
|
||||
);
|
||||
|
||||
// The SQL join to the "collection table" needs to be rendered.
|
||||
//
|
||||
|
@ -319,12 +315,17 @@ public class LoadQueryJoinAndFetchProcessor {
|
|||
)
|
||||
);
|
||||
}
|
||||
aliasResolutionContext.registerQuerySpaceAliases(
|
||||
collectionElementJoin.getRightHandSide().getUid(),
|
||||
new EntityReferenceAliasesImpl(
|
||||
aliases.getElementTableAlias(),
|
||||
aliases.getEntityElementColumnAliases()
|
||||
)
|
||||
aliasResolutionContext.generateCollectionReferenceAliases(
|
||||
rightHandSide.getUid(),
|
||||
rightHandSide.getCollectionPersister(),
|
||||
collectionElementJoin.getRightHandSide().getUid()
|
||||
);
|
||||
}
|
||||
else {
|
||||
aliasResolutionContext.generateCollectionReferenceAliases(
|
||||
rightHandSide.getUid(),
|
||||
rightHandSide.getCollectionPersister(),
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -554,7 +555,7 @@ public class LoadQueryJoinAndFetchProcessor {
|
|||
elementTableAlias,
|
||||
collectionTableAlias,
|
||||
|
||||
aliases.getEntityElementColumnAliases().getSuffix(),
|
||||
aliases.getEntityElementAliases().getColumnAliases().getSuffix(),
|
||||
aliases.getCollectionColumnAliases().getSuffix(),
|
||||
true
|
||||
)
|
||||
|
@ -565,7 +566,7 @@ public class LoadQueryJoinAndFetchProcessor {
|
|||
selectStatementBuilder.appendSelectClauseFragment(
|
||||
elementPersister.selectFragment(
|
||||
elementTableAlias,
|
||||
aliases.getEntityElementColumnAliases().getSuffix()
|
||||
aliases.getEntityElementAliases().getColumnAliases().getSuffix()
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -602,7 +603,7 @@ public class LoadQueryJoinAndFetchProcessor {
|
|||
selectStatementBuilder.appendSelectClauseFragment(
|
||||
elementPersister.selectFragment(
|
||||
aliases.getElementTableAlias(),
|
||||
aliases.getEntityElementColumnAliases().getSuffix()
|
||||
aliases.getEntityElementAliases().getColumnAliases().getSuffix()
|
||||
)
|
||||
);
|
||||
readerCollector.add(
|
||||
|
|
|
@ -97,7 +97,7 @@ public class BasicCollectionLoadQueryDetails extends CollectionLoadQueryDetails
|
|||
selectStatementBuilder.appendSelectClauseFragment(
|
||||
elementPersister.selectFragment(
|
||||
getCollectionReferenceAliases().getElementTableAlias(),
|
||||
getCollectionReferenceAliases().getEntityElementColumnAliases().getSuffix()
|
||||
getCollectionReferenceAliases().getEntityElementAliases().getColumnAliases().getSuffix()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -29,7 +29,6 @@ import java.sql.SQLException;
|
|||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.loader.plan.exec.internal.AliasResolutionContextImpl;
|
||||
import org.hibernate.loader.plan.exec.internal.EntityReferenceAliasesImpl;
|
||||
import org.hibernate.loader.plan.exec.process.internal.CollectionReferenceInitializerImpl;
|
||||
import org.hibernate.loader.plan.exec.process.internal.CollectionReturnReader;
|
||||
import org.hibernate.loader.plan.exec.process.internal.EntityReferenceInitializerImpl;
|
||||
|
@ -71,15 +70,16 @@ public abstract class CollectionLoadQueryDetails extends AbstractLoadQueryDetail
|
|||
buildingParameters,
|
||||
( (QueryableCollection) rootReturn.getCollectionPersister() ).getKeyColumnNames(),
|
||||
rootReturn,
|
||||
// collectionReferenceAliases.getCollectionTableAlias(),
|
||||
// collectionReferenceAliases.getCollectionColumnAliases().getSuffix(),
|
||||
// loadPlan.getQuerySpaces().getQuerySpaceByUid( rootReturn.getQuerySpaceUid() ),
|
||||
// (OuterJoinLoadable) rootReturn.getCollectionPersister(),
|
||||
factory
|
||||
);
|
||||
final String elementUid = rootReturn.getCollectionPersister().getElementType().isEntityType() ?
|
||||
rootReturn.getElementGraph().getQuerySpaceUid() :
|
||||
null;
|
||||
|
||||
this.collectionReferenceAliases = aliasResolutionContext.generateCollectionReferenceAliases(
|
||||
rootReturn.getQuerySpaceUid(),
|
||||
rootReturn.getCollectionPersister()
|
||||
rootReturn.getCollectionPersister(),
|
||||
elementUid
|
||||
);
|
||||
this.readerCollector = new CollectionLoaderReaderCollectorImpl(
|
||||
new CollectionReturnReader( rootReturn ),
|
||||
|
@ -87,16 +87,8 @@ public abstract class CollectionLoadQueryDetails extends AbstractLoadQueryDetail
|
|||
);
|
||||
if ( rootReturn.getCollectionPersister().getElementType().isEntityType() ) {
|
||||
final EntityReference elementEntityReference = rootReturn.getElementGraph().resolveEntityReference();
|
||||
final EntityReferenceAliases elementEntityReferenceAliases = new EntityReferenceAliasesImpl(
|
||||
collectionReferenceAliases.getElementTableAlias(),
|
||||
collectionReferenceAliases.getEntityElementColumnAliases()
|
||||
);
|
||||
aliasResolutionContext.registerQuerySpaceAliases(
|
||||
elementEntityReference.getQuerySpaceUid(),
|
||||
elementEntityReferenceAliases
|
||||
);
|
||||
readerCollector.add(
|
||||
new EntityReferenceInitializerImpl( elementEntityReference, elementEntityReferenceAliases )
|
||||
new EntityReferenceInitializerImpl( elementEntityReference, collectionReferenceAliases.getEntityElementAliases() )
|
||||
);
|
||||
}
|
||||
if ( rootReturn.getCollectionPersister().hasIndex() &&
|
||||
|
|
|
@ -61,9 +61,9 @@ public interface CollectionReferenceAliases {
|
|||
public CollectionAliases getCollectionColumnAliases();
|
||||
|
||||
/**
|
||||
* Obtain the column aliases for the element values when the element of the collection is an entity.
|
||||
* Obtain the entity reference aliases for the element values when the element of the collection is an entity.
|
||||
*
|
||||
* @return The column aliases for the entity element; {@code null} if the collection element is not an entity.
|
||||
* @return The entity reference aliases for the entity element; {@code null} if the collection element is not an entity.
|
||||
*/
|
||||
public EntityAliases getEntityElementColumnAliases();
|
||||
public EntityReferenceAliases getEntityElementAliases();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue