if (operand instanceof String) {
String str = (String) operand;
// escape single quotes
if (str.indexOf('\'') != -1) {
str = escapeQuotes(str);
FilterItem replacementFilterItem = new FilterItem(item.getSelectItem(), item.getOperator(), str);
return super.rewriteFilterItem(replacementFilterItem);
}
} else if (operand instanceof Iterable || operand.getClass().isArray()) {
// operand is a set of values (typically in combination with an
// IN operator). Each individual element must be escaped.
assert item.getOperator() == OperatorType.IN;
@SuppressWarnings("unchecked")
final List<Object> elements = (List<Object>) CollectionUtils.toList(operand);
for (ListIterator<Object> it = elements.listIterator(); it.hasNext();) {
Object next = it.next();
if (next == null) {
logger.warn("element in IN list is NULL, which isn't supported by SQL. Stripping the element from the list: {}", item);
it.remove();
} else if (next instanceof String) {
String str = (String) next;
if (str.indexOf('\'') != -1) {
str = escapeQuotes(str);
it.set(str);
}
}
}
FilterItem replacementFilterItem = new FilterItem(item.getSelectItem(), item.getOperator(), elements);
return super.rewriteFilterItem(replacementFilterItem);
}
}
return super.rewriteFilterItem(item);
}