use of io.requery.query.function.Function in project requery by requery.
the class QueryElement method fromExpressions.
public Set<Expression<?>> fromExpressions() {
if (from == null) {
types = new LinkedHashSet<>();
Set<? extends Expression<?>> expressions;
switch(queryType) {
case SELECT:
expressions = getSelection();
break;
case INSERT:
case UPDATE:
case UPSERT:
expressions = updates.keySet();
break;
default:
expressions = Collections.emptySet();
}
for (Expression<?> expression : expressions) {
if (expression instanceof AliasedExpression) {
expression = ((AliasedExpression) expression).getInnerExpression();
}
if (expression instanceof Attribute) {
Type type = ((Attribute) expression).getDeclaringType();
types.add(type);
} else if (expression instanceof Function) {
Function function = (Function) expression;
for (Object arg : function.arguments()) {
Type type = null;
if (arg instanceof Attribute) {
type = ((Attribute) arg).getDeclaringType();
types.add(type);
} else if (arg instanceof Class) {
type = model.typeOf((Class) arg);
}
if (type != null) {
types.add(type);
}
}
}
}
if (from == null) {
from = new LinkedHashSet<>();
}
if (!types.isEmpty()) {
from.addAll(types);
}
}
return from;
}
use of io.requery.query.function.Function in project requery by requery.
the class DefaultOutput method appendConditionValue.
private void appendConditionValue(Expression expression, Object value, boolean parameterize) {
if (value instanceof QueryAttribute) {
appendColumn((Expression<?>) value);
} else if (value instanceof Supplier && ((Supplier) value).get() instanceof QueryAttribute) {
appendColumn((Expression<?>) ((Supplier) value).get());
} else if (value instanceof NamedExpression) {
NamedExpression namedExpression = (NamedExpression) value;
qb.append(namedExpression.getName());
} else if (value instanceof Function) {
appendFunction((Function) value);
} else if (value instanceof Collection && expression.getExpressionType() == ExpressionType.ROW) {
qb.openParenthesis();
qb.commaSeparated((Collection) value);
qb.closeParenthesis();
} else {
if (parameterize) {
if (parameters != null) {
parameters.add(expression, value);
}
qb.append("?").space();
} else {
if (value instanceof CharSequence) {
qb.appendQuoted(value.toString()).space();
} else {
qb.append(value).space();
}
}
}
}
use of io.requery.query.function.Function in project requery by requery.
the class DefaultOutput method appendFunction.
private void appendFunction(Function function) {
if (function instanceof Case) {
appendCaseFunction((Case) function);
} else {
Function.Name name = configuration.getMapping().mapFunctionName(function);
qb.append(name.getName());
if (function.arguments().length == 0 && name.isConstant()) {
return;
}
qb.openParenthesis();
int index = 0;
for (Object arg : function.arguments()) {
if (index > 0) {
qb.comma();
}
if (arg instanceof Expression) {
Expression expression = (Expression) arg;
switch(expression.getExpressionType()) {
case ATTRIBUTE:
appendColumnForSelect(expression);
break;
case FUNCTION:
Function inner = (Function) arg;
appendFunction(inner);
break;
default:
qb.append(expression.getName());
break;
}
} else if (arg instanceof Class) {
qb.append("*");
} else {
appendConditionValue(function.expressionForArgument(index), arg);
}
index++;
}
qb.closeParenthesis().space();
}
}
Aggregations