}
@Override
public Object caseBinaryOperation(BinaryOperation binaryOperation)
{
Expression leftOperand = binaryOperation.getLeftOperand();
String operator = binaryOperation.getOperator();
if ("==".equals(operator))
{
Expression rightOperand = binaryOperation.getRightOperand();
String property = ExpressionBuilder.toString(leftOperand);
if (Keywords.ID_KEY.equals(property))
{
dbObject.put(property, new ObjectId(((Literal) rightOperand).getLiteralValue()));
}
else if (rightOperand instanceof Literal)
{
dbObject.put(property, getValue((Literal) rightOperand));
}
else if ("null".equals(ExpressionBuilder.toString(rightOperand)))
{
DBObject notExists = new BasicDBObject();
notExists.put("$exists", Boolean.FALSE);
dbObject.put(property, notExists);
}
else
{
// TODO: What to do?
}
}
else if ("!=".equals(operator))
{
Expression rightOperand = binaryOperation.getRightOperand();
String property = ExpressionBuilder.toString(leftOperand);
if (rightOperand instanceof Literal)
{
DBObject notEqual = new BasicDBObject();
notEqual.put("$ne", getValue((Literal) rightOperand));
dbObject.put(property, notEqual);
}
else if ("null".equals(ExpressionBuilder.toString(rightOperand)))
{
DBObject exists = new BasicDBObject();
exists.put("$exists", Boolean.TRUE);
dbObject.put(property, exists);
}
else
{
// TODO: What to do?
}
}
else if ("<".equals(operator) || "<=".equals(operator) || ">".equals(operator) || ">=".equals(operator))
{
Expression rightOperand = binaryOperation.getRightOperand();
String property = ExpressionBuilder.toString(leftOperand);
if (rightOperand instanceof Literal)
{
DBObject compare = new BasicDBObject();
compare.put("<".equals(operator) ? QueryOperators.LT : "<=".equals(operator) ? QueryOperators.LTE : ">".equals(operator) ? QueryOperators.GT : QueryOperators.GTE,