Search in sources :

Example 1 with EntityReferenceAliases

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()));
    }
}
Also used : EntityReferenceAliases(org.hibernate.loader.plan.exec.spi.EntityReferenceAliases) EntityReference(org.hibernate.loader.plan.spi.EntityReference)

Example 2 with EntityReferenceAliases

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);
}
Also used : Fetch(org.hibernate.loader.plan.spi.Fetch) EntityFetch(org.hibernate.loader.plan.spi.EntityFetch) CollectionAttributeFetch(org.hibernate.loader.plan.spi.CollectionAttributeFetch) FetchSource(org.hibernate.loader.plan.spi.FetchSource) EntityReferenceAliases(org.hibernate.loader.plan.exec.spi.EntityReferenceAliases) Joinable(org.hibernate.persister.entity.Joinable) EntityReferenceInitializerImpl(org.hibernate.loader.plan.exec.process.internal.EntityReferenceInitializerImpl)

Example 3 with EntityReferenceAliases

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);
}
Also used : EntityReferenceAliases(org.hibernate.loader.plan.exec.spi.EntityReferenceAliases) Joinable(org.hibernate.persister.entity.Joinable) EntityQuerySpace(org.hibernate.loader.plan.spi.EntityQuerySpace)

Example 4 with EntityReferenceAliases

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()));
        }
    }
}
Also used : EntityReferenceAliases(org.hibernate.loader.plan.exec.spi.EntityReferenceAliases) CollectionReferenceAliases(org.hibernate.loader.plan.exec.spi.CollectionReferenceAliases)

Example 5 with EntityReferenceAliases

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()));
        }
    }
}
Also used : EntityReferenceAliases(org.hibernate.loader.plan.exec.spi.EntityReferenceAliases) EntityAliases(org.hibernate.loader.EntityAliases) CollectionReferenceAliases(org.hibernate.loader.plan.exec.spi.CollectionReferenceAliases)

Aggregations

EntityReferenceAliases (org.hibernate.loader.plan.exec.spi.EntityReferenceAliases)5 CollectionReferenceAliases (org.hibernate.loader.plan.exec.spi.CollectionReferenceAliases)2 Joinable (org.hibernate.persister.entity.Joinable)2 EntityAliases (org.hibernate.loader.EntityAliases)1 EntityReferenceInitializerImpl (org.hibernate.loader.plan.exec.process.internal.EntityReferenceInitializerImpl)1 CollectionAttributeFetch (org.hibernate.loader.plan.spi.CollectionAttributeFetch)1 EntityFetch (org.hibernate.loader.plan.spi.EntityFetch)1 EntityQuerySpace (org.hibernate.loader.plan.spi.EntityQuerySpace)1 EntityReference (org.hibernate.loader.plan.spi.EntityReference)1 Fetch (org.hibernate.loader.plan.spi.Fetch)1 FetchSource (org.hibernate.loader.plan.spi.FetchSource)1