use of io.requery.query.NullOperand 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) {
// Handle unary operator
if (condition.getRightOperand() instanceof NullOperand) {
appendOperator(condition.getOperator());
if (depth > 0) {
qb.openParenthesis();
}
appendOperation((Condition) leftOperand, depth + 1);
if (depth > 0) {
qb.closeParenthesis().space();
}
} else {
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