Search in sources :

Example 1 with EntityInitializer

use of org.hibernate.sql.results.graph.entity.EntityInitializer in project hibernate-orm by hibernate.

the class CircularFetchImpl method createAssembler.

@Override
public DomainResultAssembler createAssembler(FetchParentAccess parentAccess, AssemblerCreationState creationState) {
    final DomainResultAssembler resultAssembler = keyResult.createResultAssembler(parentAccess, creationState);
    final EntityInitializer initializer = (EntityInitializer) creationState.resolveInitializer(getNavigablePath(), referencedModelPart, () -> {
        if (timing == FetchTiming.IMMEDIATE) {
            if (selectByUniqueKey) {
                return new EntitySelectFetchByUniqueKeyInitializer(parentAccess, fetchable, getNavigablePath(), entityMappingType.getEntityPersister(), resultAssembler);
            }
            final EntityPersister entityPersister = entityMappingType.getEntityPersister();
            if (entityPersister.isBatchLoadable()) {
                return new BatchEntitySelectFetchInitializer(parentAccess, (ToOneAttributeMapping) referencedModelPart, getReferencedPath(), entityPersister, resultAssembler);
            } else {
                return new EntitySelectFetchInitializer(parentAccess, (ToOneAttributeMapping) referencedModelPart, getReferencedPath(), entityPersister, resultAssembler);
            }
        } else {
            return new EntityDelayedFetchInitializer(parentAccess, getReferencedPath(), fetchable, selectByUniqueKey, resultAssembler);
        }
    });
    return new BiDirectionalFetchAssembler(initializer, fetchable.getJavaType());
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) DomainResultAssembler(org.hibernate.sql.results.graph.DomainResultAssembler) ToOneAttributeMapping(org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping) EntityDelayedFetchInitializer(org.hibernate.sql.results.graph.entity.internal.EntityDelayedFetchInitializer) BatchEntitySelectFetchInitializer(org.hibernate.sql.results.graph.entity.internal.BatchEntitySelectFetchInitializer) EntitySelectFetchInitializer(org.hibernate.sql.results.graph.entity.internal.EntitySelectFetchInitializer) EntityInitializer(org.hibernate.sql.results.graph.entity.EntityInitializer) EntitySelectFetchByUniqueKeyInitializer(org.hibernate.sql.results.graph.entity.internal.EntitySelectFetchByUniqueKeyInitializer) BatchEntitySelectFetchInitializer(org.hibernate.sql.results.graph.entity.internal.BatchEntitySelectFetchInitializer)

Example 2 with EntityInitializer

use of org.hibernate.sql.results.graph.entity.EntityInitializer in project hibernate-orm by hibernate.

the class AbstractEmbeddableInitializer method determineParentInstance.

private Object determineParentInstance(RowProcessingState processingState) {
    // or at least the fetch-parent of the collection could get passed.
    if (fetchParentAccess != null) {
        // the embeddable being initialized is a fetch, so use the fetchParentAccess
        // to get the parent reference
        // 
        // at the moment, this uses the legacy behavior of injecting the "first
        // containing entity" as the parent.  however,
        // todo (6.x) - allow injection of containing composite as parent if
        // it is the direct parent
        final FetchParentAccess firstEntityDescriptorAccess = fetchParentAccess.findFirstEntityDescriptorAccess();
        return firstEntityDescriptorAccess.getInitializedInstance();
    }
    // Otherwise, fallback to determining the parent-initializer by path
    // todo (6.0) - this is the part that should be "subsumed" based on the
    // comment above
    final NavigablePath parentPath = navigablePath.getParent();
    if (parentPath == null) {
        return null;
    }
    final Initializer parentInitializer = processingState.resolveInitializer(parentPath);
    if (parentInitializer instanceof CollectionInitializer) {
        return ((CollectionInitializer) parentInitializer).getCollectionInstance().getOwner();
    }
    if (parentInitializer instanceof EntityInitializer) {
        return ((EntityInitializer) parentInitializer).getEntityInstance();
    }
    throw new NotYetImplementedFor6Exception(getClass());
}
Also used : AbstractFetchParentAccess(org.hibernate.sql.results.graph.AbstractFetchParentAccess) FetchParentAccess(org.hibernate.sql.results.graph.FetchParentAccess) NavigablePath(org.hibernate.query.spi.NavigablePath) EntityInitializer(org.hibernate.sql.results.graph.entity.EntityInitializer) CollectionInitializer(org.hibernate.sql.results.graph.collection.CollectionInitializer) Initializer(org.hibernate.sql.results.graph.Initializer) EntityInitializer(org.hibernate.sql.results.graph.entity.EntityInitializer) CollectionInitializer(org.hibernate.sql.results.graph.collection.CollectionInitializer) NotYetImplementedFor6Exception(org.hibernate.NotYetImplementedFor6Exception)

Example 3 with EntityInitializer

use of org.hibernate.sql.results.graph.entity.EntityInitializer in project hibernate-orm by hibernate.

the class EntityDelayedFetchImpl method createAssembler.

@Override
public DomainResultAssembler createAssembler(FetchParentAccess parentAccess, AssemblerCreationState creationState) {
    final NavigablePath navigablePath = getNavigablePath();
    final EntityInitializer entityInitializer = (EntityInitializer) creationState.resolveInitializer(navigablePath, getEntityValuedModelPart(), () -> new EntityDelayedFetchInitializer(parentAccess, navigablePath, (ToOneAttributeMapping) getEntityValuedModelPart(), selectByUniqueKey, keyResult.createResultAssembler(parentAccess, creationState)));
    return new EntityAssembler(getFetchedMapping().getJavaType(), entityInitializer);
}
Also used : NavigablePath(org.hibernate.query.spi.NavigablePath) EntityInitializer(org.hibernate.sql.results.graph.entity.EntityInitializer)

Aggregations

EntityInitializer (org.hibernate.sql.results.graph.entity.EntityInitializer)3 NavigablePath (org.hibernate.query.spi.NavigablePath)2 NotYetImplementedFor6Exception (org.hibernate.NotYetImplementedFor6Exception)1 ToOneAttributeMapping (org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping)1 EntityPersister (org.hibernate.persister.entity.EntityPersister)1 AbstractFetchParentAccess (org.hibernate.sql.results.graph.AbstractFetchParentAccess)1 DomainResultAssembler (org.hibernate.sql.results.graph.DomainResultAssembler)1 FetchParentAccess (org.hibernate.sql.results.graph.FetchParentAccess)1 Initializer (org.hibernate.sql.results.graph.Initializer)1 CollectionInitializer (org.hibernate.sql.results.graph.collection.CollectionInitializer)1 BatchEntitySelectFetchInitializer (org.hibernate.sql.results.graph.entity.internal.BatchEntitySelectFetchInitializer)1 EntityDelayedFetchInitializer (org.hibernate.sql.results.graph.entity.internal.EntityDelayedFetchInitializer)1 EntitySelectFetchByUniqueKeyInitializer (org.hibernate.sql.results.graph.entity.internal.EntitySelectFetchByUniqueKeyInitializer)1 EntitySelectFetchInitializer (org.hibernate.sql.results.graph.entity.internal.EntitySelectFetchInitializer)1