Search in sources :

Example 16 with Expression

use of org.hibernate.sql.ast.tree.expression.Expression in project hibernate-orm by hibernate.

the class AbstractSqlAstTranslator method getSelectItemsToInline.

private BitSet getSelectItemsToInline() {
    final QuerySpec querySpec = (QuerySpec) getQueryPartStack().getCurrent();
    final List<SqlSelection> sqlSelections = querySpec.getSelectClause().getSqlSelections();
    final BitSet bitSet = new BitSet(sqlSelections.size());
    for (Expression groupByClauseExpression : querySpec.getGroupByClauseExpressions()) {
        final SqlSelectionExpression selectItemReference = getSelectItemReference(groupByClauseExpression);
        if (selectItemReference != null) {
            bitSet.set(sqlSelections.indexOf(selectItemReference.getSelection()));
        }
    }
    return bitSet;
}
Also used : Expression(org.hibernate.sql.ast.tree.expression.Expression) BinaryArithmeticExpression(org.hibernate.sql.ast.tree.expression.BinaryArithmeticExpression) SelfRenderingExpression(org.hibernate.sql.ast.tree.expression.SelfRenderingExpression) OrderedSetAggregateFunctionExpression(org.hibernate.sql.ast.tree.expression.OrderedSetAggregateFunctionExpression) CaseSimpleExpression(org.hibernate.sql.ast.tree.expression.CaseSimpleExpression) SqlSelectionExpression(org.hibernate.sql.ast.tree.expression.SqlSelectionExpression) CaseSearchedExpression(org.hibernate.sql.ast.tree.expression.CaseSearchedExpression) ModifiedSubQueryExpression(org.hibernate.sql.ast.tree.expression.ModifiedSubQueryExpression) BitSet(java.util.BitSet) QuerySpec(org.hibernate.sql.ast.tree.select.QuerySpec) SqlSelectionExpression(org.hibernate.sql.ast.tree.expression.SqlSelectionExpression)

Example 17 with Expression

use of org.hibernate.sql.ast.tree.expression.Expression in project hibernate-orm by hibernate.

the class ExpressionReplacementWalker method visitInListPredicate.

@Override
public void visitInListPredicate(InListPredicate inListPredicate) {
    final Expression testExpression = replaceExpression(inListPredicate.getTestExpression());
    List<Expression> items = null;
    final List<Expression> listExpressions = inListPredicate.getListExpressions();
    for (int i = 0; i < listExpressions.size(); i++) {
        final Expression listExpression = listExpressions.get(i);
        final Expression newListExpression = replaceExpression(listExpression);
        if (newListExpression != listExpression) {
            if (items == null) {
                items = new ArrayList<>(listExpressions);
            }
            items.set(i, newListExpression);
        }
    }
    if (testExpression != inListPredicate.getTestExpression() || items != null) {
        returnedNode = new InListPredicate(testExpression, items == null ? listExpressions : items, inListPredicate.isNegated(), inListPredicate.getExpressionType());
    } else {
        returnedNode = inListPredicate;
    }
}
Also used : Expression(org.hibernate.sql.ast.tree.expression.Expression) CaseSimpleExpression(org.hibernate.sql.ast.tree.expression.CaseSimpleExpression) BinaryArithmeticExpression(org.hibernate.sql.ast.tree.expression.BinaryArithmeticExpression) SqlSelectionExpression(org.hibernate.sql.ast.tree.expression.SqlSelectionExpression) CaseSearchedExpression(org.hibernate.sql.ast.tree.expression.CaseSearchedExpression) ModifiedSubQueryExpression(org.hibernate.sql.ast.tree.expression.ModifiedSubQueryExpression) SelfRenderingExpression(org.hibernate.sql.ast.tree.expression.SelfRenderingExpression) InListPredicate(org.hibernate.sql.ast.tree.predicate.InListPredicate)

Example 18 with Expression

use of org.hibernate.sql.ast.tree.expression.Expression in project hibernate-orm by hibernate.

the class ColumnReference method apply.

@Override
public void apply(QuerySpec ast, TableGroup tableGroup, String collation, String modelPartName, SortOrder sortOrder, NullPrecedence nullPrecedence, SqlAstCreationState creationState) {
    final Expression expression = resolve(ast, tableGroup, modelPartName, creationState);
    // SQL Server even reports a query error in this case
    if (ast.hasSortSpecifications()) {
        for (SortSpecification sortSpecification : ast.getSortSpecifications()) {
            if (sortSpecification.getSortExpression() == expression) {
                return;
            }
        }
    }
    final Expression sortExpression = OrderingExpression.applyCollation(expression, collation, creationState);
    ast.addSortSpecification(new SortSpecification(sortExpression, sortOrder, nullPrecedence));
}
Also used : Expression(org.hibernate.sql.ast.tree.expression.Expression) SortSpecification(org.hibernate.sql.ast.tree.select.SortSpecification)

Example 19 with Expression

use of org.hibernate.sql.ast.tree.expression.Expression in project hibernate-orm by hibernate.

the class SelfRenderingOrderingExpression method apply.

@Override
public void apply(QuerySpec ast, TableGroup tableGroup, String collation, String modelPartName, SortOrder sortOrder, NullPrecedence nullPrecedence, SqlAstCreationState creationState) {
    final Expression expression = resolve(ast, tableGroup, modelPartName, creationState);
    // SQL Server even reports a query error in this case
    if (ast.hasSortSpecifications()) {
        for (SortSpecification sortSpecification : ast.getSortSpecifications()) {
            if (sortSpecification.getSortExpression() == expression) {
                return;
            }
        }
    }
    final Expression sortExpression = OrderingExpression.applyCollation(expression, collation, creationState);
    ast.addSortSpecification(new SortSpecification(sortExpression, sortOrder, nullPrecedence));
}
Also used : SelfRenderingSqlFragmentExpression(org.hibernate.sql.ast.tree.expression.SelfRenderingSqlFragmentExpression) Expression(org.hibernate.sql.ast.tree.expression.Expression) SortSpecification(org.hibernate.sql.ast.tree.select.SortSpecification)

Example 20 with Expression

use of org.hibernate.sql.ast.tree.expression.Expression in project hibernate-orm by hibernate.

the class SimpleNaturalIdLoader method applyNaturalIdRestriction.

@Override
protected void applyNaturalIdRestriction(Object bindValue, TableGroup rootTableGroup, Consumer<Predicate> predicateConsumer, BiConsumer<JdbcParameter, JdbcParameterBinding> jdbcParameterConsumer, LoaderSqlAstCreationState sqlAstCreationState, SharedSessionContractImplementor session) {
    if (bindValue == null) {
        naturalIdMapping().getAttribute().forEachSelectable((index, selectable) -> {
            final Expression columnReference = resolveColumnReference(rootTableGroup, selectable, sqlAstCreationState.getSqlExpressionResolver(), session.getFactory());
            predicateConsumer.accept(new NullnessPredicate(columnReference));
        });
    } else {
        naturalIdMapping().getAttribute().breakDownJdbcValues(bindValue, (jdbcValue, jdbcValueMapping) -> {
            final Expression columnReference = resolveColumnReference(rootTableGroup, jdbcValueMapping, sqlAstCreationState.getSqlExpressionResolver(), session.getFactory());
            if (jdbcValue == null) {
                predicateConsumer.accept(new NullnessPredicate(columnReference));
            } else {
                final JdbcParameter jdbcParameter = new JdbcParameterImpl(jdbcValueMapping.getJdbcMapping());
                final ComparisonPredicate predicate = new ComparisonPredicate(columnReference, ComparisonOperator.EQUAL, jdbcParameter);
                predicateConsumer.accept(predicate);
                jdbcParameterConsumer.accept(jdbcParameter, new JdbcParameterBindingImpl(jdbcValueMapping.getJdbcMapping(), jdbcValue));
            }
        }, session);
    }
}
Also used : Expression(org.hibernate.sql.ast.tree.expression.Expression) JdbcParameter(org.hibernate.sql.ast.tree.expression.JdbcParameter) JdbcParameterBindingImpl(org.hibernate.sql.exec.internal.JdbcParameterBindingImpl) NullnessPredicate(org.hibernate.sql.ast.tree.predicate.NullnessPredicate) JdbcParameterImpl(org.hibernate.sql.exec.internal.JdbcParameterImpl) ComparisonPredicate(org.hibernate.sql.ast.tree.predicate.ComparisonPredicate)

Aggregations

Expression (org.hibernate.sql.ast.tree.expression.Expression)130 CaseSearchedExpression (org.hibernate.sql.ast.tree.expression.CaseSearchedExpression)68 CaseSimpleExpression (org.hibernate.sql.ast.tree.expression.CaseSimpleExpression)67 BinaryArithmeticExpression (org.hibernate.sql.ast.tree.expression.BinaryArithmeticExpression)62 SqlSelectionExpression (org.hibernate.sql.ast.tree.expression.SqlSelectionExpression)57 ModifiedSubQueryExpression (org.hibernate.sql.ast.tree.expression.ModifiedSubQueryExpression)54 SelfRenderingExpression (org.hibernate.sql.ast.tree.expression.SelfRenderingExpression)54 ColumnReference (org.hibernate.sql.ast.tree.expression.ColumnReference)42 SelfRenderingFunctionSqlAstExpression (org.hibernate.query.sqm.function.SelfRenderingFunctionSqlAstExpression)37 SqlTuple (org.hibernate.sql.ast.tree.expression.SqlTuple)35 SqmExpression (org.hibernate.query.sqm.tree.expression.SqmExpression)34 SelfRenderingSqlFragmentExpression (org.hibernate.sql.ast.tree.expression.SelfRenderingSqlFragmentExpression)33 SelfRenderingAggregateFunctionSqlAstExpression (org.hibernate.query.sqm.function.SelfRenderingAggregateFunctionSqlAstExpression)32 ArrayList (java.util.ArrayList)31 SqmModifiedSubQueryExpression (org.hibernate.query.sqm.tree.expression.SqmModifiedSubQueryExpression)31 TableGroup (org.hibernate.sql.ast.tree.from.TableGroup)28 TableReference (org.hibernate.sql.ast.tree.from.TableReference)25 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)23 ComparisonPredicate (org.hibernate.sql.ast.tree.predicate.ComparisonPredicate)23 NavigablePath (org.hibernate.query.spi.NavigablePath)21