Search in sources :

Example 6 with NavigablePath

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

the class EntityCollectionPart method createRootTableGroupJoin.

@Override
public LazyTableGroup createRootTableGroupJoin(NavigablePath navigablePath, TableGroup lhs, String explicitSourceAlias, SqlAstJoinType requestedJoinType, boolean fetched, Consumer<Predicate> predicateConsumer, SqlAliasBaseGenerator aliasBaseGenerator, SqlExpressionResolver sqlExpressionResolver, FromClauseAccess fromClauseAccess, SqlAstCreationContext creationContext) {
    final SqlAstJoinType joinType;
    if (requestedJoinType == null) {
        joinType = SqlAstJoinType.INNER;
    } else {
        joinType = requestedJoinType;
    }
    final SqlAliasBase sqlAliasBase = aliasBaseGenerator.createSqlAliasBase(getSqlAliasStem());
    final boolean canUseInnerJoin = joinType == SqlAstJoinType.INNER || lhs.canUseInnerJoins();
    final LazyTableGroup lazyTableGroup = new LazyTableGroup(canUseInnerJoin, navigablePath, fetched, () -> createTableGroupInternal(canUseInnerJoin, navigablePath, fetched, null, sqlAliasBase, sqlExpressionResolver, creationContext), (np, tableExpression) -> {
        NavigablePath path = np.getParent();
        // Fast path
        if (path != null && navigablePath.equals(path)) {
            return targetKeyPropertyNames.contains(np.getUnaliasedLocalName()) && fkDescriptor.getKeyTable().equals(tableExpression);
        }
        final StringBuilder sb = new StringBuilder(np.getFullPath().length());
        sb.append(np.getUnaliasedLocalName());
        while (path != null && !navigablePath.equals(path)) {
            sb.insert(0, '.');
            sb.insert(0, path.getUnaliasedLocalName());
            path = path.getParent();
        }
        return path != null && navigablePath.equals(path) && targetKeyPropertyNames.contains(sb.toString()) && fkDescriptor.getKeyTable().equals(tableExpression);
    }, this, explicitSourceAlias, sqlAliasBase, creationContext.getSessionFactory(), lhs);
    if (predicateConsumer != null) {
        final TableReference keySideTableReference = lhs.resolveTableReference(navigablePath, fkDescriptor.getKeyTable());
        lazyTableGroup.setTableGroupInitializerCallback(tableGroup -> predicateConsumer.accept(fkDescriptor.generateJoinPredicate(tableGroup.getPrimaryTableReference(), keySideTableReference, sqlExpressionResolver, creationContext)));
    }
    return lazyTableGroup;
}
Also used : TableReference(org.hibernate.sql.ast.tree.from.TableReference) NavigablePath(org.hibernate.query.spi.NavigablePath) LazyTableGroup(org.hibernate.sql.ast.tree.from.LazyTableGroup) SqlAstJoinType(org.hibernate.sql.ast.SqlAstJoinType) SqlAliasBase(org.hibernate.sql.ast.spi.SqlAliasBase)

Example 7 with NavigablePath

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

the class EntityVersionMappingImpl method generateFetch.

@Override
public Fetch generateFetch(FetchParent fetchParent, NavigablePath fetchablePath, FetchTiming fetchTiming, boolean selected, String resultVariable, DomainResultCreationState creationState) {
    final SqlAstCreationState sqlAstCreationState = creationState.getSqlAstCreationState();
    final TableGroup tableGroup = sqlAstCreationState.getFromClauseAccess().findTableGroup(fetchParent.getNavigablePath());
    final SqlExpressionResolver sqlExpressionResolver = sqlAstCreationState.getSqlExpressionResolver();
    final TableReference columnTableReference = tableGroup.resolveTableReference(fetchablePath, columnTableExpression);
    final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(sqlExpressionResolver.resolveSqlExpression(SqlExpressionResolver.createColumnReferenceKey(columnTableReference, columnExpression), sqlAstProcessingState -> new ColumnReference(columnTableReference, columnExpression, false, null, null, versionBasicType, sqlAstCreationState.getCreationContext().getSessionFactory())), versionBasicType.getJdbcMapping().getJavaTypeDescriptor(), sqlAstCreationState.getCreationContext().getSessionFactory().getTypeConfiguration());
    return new BasicFetch<>(sqlSelection.getValuesArrayPosition(), fetchParent, fetchablePath, this, null, fetchTiming, creationState);
}
Also used : DomainResultCreationState(org.hibernate.sql.results.graph.DomainResultCreationState) JdbcMapping(org.hibernate.metamodel.mapping.JdbcMapping) BasicType(org.hibernate.type.BasicType) UnsavedValueFactory(org.hibernate.engine.internal.UnsavedValueFactory) RootClass(org.hibernate.mapping.RootClass) ColumnReference(org.hibernate.sql.ast.tree.expression.ColumnReference) JavaType(org.hibernate.type.descriptor.java.JavaType) Clause(org.hibernate.sql.ast.Clause) Supplier(java.util.function.Supplier) BasicFetch(org.hibernate.sql.results.graph.basic.BasicFetch) EntityMappingType(org.hibernate.metamodel.mapping.EntityMappingType) MappingType(org.hibernate.metamodel.mapping.MappingType) TableReference(org.hibernate.sql.ast.tree.from.TableReference) FetchOptions(org.hibernate.sql.results.graph.FetchOptions) BiConsumer(java.util.function.BiConsumer) EntityVersionMapping(org.hibernate.metamodel.mapping.EntityVersionMapping) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection) SqlAstCreationState(org.hibernate.sql.ast.spi.SqlAstCreationState) FetchTiming(org.hibernate.engine.FetchTiming) NavigablePath(org.hibernate.query.spi.NavigablePath) DomainResult(org.hibernate.sql.results.graph.DomainResult) VersionJavaType(org.hibernate.type.descriptor.java.VersionJavaType) Fetch(org.hibernate.sql.results.graph.Fetch) BasicResult(org.hibernate.sql.results.graph.basic.BasicResult) SqlExpressionResolver(org.hibernate.sql.ast.spi.SqlExpressionResolver) NavigableRole(org.hibernate.metamodel.model.domain.NavigableRole) FetchStyle(org.hibernate.engine.FetchStyle) VersionValue(org.hibernate.engine.spi.VersionValue) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) SharedSessionContractImplementor(org.hibernate.engine.spi.SharedSessionContractImplementor) KeyValue(org.hibernate.mapping.KeyValue) IndexedConsumer(org.hibernate.mapping.IndexedConsumer) FetchParent(org.hibernate.sql.results.graph.FetchParent) BasicFetch(org.hibernate.sql.results.graph.basic.BasicFetch) TableReference(org.hibernate.sql.ast.tree.from.TableReference) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) SqlExpressionResolver(org.hibernate.sql.ast.spi.SqlExpressionResolver) SqlAstCreationState(org.hibernate.sql.ast.spi.SqlAstCreationState) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection) ColumnReference(org.hibernate.sql.ast.tree.expression.ColumnReference)

Example 8 with NavigablePath

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

the class SimpleForeignKeyDescriptor method getTableReference.

protected TableReference getTableReference(TableGroup lhs, TableGroup tableGroup, String table) {
    final NavigablePath navigablePath = lhs.getNavigablePath().append(getTargetPart().getFetchableName());
    if (lhs.getPrimaryTableReference().getTableReference(navigablePath, table) != null) {
        return lhs.getPrimaryTableReference();
    } else if (tableGroup.getPrimaryTableReference().getTableReference(navigablePath, table) != null) {
        return tableGroup.getPrimaryTableReference();
    }
    final TableReference tableReference = lhs.resolveTableReference(navigablePath, table);
    if (tableReference != null) {
        return tableReference;
    }
    throw new IllegalStateException("Could not resolve binding for table `" + table + "`");
}
Also used : TableReference(org.hibernate.sql.ast.tree.from.TableReference) NavigablePath(org.hibernate.query.spi.NavigablePath)

Example 9 with NavigablePath

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

the class BasicAttributeMapping method resolveSqlSelection.

private SqlSelection resolveSqlSelection(NavigablePath navigablePath, TableGroup tableGroup, boolean allowFkOptimization, DomainResultCreationState creationState) {
    final SqlExpressionResolver expressionResolver = creationState.getSqlAstCreationState().getSqlExpressionResolver();
    final TableReference tableReference = tableGroup.resolveTableReference(navigablePath, getContainingTableExpression(), allowFkOptimization);
    return expressionResolver.resolveSqlSelection(expressionResolver.resolveSqlExpression(SqlExpressionResolver.createColumnReferenceKey(tableReference, mappedColumnExpression), sqlAstProcessingState -> new ColumnReference(tableReference, this, creationState.getSqlAstCreationState().getCreationContext().getSessionFactory())), valueConverter == null ? getMappedType().getMappedJavaType() : valueConverter.getRelationalJavaType(), creationState.getSqlAstCreationState().getCreationContext().getSessionFactory().getTypeConfiguration());
}
Also used : BasicValuedModelPart(org.hibernate.metamodel.mapping.BasicValuedModelPart) DomainResultCreationState(org.hibernate.sql.results.graph.DomainResultCreationState) JdbcMapping(org.hibernate.metamodel.mapping.JdbcMapping) ColumnReference(org.hibernate.sql.ast.tree.expression.ColumnReference) JavaType(org.hibernate.type.descriptor.java.JavaType) Clause(org.hibernate.sql.ast.Clause) PropertyAccess(org.hibernate.property.access.spi.PropertyAccess) BasicFetch(org.hibernate.sql.results.graph.basic.BasicFetch) EntityMappingType(org.hibernate.metamodel.mapping.EntityMappingType) MappingType(org.hibernate.metamodel.mapping.MappingType) TableReference(org.hibernate.sql.ast.tree.from.TableReference) ValueGeneration(org.hibernate.tuple.ValueGeneration) ConvertibleModelPart(org.hibernate.metamodel.mapping.ConvertibleModelPart) BiConsumer(java.util.function.BiConsumer) ManagedMappingType(org.hibernate.metamodel.mapping.ManagedMappingType) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection) SqlAstCreationState(org.hibernate.sql.ast.spi.SqlAstCreationState) FetchTiming(org.hibernate.engine.FetchTiming) SingularAttributeMapping(org.hibernate.metamodel.mapping.SingularAttributeMapping) NavigablePath(org.hibernate.query.spi.NavigablePath) DomainResult(org.hibernate.sql.results.graph.DomainResult) StateArrayContributorMetadataAccess(org.hibernate.metamodel.mapping.StateArrayContributorMetadataAccess) Fetch(org.hibernate.sql.results.graph.Fetch) BasicResult(org.hibernate.sql.results.graph.basic.BasicResult) SqlExpressionResolver(org.hibernate.sql.ast.spi.SqlExpressionResolver) NavigableRole(org.hibernate.metamodel.model.domain.NavigableRole) FetchStyle(org.hibernate.engine.FetchStyle) SelectableMapping(org.hibernate.metamodel.mapping.SelectableMapping) BasicValueConverter(org.hibernate.metamodel.model.convert.spi.BasicValueConverter) SelectableConsumer(org.hibernate.metamodel.mapping.SelectableConsumer) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) SharedSessionContractImplementor(org.hibernate.engine.spi.SharedSessionContractImplementor) IndexedConsumer(org.hibernate.mapping.IndexedConsumer) FetchParent(org.hibernate.sql.results.graph.FetchParent) TableReference(org.hibernate.sql.ast.tree.from.TableReference) SqlExpressionResolver(org.hibernate.sql.ast.spi.SqlExpressionResolver) ColumnReference(org.hibernate.sql.ast.tree.expression.ColumnReference)

Example 10 with NavigablePath

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

the class CollectionIdentifierDescriptorImpl method generateFetch.

@Override
public Fetch generateFetch(FetchParent fetchParent, NavigablePath fetchablePath, FetchTiming fetchTiming, boolean selected, String resultVariable, DomainResultCreationState creationState) {
    // get the collection TableGroup
    final FromClauseAccess fromClauseAccess = creationState.getSqlAstCreationState().getFromClauseAccess();
    final TableGroup tableGroup = fromClauseAccess.getTableGroup(fetchablePath.getParent());
    final SqlAstCreationState astCreationState = creationState.getSqlAstCreationState();
    final SqlAstCreationContext astCreationContext = astCreationState.getCreationContext();
    final SessionFactoryImplementor sessionFactory = astCreationContext.getSessionFactory();
    final SqlExpressionResolver sqlExpressionResolver = astCreationState.getSqlExpressionResolver();
    final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(sqlExpressionResolver.resolveSqlExpression(SqlExpressionResolver.createColumnReferenceKey(tableGroup.getPrimaryTableReference(), columnName), p -> new ColumnReference(tableGroup.getPrimaryTableReference().getIdentificationVariable(), columnName, false, null, null, type, sessionFactory)), type.getJavaTypeDescriptor(), sessionFactory.getTypeConfiguration());
    return new BasicFetch<>(sqlSelection.getValuesArrayPosition(), fetchParent, fetchablePath, this, null, FetchTiming.IMMEDIATE, creationState);
}
Also used : DomainResultCreationState(org.hibernate.sql.results.graph.DomainResultCreationState) JdbcMapping(org.hibernate.metamodel.mapping.JdbcMapping) BasicType(org.hibernate.type.BasicType) ColumnReference(org.hibernate.sql.ast.tree.expression.ColumnReference) JavaType(org.hibernate.type.descriptor.java.JavaType) CollectionIdentifierDescriptor(org.hibernate.metamodel.mapping.CollectionIdentifierDescriptor) Clause(org.hibernate.sql.ast.Clause) BasicFetch(org.hibernate.sql.results.graph.basic.BasicFetch) EntityMappingType(org.hibernate.metamodel.mapping.EntityMappingType) MappingType(org.hibernate.metamodel.mapping.MappingType) SqlAstCreationContext(org.hibernate.sql.ast.spi.SqlAstCreationContext) FetchOptions(org.hibernate.sql.results.graph.FetchOptions) BiConsumer(java.util.function.BiConsumer) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection) SqlAstCreationState(org.hibernate.sql.ast.spi.SqlAstCreationState) FetchTiming(org.hibernate.engine.FetchTiming) NavigablePath(org.hibernate.query.spi.NavigablePath) DomainResult(org.hibernate.sql.results.graph.DomainResult) Fetch(org.hibernate.sql.results.graph.Fetch) BasicResult(org.hibernate.sql.results.graph.basic.BasicResult) SqlExpressionResolver(org.hibernate.sql.ast.spi.SqlExpressionResolver) NavigableRole(org.hibernate.metamodel.model.domain.NavigableRole) FetchStyle(org.hibernate.engine.FetchStyle) FromClauseAccess(org.hibernate.sql.ast.spi.FromClauseAccess) CollectionPersister(org.hibernate.persister.collection.CollectionPersister) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) SharedSessionContractImplementor(org.hibernate.engine.spi.SharedSessionContractImplementor) IndexedConsumer(org.hibernate.mapping.IndexedConsumer) FetchParent(org.hibernate.sql.results.graph.FetchParent) BasicFetch(org.hibernate.sql.results.graph.basic.BasicFetch) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) FromClauseAccess(org.hibernate.sql.ast.spi.FromClauseAccess) SqlAstCreationContext(org.hibernate.sql.ast.spi.SqlAstCreationContext) SqlExpressionResolver(org.hibernate.sql.ast.spi.SqlExpressionResolver) SqlAstCreationState(org.hibernate.sql.ast.spi.SqlAstCreationState) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection) ColumnReference(org.hibernate.sql.ast.tree.expression.ColumnReference)

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