use of io.requery.query.element.QueryWrapper in project requery by requery.
the class DefaultOutput method appendFromExpression.
private void appendFromExpression(Expression expression) {
if (expression.getExpressionType() == ExpressionType.QUERY) {
QueryWrapper wrapper = (QueryWrapper) expression;
String alias = wrapper.unwrapQuery().getAlias();
if (alias == null) {
throw new IllegalStateException("query in 'from' expression must have an alias");
}
qb.openParenthesis();
appendQuery(wrapper);
qb.closeParenthesis().space();
qb.append(alias).space();
} else {
qb.append(expression.getName());
}
}
use of io.requery.query.element.QueryWrapper in project requery by requery.
the class DefaultOutput method appendOperation.
private void appendOperation(Condition condition, int depth) {
Object leftOperand = condition.getLeftOperand();
if (leftOperand instanceof Expression) {
final Expression<?> expression = (Expression<?>) condition.getLeftOperand();
appendColumn(expression);
Object value = condition.getRightOperand();
appendOperator(condition.getOperator());
if (value instanceof Collection && (condition.getOperator() == Operator.IN || condition.getOperator() == Operator.NOT_IN)) {
Collection collection = (Collection) value;
qb.openParenthesis();
qb.commaSeparated(collection, new QueryBuilder.Appender() {
@Override
public void append(QueryBuilder qb, Object value) {
appendConditionValue(expression, value);
}
});
qb.closeParenthesis();
} else if (value instanceof Object[]) {
Object[] values = (Object[]) value;
if (condition.getOperator() == Operator.BETWEEN) {
Object begin = values[0];
Object end = values[1];
appendConditionValue(expression, begin);
qb.keyword(AND);
appendConditionValue(expression, end);
} else {
for (Object o : values) {
appendConditionValue(expression, o);
}
}
} else if (value instanceof QueryWrapper) {
QueryWrapper wrapper = (QueryWrapper) value;
qb.openParenthesis();
appendQuery(wrapper);
qb.closeParenthesis().space();
} else if (value instanceof Condition) {
appendOperation((Condition) value, depth + 1);
} else if (value != null) {
appendConditionValue(expression, value);
}
} else if (leftOperand instanceof Condition) {
if (depth > 0) {
qb.openParenthesis();
}
appendOperation((Condition) leftOperand, depth + 1);
appendOperator(condition.getOperator());
Object value = condition.getRightOperand();
if (value instanceof Condition) {
appendOperation((Condition) value, depth + 1);
} else {
throw new IllegalStateException();
}
if (depth > 0) {
qb.closeParenthesis().space();
}
} else {
throw new IllegalStateException("unknown start expression type " + leftOperand);
}
}
Aggregations