*
* @return A string builder representing the where clause of the SQL query.
*/
private static StrBuilder buildWhereClauseFromRightAndLeftParts(
StrBuilder value1, StrBuilder value2, ComparisonFilter.Operator operator) {
StrBuilder clause;
switch (operator) {
case EQ:
clause = value1.append("=").append(value2);
break;
case NE:
clause = value1.append("<>").append(value2);
break;
case LT:
clause = value1.append("<").append(value2);
break;
case GT:
clause = value1.append(">").append(value2);
break;
case LE:
clause = value1.append("<=").append(value2);
break;
case GE:
clause = value1.append(">=").append(value2);
break;
case CONTAINS:
value2 = new StrBuilder(value2.toString().replace("\"", ""));
clause = value1.append(" LIKE ").append("\"%").append(value2).append("%\"");
break;
case STARTS_WITH:
value2 = new StrBuilder(value2.toString().replace("\"", ""));
clause = value1.append(" LIKE ").append("\"").append(value2).append("%\"");
break;
case ENDS_WITH:
value2 = new StrBuilder(value2.toString().replace("\"", ""));
clause = value1.append(" LIKE ").append("\"%").append(value2).append("\"");
break;
case MATCHES:
throw new RuntimeException("SQL does not support regular expression");
case LIKE:
value2 = new StrBuilder(value2.toString().replace("\"", ""));
clause = value1.append(" LIKE ").append("\"").append(value2).append("\"");
break;
default:// Should never get here.
throw new RuntimeException("Operator was not found: " + operator);
}
clause.insert(0, "(").append(")");
return clause;
}