use of io.requery.query.Condition 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);
}
}
use of io.requery.query.Condition in project requery by requery.
the class DefaultOutput method appendConditional.
@Override
public void appendConditional(LogicalElement element) {
LogicalOperator op = element.getOperator();
if (op != null) {
switch(op) {
case AND:
qb.keyword(AND);
break;
case OR:
qb.keyword(OR);
break;
}
}
Condition condition = element.getCondition();
boolean nested = condition.getRightOperand() instanceof Condition;
if (nested) {
qb.openParenthesis();
}
appendOperation(condition, 0);
if (nested) {
qb.closeParenthesis().space();
}
}
Aggregations