Search in sources :

Example 1 with StandardTableGroup

use of org.hibernate.sql.ast.tree.from.StandardTableGroup in project hibernate-orm by hibernate.

the class InformixSqmToSqlAstConverter method visitQuerySpec.

@Override
public QuerySpec visitQuerySpec(SqmQuerySpec<?> sqmQuerySpec) {
    final boolean needsDummy = this.needsDummyTableGroup;
    this.needsDummyTableGroup = false;
    try {
        final QuerySpec querySpec = super.visitQuerySpec(sqmQuerySpec);
        if (this.needsDummyTableGroup) {
            querySpec.getFromClause().addRoot(new StandardTableGroup(true, null, null, null, new NamedTableReference("(select 1)", "dummy_(x)", false, getCreationContext().getSessionFactory()), null, getCreationContext().getSessionFactory()));
        }
        return querySpec;
    } finally {
        this.needsDummyTableGroup = needsDummy;
    }
}
Also used : StandardTableGroup(org.hibernate.sql.ast.tree.from.StandardTableGroup) NamedTableReference(org.hibernate.sql.ast.tree.from.NamedTableReference) SqmQuerySpec(org.hibernate.query.sqm.tree.select.SqmQuerySpec) QuerySpec(org.hibernate.sql.ast.tree.select.QuerySpec)

Example 2 with StandardTableGroup

use of org.hibernate.sql.ast.tree.from.StandardTableGroup in project hibernate-orm by hibernate.

the class SybaseSqmToSqlAstConverter method visitQuerySpec.

@Override
public QuerySpec visitQuerySpec(SqmQuerySpec<?> sqmQuerySpec) {
    final boolean needsDummy = this.needsDummyTableGroup;
    this.needsDummyTableGroup = false;
    try {
        final QuerySpec querySpec = super.visitQuerySpec(sqmQuerySpec);
        if (this.needsDummyTableGroup) {
            querySpec.getFromClause().addRoot(new StandardTableGroup(true, null, null, null, new NamedTableReference("(select 1)", "dummy_(x)", false, getCreationContext().getSessionFactory()), null, getCreationContext().getSessionFactory()));
        }
        return querySpec;
    } finally {
        this.needsDummyTableGroup = needsDummy;
    }
}
Also used : StandardTableGroup(org.hibernate.sql.ast.tree.from.StandardTableGroup) NamedTableReference(org.hibernate.sql.ast.tree.from.NamedTableReference) SqmQuerySpec(org.hibernate.query.sqm.tree.select.SqmQuerySpec) QuerySpec(org.hibernate.sql.ast.tree.select.QuerySpec)

Example 3 with StandardTableGroup

use of org.hibernate.sql.ast.tree.from.StandardTableGroup in project hibernate-orm by hibernate.

the class IngresSqmToSqlAstConverter method visitQuerySpec.

@Override
public QuerySpec visitQuerySpec(SqmQuerySpec<?> sqmQuerySpec) {
    final boolean needsDummy = this.needsDummyTableGroup;
    this.needsDummyTableGroup = false;
    try {
        final QuerySpec querySpec = super.visitQuerySpec(sqmQuerySpec);
        if (this.needsDummyTableGroup) {
            querySpec.getFromClause().addRoot(new StandardTableGroup(true, null, null, null, new NamedTableReference("(select 1)", "dummy_(x)", false, getCreationContext().getSessionFactory()), null, getCreationContext().getSessionFactory()));
        }
        return querySpec;
    } finally {
        this.needsDummyTableGroup = needsDummy;
    }
}
Also used : StandardTableGroup(org.hibernate.sql.ast.tree.from.StandardTableGroup) NamedTableReference(org.hibernate.sql.ast.tree.from.NamedTableReference) SqmQuerySpec(org.hibernate.query.sqm.tree.select.SqmQuerySpec) QuerySpec(org.hibernate.sql.ast.tree.select.QuerySpec)

Example 4 with StandardTableGroup

use of org.hibernate.sql.ast.tree.from.StandardTableGroup in project hibernate-orm by hibernate.

the class ExecuteWithoutIdTableHelper method createIdMatchingSubQuerySpec.

public static QuerySpec createIdMatchingSubQuerySpec(NavigablePath navigablePath, TableReference rootTableReference, Predicate predicate, EntityPersister rootEntityPersister, SqlExpressionResolver sqlExpressionResolver, SessionFactoryImplementor sessionFactory) {
    /*
		 * `select root_id from root_table where {predicate}
		 */
    final QuerySpec matchingIdSelect = new QuerySpec(false, 1);
    final StandardTableGroup matchingIdSelectTableGroup = new StandardTableGroup(true, navigablePath, rootEntityPersister, rootTableReference.getIdentificationVariable(), rootTableReference, null, sessionFactory);
    matchingIdSelect.getFromClause().addRoot(matchingIdSelectTableGroup);
    rootEntityPersister.getIdentifierMapping().forEachSelectable((columnIndex, selection) -> {
        final ColumnReference columnReference = (ColumnReference) sqlExpressionResolver.resolveSqlExpression(SqlExpressionResolver.createColumnReferenceKey(rootTableReference, selection.getSelectionExpression()), sqlAstProcessingState -> new ColumnReference(rootTableReference, selection, sessionFactory));
        final SqlSelection sqlSelection = new SqlSelectionImpl(// irrelevant
        0, 0, columnReference);
        matchingIdSelect.getSelectClause().addSqlSelection(sqlSelection);
    });
    matchingIdSelect.applyPredicate(predicate);
    return matchingIdSelect;
}
Also used : StandardTableGroup(org.hibernate.sql.ast.tree.from.StandardTableGroup) Predicate(org.hibernate.sql.ast.tree.predicate.Predicate) EntityPersister(org.hibernate.persister.entity.EntityPersister) SqlSelectionImpl(org.hibernate.sql.results.internal.SqlSelectionImpl) NavigablePath(org.hibernate.query.spi.NavigablePath) ColumnReference(org.hibernate.sql.ast.tree.expression.ColumnReference) QuerySpec(org.hibernate.sql.ast.tree.select.QuerySpec) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) StandardTableGroup(org.hibernate.sql.ast.tree.from.StandardTableGroup) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection) SqlExpressionResolver(org.hibernate.sql.ast.spi.SqlExpressionResolver) TableReference(org.hibernate.sql.ast.tree.from.TableReference) SqlSelectionImpl(org.hibernate.sql.results.internal.SqlSelectionImpl) QuerySpec(org.hibernate.sql.ast.tree.select.QuerySpec) ColumnReference(org.hibernate.sql.ast.tree.expression.ColumnReference) SqlSelection(org.hibernate.sql.ast.spi.SqlSelection)

Example 5 with StandardTableGroup

use of org.hibernate.sql.ast.tree.from.StandardTableGroup in project hibernate-orm by hibernate.

the class ExecuteWithTemporaryTableHelper method createIdTableSelectQuerySpec.

public static QuerySpec createIdTableSelectQuerySpec(TemporaryTable idTable, ModelPart fkModelPart, Function<SharedSessionContractImplementor, String> sessionUidAccess, EntityMappingType entityDescriptor, ExecutionContext executionContext) {
    final QuerySpec querySpec = new QuerySpec(false);
    final NamedTableReference idTableReference = new NamedTableReference(idTable.getTableExpression(), TemporaryTable.DEFAULT_ALIAS, true, executionContext.getSession().getFactory());
    final TableGroup idTableGroup = new StandardTableGroup(true, new NavigablePath(idTableReference.getTableExpression()), entityDescriptor, null, idTableReference, null, executionContext.getSession().getFactory());
    querySpec.getFromClause().addRoot(idTableGroup);
    applyIdTableSelections(querySpec, idTableReference, idTable, fkModelPart, executionContext);
    applyIdTableRestrictions(querySpec, idTableReference, idTable, sessionUidAccess, executionContext);
    return querySpec;
}
Also used : StandardTableGroup(org.hibernate.sql.ast.tree.from.StandardTableGroup) NamedTableReference(org.hibernate.sql.ast.tree.from.NamedTableReference) StandardTableGroup(org.hibernate.sql.ast.tree.from.StandardTableGroup) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) NavigablePath(org.hibernate.query.spi.NavigablePath) QuerySpec(org.hibernate.sql.ast.tree.select.QuerySpec)

Aggregations

StandardTableGroup (org.hibernate.sql.ast.tree.from.StandardTableGroup)5 QuerySpec (org.hibernate.sql.ast.tree.select.QuerySpec)5 NamedTableReference (org.hibernate.sql.ast.tree.from.NamedTableReference)4 SqmQuerySpec (org.hibernate.query.sqm.tree.select.SqmQuerySpec)3 NavigablePath (org.hibernate.query.spi.NavigablePath)2 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)1 EntityPersister (org.hibernate.persister.entity.EntityPersister)1 SqlExpressionResolver (org.hibernate.sql.ast.spi.SqlExpressionResolver)1 SqlSelection (org.hibernate.sql.ast.spi.SqlSelection)1 ColumnReference (org.hibernate.sql.ast.tree.expression.ColumnReference)1 TableGroup (org.hibernate.sql.ast.tree.from.TableGroup)1 TableReference (org.hibernate.sql.ast.tree.from.TableReference)1 Predicate (org.hibernate.sql.ast.tree.predicate.Predicate)1 SqlSelectionImpl (org.hibernate.sql.results.internal.SqlSelectionImpl)1