@Override public ThenClause when(Expression conditionOrExpression) { whens.add(conditionOrExpression); thens.add(Expression.NULL()); return this; }
protected static Expression build(String operator, Expression expression1, Expression expression2, Expression... others) { StringBuilder result = new StringBuilder(operator); result.append('(').append(expression1.toString()).append(", ").append(expression2.toString()); if (others != null) { for (Expression other : others) { if (other == null) { other = Expression.NULL(); } result.append(", ").append(other.toString()); } } result.append(')'); return x(result.toString()); }
/** * Returned expression results in the smallest non-NULL, non-MISSING value * if the values are of the same type, otherwise NULL. At least two expressions are necessary. */ public static Expression least(Expression e1, Expression e2, Expression... otherExpressions) { StringBuilder least = new StringBuilder("LEAST("); least.append(e1.toString()).append(", ").append(e2.toString()); if (otherExpressions == null) { return x(least.append(')').toString()); } for (Expression otherExpression : otherExpressions) { if (otherExpression == null) { otherExpression = Expression.NULL(); } least.append(", ").append(otherExpression.toString()); } least.append(')'); return x(least.toString()); } }
/** * Returned expression results in the largest non-NULL, non-MISSING value if the values are * of the same type, otherwise NULL. At least two expressions are necessary. */ public static Expression greatest(Expression e1, Expression e2, Expression... otherExpressions) { StringBuilder greatest = new StringBuilder("GREATEST("); greatest.append(e1.toString()).append(", ").append(e2.toString()); if (otherExpressions == null) { return x(greatest.append(')').toString()); } for (Expression otherExpression : otherExpressions) { if (otherExpression == null) { otherExpression = Expression.NULL(); } greatest.append(", ").append(otherExpression.toString()); } greatest.append(')'); return x(greatest.toString()); }
protected static Expression like(Iterator<Object> parameterValues, boolean ignoreCase, boolean anyPrefix, boolean anySuffix) { Object next = parameterValues.next(); if (next == null) { return Expression.NULL(); } Expression converted; if (next instanceof String) { String pattern = (String) next; if (anyPrefix) { pattern = "%" + pattern; } if (anySuffix) { pattern = pattern + "%"; } converted = s(pattern); } else { converted = x(String.valueOf(next)); } if (ignoreCase) { return StringFunctions.lower(converted); } return converted; }
protected static Expression like(Iterator<Object> parameterValues, boolean ignoreCase, boolean anyPrefix, boolean anySuffix) { Object next = parameterValues.next(); if (next == null) { return Expression.NULL(); } Expression converted; if (next instanceof String) { String pattern = (String) next; if (anyPrefix) { pattern = "%" + pattern; } if (anySuffix) { pattern = pattern + "%"; } converted = s(pattern); } else { converted = x(String.valueOf(next)); } if (ignoreCase) { return StringFunctions.lower(converted); } return converted; }