HHH-8750 : Move load plan implementations from spi to internal

This commit is contained in:
Gail Badner 2013-11-27 01:23:46 -08:00
parent c188767510
commit ebedc75e0f
7 changed files with 60 additions and 48 deletions

View File

@ -150,7 +150,7 @@ public class QuerySpaceTreePrinter {
+ StringHelper.join( ", ", collectionReferenceAliases.getCollectionColumnAliases().getSuffixedKeyAliases() ) + StringHelper.join( ", ", collectionReferenceAliases.getCollectionColumnAliases().getSuffixedKeyAliases() )
+ "}" + "}"
); );
final EntityAliases elementAliases = collectionReferenceAliases.getEntityElementColumnAliases(); final EntityAliases elementAliases = collectionReferenceAliases.getEntityElementAliases().getColumnAliases();
if ( elementAliases != null ) { if ( elementAliases != null ) {
printWriter.println( printWriter.println(
TreePrinterHelper.INSTANCE.generateNodePrefix( depth + detailDepthOffset ) TreePrinterHelper.INSTANCE.generateNodePrefix( depth + detailDepthOffset )

View File

@ -175,14 +175,27 @@ public class AliasResolutionContextImpl implements AliasResolutionContext {
* </li> * </li>
* </ul> * </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 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. * @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#getQuerySpaceUid()
* @see org.hibernate.loader.plan.spi.CollectionReference#getCollectionPersister() * @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 manyToManyTableAlias;
final String tableAlias; final String tableAlias;
if ( persister.isManyToMany() ) { if ( persister.isManyToMany() ) {
@ -194,15 +207,18 @@ public class AliasResolutionContextImpl implements AliasResolutionContext {
tableAlias = createTableAlias( persister.getRole() ); tableAlias = createTableAlias( persister.getRole() );
} }
final CollectionReferenceAliasesImpl aliases = new CollectionReferenceAliasesImpl( final CollectionReferenceAliases collectionAliases = new CollectionReferenceAliasesImpl(
tableAlias, tableAlias,
manyToManyTableAlias, manyToManyTableAlias,
createCollectionAliases( persister ), createCollectionAliases( persister ),
createCollectionElementAliases( persister ) createCollectionElementAliases( persister )
); );
registerQuerySpaceAliases( uid, aliases ); registerQuerySpaceAliases( collectionQuerySpaceUid, collectionAliases );
return aliases; if ( collectionAliases.getEntityElementAliases() != null ) {
registerQuerySpaceAliases( elementQuerySpaceUid, collectionAliases.getEntityElementAliases() );
}
return collectionAliases;
} }
private CollectionAliases createCollectionAliases(CollectionPersister collectionPersister) { 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 ) { if ( entityReferenceAliasesMap == null ) {
entityReferenceAliasesMap = new HashMap<String, EntityReferenceAliases>(); entityReferenceAliasesMap = new HashMap<String, EntityReferenceAliases>();
} }
@ -227,7 +243,7 @@ public class AliasResolutionContextImpl implements AliasResolutionContext {
registerSqlTableAliasMapping( querySpaceUid, entityReferenceAliases.getTableAlias() ); registerSqlTableAliasMapping( querySpaceUid, entityReferenceAliases.getTableAlias() );
} }
public void registerSqlTableAliasMapping(String querySpaceUid, String sqlTableAlias) { private void registerSqlTableAliasMapping(String querySpaceUid, String sqlTableAlias) {
if ( querySpaceUidToSqlTableAliasMap == null ) { if ( querySpaceUidToSqlTableAliasMap == null ) {
querySpaceUidToSqlTableAliasMap = new HashMap<String, String>(); querySpaceUidToSqlTableAliasMap = new HashMap<String, String>();
} }
@ -270,7 +286,7 @@ public class AliasResolutionContextImpl implements AliasResolutionContext {
return entityReferenceAliasesMap == null ? null : entityReferenceAliasesMap.get( querySpaceUid ); return entityReferenceAliasesMap == null ? null : entityReferenceAliasesMap.get( querySpaceUid );
} }
public void registerQuerySpaceAliases(String querySpaceUid, CollectionReferenceAliases collectionReferenceAliases) { private void registerQuerySpaceAliases(String querySpaceUid, CollectionReferenceAliases collectionReferenceAliases) {
if ( collectionReferenceAliasesMap == null ) { if ( collectionReferenceAliasesMap == null ) {
collectionReferenceAliasesMap = new HashMap<String, CollectionReferenceAliases>(); collectionReferenceAliasesMap = new HashMap<String, CollectionReferenceAliases>();
} }
@ -354,17 +370,17 @@ public class AliasResolutionContextImpl implements AliasResolutionContext {
+ "suffixed key columns - " + "suffixed key columns - "
+ StringHelper.join( ", ", collectionReferenceAliases.getCollectionColumnAliases().getSuffixedKeyAliases() ) + StringHelper.join( ", ", collectionReferenceAliases.getCollectionColumnAliases().getSuffixedKeyAliases() )
); );
final EntityAliases elementAliases = collectionReferenceAliases.getEntityElementColumnAliases(); final EntityReferenceAliases elementAliases = collectionReferenceAliases.getEntityElementAliases();
if ( elementAliases != null ) { if ( elementAliases != null ) {
printWriter.println( printWriter.println(
TreePrinterHelper.INSTANCE.generateNodePrefix( depth+3 ) TreePrinterHelper.INSTANCE.generateNodePrefix( depth+3 )
+ "entity-element alias suffix - " + elementAliases.getSuffix() + "entity-element alias suffix - " + elementAliases.getColumnAliases().getSuffix()
); );
printWriter.println( printWriter.println(
TreePrinterHelper.INSTANCE.generateNodePrefix( depth+3 ) TreePrinterHelper.INSTANCE.generateNodePrefix( depth+3 )
+ elementAliases.getSuffix() + elementAliases.getColumnAliases().getSuffix()
+ "entity-element suffixed key columns - " + "entity-element suffixed key columns - "
+ StringHelper.join( ", ", elementAliases.getSuffixedKeyAliases() ) + StringHelper.join( ", ", elementAliases.getColumnAliases().getSuffixedKeyAliases() )
); );
} }
} }

View File

@ -27,6 +27,7 @@ import org.hibernate.internal.util.StringHelper;
import org.hibernate.loader.CollectionAliases; import org.hibernate.loader.CollectionAliases;
import org.hibernate.loader.EntityAliases; import org.hibernate.loader.EntityAliases;
import org.hibernate.loader.plan.exec.spi.CollectionReferenceAliases; import org.hibernate.loader.plan.exec.spi.CollectionReferenceAliases;
import org.hibernate.loader.plan.exec.spi.EntityReferenceAliases;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
@ -35,7 +36,7 @@ public class CollectionReferenceAliasesImpl implements CollectionReferenceAliase
private final String tableAlias; private final String tableAlias;
private final String manyToManyAssociationTableAlias; private final String manyToManyAssociationTableAlias;
private final CollectionAliases collectionAliases; private final CollectionAliases collectionAliases;
private final EntityAliases entityElementAliases; private final EntityReferenceAliases entityElementAliases;
public CollectionReferenceAliasesImpl( public CollectionReferenceAliasesImpl(
String tableAlias, String tableAlias,
@ -45,7 +46,9 @@ public class CollectionReferenceAliasesImpl implements CollectionReferenceAliase
this.tableAlias = tableAlias; this.tableAlias = tableAlias;
this.manyToManyAssociationTableAlias = manyToManyAssociationTableAlias; this.manyToManyAssociationTableAlias = manyToManyAssociationTableAlias;
this.collectionAliases = collectionAliases; this.collectionAliases = collectionAliases;
this.entityElementAliases = entityElementAliases; this.entityElementAliases = entityElementAliases == null ?
null :
new EntityReferenceAliasesImpl( tableAlias, entityElementAliases );
} }
@Override @Override
@ -66,7 +69,7 @@ public class CollectionReferenceAliasesImpl implements CollectionReferenceAliase
} }
@Override @Override
public EntityAliases getEntityElementColumnAliases() { public EntityReferenceAliases getEntityElementAliases() {
return entityElementAliases; return entityElementAliases;
} }
} }

View File

@ -274,10 +274,6 @@ public class LoadQueryJoinAndFetchProcessor {
private void renderCollectionJoin(Join join, JoinFragment joinFragment) { private void renderCollectionJoin(Join join, JoinFragment joinFragment) {
final CollectionQuerySpace rightHandSide = (CollectionQuerySpace) join.getRightHandSide(); 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. // The SQL join to the "collection table" needs to be rendered.
// //
@ -319,12 +315,17 @@ public class LoadQueryJoinAndFetchProcessor {
) )
); );
} }
aliasResolutionContext.registerQuerySpaceAliases( aliasResolutionContext.generateCollectionReferenceAliases(
collectionElementJoin.getRightHandSide().getUid(), rightHandSide.getUid(),
new EntityReferenceAliasesImpl( rightHandSide.getCollectionPersister(),
aliases.getElementTableAlias(), collectionElementJoin.getRightHandSide().getUid()
aliases.getEntityElementColumnAliases() );
) }
else {
aliasResolutionContext.generateCollectionReferenceAliases(
rightHandSide.getUid(),
rightHandSide.getCollectionPersister(),
null
); );
} }
@ -554,7 +555,7 @@ public class LoadQueryJoinAndFetchProcessor {
elementTableAlias, elementTableAlias,
collectionTableAlias, collectionTableAlias,
aliases.getEntityElementColumnAliases().getSuffix(), aliases.getEntityElementAliases().getColumnAliases().getSuffix(),
aliases.getCollectionColumnAliases().getSuffix(), aliases.getCollectionColumnAliases().getSuffix(),
true true
) )
@ -565,7 +566,7 @@ public class LoadQueryJoinAndFetchProcessor {
selectStatementBuilder.appendSelectClauseFragment( selectStatementBuilder.appendSelectClauseFragment(
elementPersister.selectFragment( elementPersister.selectFragment(
elementTableAlias, elementTableAlias,
aliases.getEntityElementColumnAliases().getSuffix() aliases.getEntityElementAliases().getColumnAliases().getSuffix()
) )
); );
@ -602,7 +603,7 @@ public class LoadQueryJoinAndFetchProcessor {
selectStatementBuilder.appendSelectClauseFragment( selectStatementBuilder.appendSelectClauseFragment(
elementPersister.selectFragment( elementPersister.selectFragment(
aliases.getElementTableAlias(), aliases.getElementTableAlias(),
aliases.getEntityElementColumnAliases().getSuffix() aliases.getEntityElementAliases().getColumnAliases().getSuffix()
) )
); );
readerCollector.add( readerCollector.add(

View File

@ -97,7 +97,7 @@ public class BasicCollectionLoadQueryDetails extends CollectionLoadQueryDetails
selectStatementBuilder.appendSelectClauseFragment( selectStatementBuilder.appendSelectClauseFragment(
elementPersister.selectFragment( elementPersister.selectFragment(
getCollectionReferenceAliases().getElementTableAlias(), getCollectionReferenceAliases().getElementTableAlias(),
getCollectionReferenceAliases().getEntityElementColumnAliases().getSuffix() getCollectionReferenceAliases().getEntityElementAliases().getColumnAliases().getSuffix()
) )
); );
} }

View File

@ -29,7 +29,6 @@ import java.sql.SQLException;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.StringHelper;
import org.hibernate.loader.plan.exec.internal.AliasResolutionContextImpl; 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.CollectionReferenceInitializerImpl;
import org.hibernate.loader.plan.exec.process.internal.CollectionReturnReader; import org.hibernate.loader.plan.exec.process.internal.CollectionReturnReader;
import org.hibernate.loader.plan.exec.process.internal.EntityReferenceInitializerImpl; import org.hibernate.loader.plan.exec.process.internal.EntityReferenceInitializerImpl;
@ -71,15 +70,16 @@ public abstract class CollectionLoadQueryDetails extends AbstractLoadQueryDetail
buildingParameters, buildingParameters,
( (QueryableCollection) rootReturn.getCollectionPersister() ).getKeyColumnNames(), ( (QueryableCollection) rootReturn.getCollectionPersister() ).getKeyColumnNames(),
rootReturn, rootReturn,
// collectionReferenceAliases.getCollectionTableAlias(),
// collectionReferenceAliases.getCollectionColumnAliases().getSuffix(),
// loadPlan.getQuerySpaces().getQuerySpaceByUid( rootReturn.getQuerySpaceUid() ),
// (OuterJoinLoadable) rootReturn.getCollectionPersister(),
factory factory
); );
final String elementUid = rootReturn.getCollectionPersister().getElementType().isEntityType() ?
rootReturn.getElementGraph().getQuerySpaceUid() :
null;
this.collectionReferenceAliases = aliasResolutionContext.generateCollectionReferenceAliases( this.collectionReferenceAliases = aliasResolutionContext.generateCollectionReferenceAliases(
rootReturn.getQuerySpaceUid(), rootReturn.getQuerySpaceUid(),
rootReturn.getCollectionPersister() rootReturn.getCollectionPersister(),
elementUid
); );
this.readerCollector = new CollectionLoaderReaderCollectorImpl( this.readerCollector = new CollectionLoaderReaderCollectorImpl(
new CollectionReturnReader( rootReturn ), new CollectionReturnReader( rootReturn ),
@ -87,16 +87,8 @@ public abstract class CollectionLoadQueryDetails extends AbstractLoadQueryDetail
); );
if ( rootReturn.getCollectionPersister().getElementType().isEntityType() ) { if ( rootReturn.getCollectionPersister().getElementType().isEntityType() ) {
final EntityReference elementEntityReference = rootReturn.getElementGraph().resolveEntityReference(); final EntityReference elementEntityReference = rootReturn.getElementGraph().resolveEntityReference();
final EntityReferenceAliases elementEntityReferenceAliases = new EntityReferenceAliasesImpl(
collectionReferenceAliases.getElementTableAlias(),
collectionReferenceAliases.getEntityElementColumnAliases()
);
aliasResolutionContext.registerQuerySpaceAliases(
elementEntityReference.getQuerySpaceUid(),
elementEntityReferenceAliases
);
readerCollector.add( readerCollector.add(
new EntityReferenceInitializerImpl( elementEntityReference, elementEntityReferenceAliases ) new EntityReferenceInitializerImpl( elementEntityReference, collectionReferenceAliases.getEntityElementAliases() )
); );
} }
if ( rootReturn.getCollectionPersister().hasIndex() && if ( rootReturn.getCollectionPersister().hasIndex() &&

View File

@ -61,9 +61,9 @@ public interface CollectionReferenceAliases {
public CollectionAliases getCollectionColumnAliases(); 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();
} }