use of org.hibernate.loader.plan.exec.spi.EntityReferenceAliases in project hibernate-orm by hibernate.
the class AbstractCollectionLoadQueryDetails method applyRootReturnSelectFragments.
@Override
protected void applyRootReturnSelectFragments(SelectStatementBuilder selectStatementBuilder) {
if (getRootCollectionReturn().allowIndexJoin() && getQueryableCollection().getIndexType().isEntityType()) {
final EntityReference indexEntityReference = getRootCollectionReturn().getIndexGraph().resolveEntityReference();
final EntityReferenceAliases indexEntityReferenceAliases = getAliasResolutionContext().resolveEntityReferenceAliases(indexEntityReference.getQuerySpaceUid());
selectStatementBuilder.appendSelectClauseFragment(((OuterJoinLoadable) indexEntityReference.getEntityPersister()).selectFragment(indexEntityReferenceAliases.getTableAlias(), indexEntityReferenceAliases.getColumnAliases().getSuffix()));
}
}
use of org.hibernate.loader.plan.exec.spi.EntityReferenceAliases in project hibernate-orm by hibernate.
the class LoadQueryJoinAndFetchProcessor method processEntityFetch.
private void processEntityFetch(SelectStatementBuilder selectStatementBuilder, FetchSource fetchSource, EntityFetch fetch, ReaderCollector readerCollector, FetchStatsImpl fetchStats) {
// todo : still need to think through expressing bi-directionality in the new model...
// if ( BidirectionalEntityFetch.class.isInstance( fetch ) ) {
// log.tracef( "Skipping bi-directional entity fetch [%s]", fetch );
// return;
// }
fetchStats.processingFetch(fetch);
if (!FetchStrategyHelper.isJoinFetched(fetch.getFetchStrategy())) {
// not join fetched, so nothing else to do
return;
}
// First write out the SQL SELECT fragments
final Joinable joinable = (Joinable) fetch.getEntityPersister();
EntityReferenceAliases aliases = aliasResolutionContext.resolveEntityReferenceAliases(fetch.getQuerySpaceUid());
// the null arguments here relate to many-to-many fetches
selectStatementBuilder.appendSelectClauseFragment(joinable.selectFragment(null, null, aliases.getTableAlias(), aliases.getColumnAliases().getSuffix(), null, true));
// process its identifier fetches first (building EntityReferenceInitializers for them if needed)
if (fetch.getIdentifierDescription().hasFetches()) {
final FetchSource entityIdentifierAsFetchSource = (FetchSource) fetch.getIdentifierDescription();
for (Fetch identifierFetch : entityIdentifierAsFetchSource.getFetches()) {
processFetch(selectStatementBuilder, fetch, identifierFetch, readerCollector, fetchStats);
}
}
// build an EntityReferenceInitializers for the incoming fetch itself
readerCollector.add(new EntityReferenceInitializerImpl(fetch, aliases));
// then visit each of our (non-identifier) fetches
processFetches(fetch, selectStatementBuilder, readerCollector, fetchStats);
}
use of org.hibernate.loader.plan.exec.spi.EntityReferenceAliases in project hibernate-orm by hibernate.
the class LoadQueryJoinAndFetchProcessor method renderEntityJoin.
private void renderEntityJoin(Join join, JoinFragment joinFragment) {
final EntityQuerySpace rightHandSide = (EntityQuerySpace) join.getRightHandSide();
// see if there is already aliases registered for this entity query space (collection joins)
EntityReferenceAliases aliases = aliasResolutionContext.resolveEntityReferenceAliases(rightHandSide.getUid());
if (aliases == null) {
aliasResolutionContext.generateEntityReferenceAliases(rightHandSide.getUid(), rightHandSide.getEntityPersister());
}
final Joinable joinable = (Joinable) rightHandSide.getEntityPersister();
addJoins(join, joinFragment, joinable, null);
}
use of org.hibernate.loader.plan.exec.spi.EntityReferenceAliases in project hibernate-orm by hibernate.
the class AliasResolutionContextImpl method generateDetailLines.
private void generateDetailLines(QuerySpace querySpace, int depth, PrintWriter printWriter) {
printWriter.println(TreePrinterHelper.INSTANCE.generateNodePrefix(depth) + querySpace.getUid() + " -> " + extractDetails(querySpace));
printWriter.println(TreePrinterHelper.INSTANCE.generateNodePrefix(depth + 3) + "SQL table alias mapping - " + resolveSqlTableAliasFromQuerySpaceUid(querySpace.getUid()));
final EntityReferenceAliases entityAliases = resolveEntityReferenceAliases(querySpace.getUid());
final CollectionReferenceAliases collectionReferenceAliases = resolveCollectionReferenceAliases(querySpace.getUid());
if (entityAliases != null) {
printWriter.println(TreePrinterHelper.INSTANCE.generateNodePrefix(depth + 3) + "alias suffix - " + entityAliases.getColumnAliases().getSuffix());
printWriter.println(TreePrinterHelper.INSTANCE.generateNodePrefix(depth + 3) + "suffixed key columns - " + String.join(", ", entityAliases.getColumnAliases().getSuffixedKeyAliases()));
}
if (collectionReferenceAliases != null) {
printWriter.println(TreePrinterHelper.INSTANCE.generateNodePrefix(depth + 3) + "alias suffix - " + collectionReferenceAliases.getCollectionColumnAliases().getSuffix());
printWriter.println(TreePrinterHelper.INSTANCE.generateNodePrefix(depth + 3) + "suffixed key columns - " + String.join(", ", collectionReferenceAliases.getCollectionColumnAliases().getSuffixedKeyAliases()));
final EntityReferenceAliases elementAliases = collectionReferenceAliases.getEntityElementAliases();
if (elementAliases != null) {
printWriter.println(TreePrinterHelper.INSTANCE.generateNodePrefix(depth + 3) + "entity-element alias suffix - " + elementAliases.getColumnAliases().getSuffix());
printWriter.println(TreePrinterHelper.INSTANCE.generateNodePrefix(depth + 3) + elementAliases.getColumnAliases().getSuffix() + "entity-element suffixed key columns - " + String.join(", ", elementAliases.getColumnAliases().getSuffixedKeyAliases()));
}
}
}
use of org.hibernate.loader.plan.exec.spi.EntityReferenceAliases in project hibernate-orm by hibernate.
the class QuerySpaceTreePrinter method generateDetailLines.
private void generateDetailLines(QuerySpace querySpace, int depth, AliasResolutionContext aliasResolutionContext, PrintWriter printWriter) {
printWriter.println(TreePrinterHelper.INSTANCE.generateNodePrefix(depth) + extractDetails(querySpace));
if (aliasResolutionContext == null) {
return;
}
printWriter.println(TreePrinterHelper.INSTANCE.generateNodePrefix(depth + detailDepthOffset) + "SQL table alias mapping - " + aliasResolutionContext.resolveSqlTableAliasFromQuerySpaceUid(querySpace.getUid()));
final EntityReferenceAliases entityAliases = aliasResolutionContext.resolveEntityReferenceAliases(querySpace.getUid());
final CollectionReferenceAliases collectionReferenceAliases = aliasResolutionContext.resolveCollectionReferenceAliases(querySpace.getUid());
if (entityAliases != null) {
printWriter.println(TreePrinterHelper.INSTANCE.generateNodePrefix(depth + detailDepthOffset) + "alias suffix - " + entityAliases.getColumnAliases().getSuffix());
printWriter.println(TreePrinterHelper.INSTANCE.generateNodePrefix(depth + detailDepthOffset) + "suffixed key columns - {" + String.join(", ", entityAliases.getColumnAliases().getSuffixedKeyAliases()) + "}");
}
if (collectionReferenceAliases != null) {
printWriter.println(TreePrinterHelper.INSTANCE.generateNodePrefix(depth + detailDepthOffset) + "alias suffix - " + collectionReferenceAliases.getCollectionColumnAliases().getSuffix());
printWriter.println(TreePrinterHelper.INSTANCE.generateNodePrefix(depth + detailDepthOffset) + "suffixed key columns - {" + String.join(", ", collectionReferenceAliases.getCollectionColumnAliases().getSuffixedKeyAliases()) + "}");
final EntityAliases elementAliases = collectionReferenceAliases.getEntityElementAliases() == null ? null : collectionReferenceAliases.getEntityElementAliases().getColumnAliases();
if (elementAliases != null) {
printWriter.println(TreePrinterHelper.INSTANCE.generateNodePrefix(depth + detailDepthOffset) + "entity-element alias suffix - " + elementAliases.getSuffix());
printWriter.println(TreePrinterHelper.INSTANCE.generateNodePrefix(depth + detailDepthOffset) + elementAliases.getSuffix() + "entity-element suffixed key columns - " + String.join(", ", elementAliases.getSuffixedKeyAliases()));
}
}
}
Aggregations