Search in sources :

Example 16 with SqlAstNode

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

the class DerbyLpadEmulation method render.

@Override
public void render(SqlAppender sqlAppender, List<? extends SqlAstNode> arguments, SqlAstTranslator<?> walker) {
    final SqlAstNode string = arguments.get(0);
    final SqlAstNode length = arguments.get(1);
    sqlAppender.appendSql("case when length(");
    walker.render(string, SqlAstNodeRenderingMode.NO_PLAIN_PARAMETER);
    sqlAppender.appendSql(")<");
    walker.render(length, SqlAstNodeRenderingMode.DEFAULT);
    sqlAppender.appendSql(" then substr(char('',");
    // The char function for Derby always needs a literal value
    walker.render(length, SqlAstNodeRenderingMode.INLINE_PARAMETERS);
    sqlAppender.appendSql(")||");
    walker.render(string, SqlAstNodeRenderingMode.DEFAULT);
    sqlAppender.appendSql(",length(");
    walker.render(string, SqlAstNodeRenderingMode.NO_PLAIN_PARAMETER);
    sqlAppender.appendSql(")+1) else ");
    walker.render(string, SqlAstNodeRenderingMode.NO_PLAIN_PARAMETER);
    sqlAppender.appendSql(" end");
}
Also used : SqlAstNode(org.hibernate.sql.ast.tree.SqlAstNode)

Example 17 with SqlAstNode

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

the class ArgumentTypesValidator method validateSqlTypes.

/**
 * This is the final validation phase with the fully-typed SQL nodes. Note that these
 * checks are much less useful, occurring "too late", right before we execute the
 * query and get an error from the database. However, they help in the sense of (a)
 * resulting in more consistent/understandable error messages, and (b) protecting the
 * user from writing queries that depend on generally-unportable implicit type
 * conversions happening at the database level. (Implicit type conversions between
 * numeric types are portable, and are not prohibited here.)
 */
@Override
public void validateSqlTypes(List<? extends SqlAstNode> arguments, String functionName) {
    int count = 0;
    for (SqlAstNode argument : arguments) {
        if (argument instanceof Expression) {
            JdbcMappingContainer expressionType = ((Expression) argument).getExpressionType();
            if (expressionType != null) {
                ParameterDetector detector = new ParameterDetector();
                argument.accept(detector);
                if (detector.detected) {
                    count += expressionType.getJdbcTypeCount();
                } else {
                    count = validateArgument(count, expressionType, functionName);
                }
            }
        }
    }
}
Also used : JdbcMappingContainer(org.hibernate.metamodel.mapping.JdbcMappingContainer) Expression(org.hibernate.sql.ast.tree.expression.Expression) SqlAstNode(org.hibernate.sql.ast.tree.SqlAstNode)

Example 18 with SqlAstNode

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

the class AbstractSqlAstTranslator method renderCommaSeparated.

protected final void renderCommaSeparated(Iterable<? extends SqlAstNode> expressions) {
    String separator = NO_SEPARATOR;
    for (SqlAstNode expression : expressions) {
        appendSql(separator);
        expression.accept(this);
        separator = COMA_SEPARATOR;
    }
}
Also used : SqlAstNode(org.hibernate.sql.ast.tree.SqlAstNode)

Example 19 with SqlAstNode

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

the class AbstractSqlAstTranslator method renderCommaSeparatedSelectExpression.

protected final void renderCommaSeparatedSelectExpression(Iterable<? extends SqlAstNode> expressions) {
    String separator = NO_SEPARATOR;
    for (SqlAstNode expression : expressions) {
        final SqlTuple sqlTuple = SqlTupleContainer.getSqlTuple(expression);
        if (sqlTuple != null) {
            for (Expression e : sqlTuple.getExpressions()) {
                appendSql(separator);
                renderSelectExpression(e);
                separator = COMA_SEPARATOR;
            }
        } else if (expression instanceof Expression) {
            appendSql(separator);
            renderSelectExpression((Expression) expression);
        } else {
            appendSql(separator);
            expression.accept(this);
        }
        separator = COMA_SEPARATOR;
    }
}
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) SqlTuple(org.hibernate.sql.ast.tree.expression.SqlTuple) SqlAstNode(org.hibernate.sql.ast.tree.SqlAstNode)

Example 20 with SqlAstNode

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

the class SelfRenderingSqmAggregateFunction method convertToSqlAst.

@Override
public Expression convertToSqlAst(SqmToSqlAstConverter walker) {
    final ReturnableType<?> resultType = resolveResultType(walker.getCreationContext().getMappingMetamodel().getTypeConfiguration());
    List<SqlAstNode> arguments = resolveSqlAstArguments(getArguments(), walker);
    ArgumentsValidator argumentsValidator = getArgumentsValidator();
    if (argumentsValidator != null) {
        argumentsValidator.validateSqlTypes(arguments, getFunctionName());
    }
    return new SelfRenderingAggregateFunctionSqlAstExpression(getFunctionName(), getRenderingSupport(), arguments, filter == null ? null : walker.visitNestedTopLevelPredicate(filter), resultType, getMappingModelExpressible(walker, resultType));
}
Also used : SqlAstNode(org.hibernate.sql.ast.tree.SqlAstNode) ArgumentsValidator(org.hibernate.query.sqm.produce.function.ArgumentsValidator)

Aggregations

SqlAstNode (org.hibernate.sql.ast.tree.SqlAstNode)23 Expression (org.hibernate.sql.ast.tree.expression.Expression)9 Distinct (org.hibernate.sql.ast.tree.expression.Distinct)6 ArgumentsValidator (org.hibernate.query.sqm.produce.function.ArgumentsValidator)5 ArrayList (java.util.ArrayList)4 SqlTuple (org.hibernate.sql.ast.tree.expression.SqlTuple)4 SortSpecification (org.hibernate.sql.ast.tree.select.SortSpecification)4 JdbcMappingContainer (org.hibernate.metamodel.mapping.JdbcMappingContainer)3 SqmToSqlAstConverter (org.hibernate.query.sqm.sql.SqmToSqlAstConverter)3 SqmSortSpecification (org.hibernate.query.sqm.tree.select.SqmSortSpecification)3 Over (org.hibernate.sql.ast.tree.expression.Over)3 SelfRenderingExpression (org.hibernate.sql.ast.tree.expression.SelfRenderingExpression)3 SqlSelectionExpression (org.hibernate.sql.ast.tree.expression.SqlSelectionExpression)3 Predicate (org.hibernate.sql.ast.tree.predicate.Predicate)3 List (java.util.List)2 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)2 BasicValuedMapping (org.hibernate.metamodel.mapping.BasicValuedMapping)2 SelfRenderingFunctionSqlAstExpression (org.hibernate.query.sqm.function.SelfRenderingFunctionSqlAstExpression)2 SelfRenderingOrderedSetAggregateFunctionSqlAstExpression (org.hibernate.query.sqm.function.SelfRenderingOrderedSetAggregateFunctionSqlAstExpression)2 SqmPredicate (org.hibernate.query.sqm.tree.predicate.SqmPredicate)2