Search in sources :

Example 66 with NavigablePath

use of org.hibernate.query.spi.NavigablePath 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)

Example 67 with NavigablePath

use of org.hibernate.query.spi.NavigablePath in project hibernate-orm by hibernate.

the class AbstractEntityResultGraphNode method afterInitialize.

@Override
public void afterInitialize(FetchParent fetchParent, DomainResultCreationState creationState) {
    final EntityMappingType entityDescriptor = referencedModelPart.getEntityMappingType();
    final EntityIdentifierMapping identifierMapping = entityDescriptor.getIdentifierMapping();
    final NavigablePath navigablePath = getNavigablePath();
    final TableGroup entityTableGroup = creationState.getSqlAstCreationState().getFromClauseAccess().getTableGroup(navigablePath);
    final EntityIdentifierNavigablePath identifierNavigablePath = new EntityIdentifierNavigablePath(navigablePath, attributeName(identifierMapping));
    if (navigablePath.getParent() == null && !creationState.forceIdentifierSelection()) {
        identifierFetch = null;
        visitIdentifierMapping(identifierNavigablePath, creationState, identifierMapping, entityTableGroup);
    } else {
        identifierFetch = ((Fetchable) identifierMapping).generateFetch(fetchParent, identifierNavigablePath, FetchTiming.IMMEDIATE, true, null, creationState);
    }
    final EntityDiscriminatorMapping discriminatorMapping = entityDescriptor.getDiscriminatorMapping();
    // No need to fetch the discriminator if this type does not have subclasses
    if (discriminatorMapping != null && entityDescriptor.hasSubclasses()) {
        discriminatorFetch = discriminatorMapping.generateFetch(fetchParent, navigablePath.append(EntityDiscriminatorMapping.ROLE_NAME), FetchTiming.IMMEDIATE, true, null, creationState);
    } else {
        discriminatorFetch = null;
    }
    final EntityRowIdMapping rowIdMapping = entityDescriptor.getRowIdMapping();
    if (rowIdMapping == null) {
        rowIdResult = null;
    } else {
        rowIdResult = rowIdMapping.createDomainResult(navigablePath.append(rowIdMapping.getRowIdName()), entityTableGroup, AbstractEntityPersister.ROWID_ALIAS, creationState);
    }
    super.afterInitialize(fetchParent, creationState);
}
Also used : NavigablePath(org.hibernate.query.spi.NavigablePath) EntityIdentifierNavigablePath(org.hibernate.query.sqm.spi.EntityIdentifierNavigablePath) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) EntityIdentifierNavigablePath(org.hibernate.query.sqm.spi.EntityIdentifierNavigablePath) EntityIdentifierMapping(org.hibernate.metamodel.mapping.EntityIdentifierMapping) EntityRowIdMapping(org.hibernate.metamodel.mapping.EntityRowIdMapping) EntityMappingType(org.hibernate.metamodel.mapping.EntityMappingType) EntityDiscriminatorMapping(org.hibernate.metamodel.mapping.EntityDiscriminatorMapping)

Aggregations

NavigablePath (org.hibernate.query.spi.NavigablePath)67 TableGroup (org.hibernate.sql.ast.tree.from.TableGroup)53 TableReference (org.hibernate.sql.ast.tree.from.TableReference)30 PluralTableGroup (org.hibernate.sql.ast.tree.from.PluralTableGroup)28 ColumnReference (org.hibernate.sql.ast.tree.expression.ColumnReference)27 SqlExpressionResolver (org.hibernate.sql.ast.spi.SqlExpressionResolver)24 Fetch (org.hibernate.sql.results.graph.Fetch)23 SqlSelection (org.hibernate.sql.ast.spi.SqlSelection)22 PluralAttributeMapping (org.hibernate.metamodel.mapping.PluralAttributeMapping)21 QuerySpec (org.hibernate.sql.ast.tree.select.QuerySpec)21 FetchTiming (org.hibernate.engine.FetchTiming)20 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)20 Expression (org.hibernate.sql.ast.tree.expression.Expression)20 LazyTableGroup (org.hibernate.sql.ast.tree.from.LazyTableGroup)20 DomainResultCreationState (org.hibernate.sql.results.graph.DomainResultCreationState)20 ModelPart (org.hibernate.metamodel.mapping.ModelPart)19 CorrelatedTableGroup (org.hibernate.sql.ast.tree.from.CorrelatedTableGroup)19 FetchParent (org.hibernate.sql.results.graph.FetchParent)19 ArrayList (java.util.ArrayList)18 BiConsumer (java.util.function.BiConsumer)18