Search in sources :

Example 1 with DomainResultAssembler

use of org.hibernate.sql.results.graph.DomainResultAssembler 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 DomainResultAssembler

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

the class StandardRowReader method readRow.

@Override
public T readRow(RowProcessingState rowProcessingState, JdbcValuesSourceProcessingOptions options) {
    LoadingLogger.LOGGER.trace("StandardRowReader#readRow");
    coordinateInitializers(rowProcessingState);
    final Object[] resultRow = new Object[assemblerCount];
    for (int i = 0; i < assemblerCount; i++) {
        final DomainResultAssembler assembler = resultAssemblers.get(i);
        LoadingLogger.LOGGER.debugf("Calling top-level assembler (%s / %s) : %s", i, assemblerCount, assembler);
        resultRow[i] = assembler.assemble(rowProcessingState, options);
    }
    afterRow(rowProcessingState);
    return rowTransformer.transformRow(resultRow);
}
Also used : DomainResultAssembler(org.hibernate.sql.results.graph.DomainResultAssembler)

Example 3 with DomainResultAssembler

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

the class EntityMappingType method extractConcreteTypeStateValues.

// Customer <- DomesticCustomer <- OtherCustomer
default Object[] extractConcreteTypeStateValues(Map<AttributeMapping, DomainResultAssembler> assemblerMapping, RowProcessingState rowProcessingState) {
    // todo (6.0) : getNumberOfAttributeMappings() needs to be fixed for this to work - bad walking of hierarchy
    final Object[] values = new Object[getNumberOfAttributeMappings()];
    visitStateArrayContributors(attribute -> {
        final DomainResultAssembler assembler = assemblerMapping.get(attribute);
        final Object value;
        if (assembler == null) {
            value = UNFETCHED_PROPERTY;
        } else {
            value = assembler.assemble(rowProcessingState);
        }
        values[attribute.getStateArrayPosition()] = value;
    });
    return values;
}
Also used : DomainResultAssembler(org.hibernate.sql.results.graph.DomainResultAssembler)

Example 4 with DomainResultAssembler

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

the class ResultsHelper method createRowReader.

public static <R> RowReader<R> createRowReader(ExecutionContext executionContext, LockOptions lockOptions, RowTransformer<R> rowTransformer, JdbcValues jdbcValues) {
    final Map<NavigablePath, Initializer> initializerMap = new LinkedHashMap<>();
    final List<Initializer> initializers = new ArrayList<>();
    final SessionFactoryImplementor sessionFactory = executionContext.getSession().getFactory();
    final List<DomainResultAssembler<?>> assemblers = jdbcValues.getValuesMapping().resolveAssemblers(new AssemblerCreationState() {

        @Override
        public LockMode determineEffectiveLockMode(String identificationVariable) {
            return lockOptions.getEffectiveLockMode(identificationVariable);
        }

        @Override
        public Initializer resolveInitializer(NavigablePath navigablePath, ModelPart fetchedModelPart, Supplier<Initializer> producer) {
            final Initializer existing = initializerMap.get(navigablePath);
            if (existing != null) {
                if (fetchedModelPart.getNavigableRole().equals(existing.getInitializedPart().getNavigableRole())) {
                    ResultsLogger.LOGGER.tracef("Returning previously-registered initializer : %s", existing);
                    return existing;
                }
            }
            final Initializer initializer = producer.get();
            ResultsLogger.LOGGER.tracef("Registering initializer : %s", initializer);
            initializerMap.put(navigablePath, initializer);
            initializers.add(initializer);
            return initializer;
        }

        @Override
        public SqlAstCreationContext getSqlAstCreationContext() {
            return sessionFactory;
        }
    });
    logInitializers(initializerMap);
    return new StandardRowReader<>(assemblers, initializers, rowTransformer);
}
Also used : NavigablePath(org.hibernate.query.spi.NavigablePath) ModelPart(org.hibernate.metamodel.mapping.ModelPart) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) ArrayList(java.util.ArrayList) LockMode(org.hibernate.LockMode) AssemblerCreationState(org.hibernate.sql.results.graph.AssemblerCreationState) LinkedHashMap(java.util.LinkedHashMap) DomainResultAssembler(org.hibernate.sql.results.graph.DomainResultAssembler) Initializer(org.hibernate.sql.results.graph.Initializer) SqlAstCreationContext(org.hibernate.sql.ast.spi.SqlAstCreationContext)

Aggregations

DomainResultAssembler (org.hibernate.sql.results.graph.DomainResultAssembler)4 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 LockMode (org.hibernate.LockMode)1 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)1 ModelPart (org.hibernate.metamodel.mapping.ModelPart)1 ToOneAttributeMapping (org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping)1 EntityPersister (org.hibernate.persister.entity.EntityPersister)1 NavigablePath (org.hibernate.query.spi.NavigablePath)1 SqlAstCreationContext (org.hibernate.sql.ast.spi.SqlAstCreationContext)1 AssemblerCreationState (org.hibernate.sql.results.graph.AssemblerCreationState)1 Initializer (org.hibernate.sql.results.graph.Initializer)1 EntityInitializer (org.hibernate.sql.results.graph.entity.EntityInitializer)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