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");
}
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);
}
}
}
}
}
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;
}
}
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;
}
}
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));
}
Aggregations