}
sb.append(')');
return;
}
final SelectItem selectItem = filterItem.getSelectItem();
validateSoqlSupportedSelectItem(selectItem);
final Column column = selectItem.getColumn();
sb.append(column.getName());
sb.append(' ');
final OperatorType operator = filterItem.getOperator();
if (operator == OperatorType.IN) {
throw new UnsupportedOperationException("IN operator not supported: " + filterItem);
}
sb.append(operator.toSql());
sb.append(' ');
final Object operand = filterItem.getOperand();
if (operand == null) {
sb.append("null");
} else if (operand instanceof String) {
sb.append('\'');
String str = operand.toString();
str = str.replaceAll("\'", "\\\\'");
str = str.replaceAll("\"", "\\\\\"");
str = str.replaceAll("\r", "\\\\r");
str = str.replaceAll("\n", "\\\\n");
str = str.replaceAll("\t", "\\\\t");
sb.append(str);
sb.append('\'');
} else if (operand instanceof Number) {
sb.append(operand);
} else if (operand instanceof Date) {
final SimpleDateFormat dateFormat;
ColumnType expectedColumnType = selectItem.getExpectedColumnType();
if (expectedColumnType == ColumnType.DATE) {
// note: we don't apply the timezone for DATE fields, since they
// don't contain time-of-day information.
dateFormat = new SimpleDateFormat(SOQL_DATE_FORMAT_OUT);
} else if (expectedColumnType == ColumnType.TIME) {
dateFormat = new SimpleDateFormat(SOQL_TIME_FORMAT_OUT, Locale.ENGLISH);
dateFormat.setTimeZone(SOQL_TIMEZONE);
} else {
dateFormat = new SimpleDateFormat(SOQL_DATE_TIME_FORMAT_OUT, Locale.ENGLISH);
dateFormat.setTimeZone(SOQL_TIMEZONE);
}
String str = dateFormat.format((Date) operand);
logger.debug("Date '{}' formatted as: {}", operand, str);
sb.append(str);
} else if (operand instanceof Column) {
sb.append(((Column) operand).getName());
} else if (operand instanceof SelectItem) {
SelectItem operandSelectItem = (SelectItem) operand;
validateSoqlSupportedSelectItem(operandSelectItem);
sb.append(operandSelectItem.getColumn().getName());
} else {
throw new UnsupportedOperationException("Unsupported operand: " + operand);
}
}