sb.append(checkWildcard);
position++;
}
value = sb.toString();
PreparedStatementPart result;
if (ignoreCase)
{
if (adapter.useIlike() && !replaceWithEquals)
{
if (SqlEnum.LIKE.equals(whereClausePart.getOperator()))
{
whereClausePart.setOperator(SqlEnum.ILIKE);
}
else if (SqlEnum.NOT_LIKE.equals(whereClausePart.getOperator()))
{
whereClausePart.setOperator(SqlEnum.NOT_ILIKE);
}
result = getObjectOrColumnPsPartBuilder().buildPs(
whereClausePart.getLValue(), false, adapter);
}
else
{
// no native case insensitive like is offered by the DB,
// or the LIKE was replaced with equals.
// need to ignore case manually.
result = getObjectOrColumnPsPartBuilder().buildPs(
whereClausePart.getLValue(), true, adapter);
}
}
else
{
result = getObjectOrColumnPsPartBuilder().buildPs(
whereClausePart.getLValue(), ignoreCase, adapter);
}
if (replaceWithEquals)
{
if (whereClausePart.getOperator().equals(SqlEnum.NOT_LIKE)
|| whereClausePart.getOperator().equals(SqlEnum.NOT_ILIKE))
{
result.getSql().append(SqlEnum.NOT_EQUAL);
}
else
{
result.getSql().append(SqlEnum.EQUAL);
}
// remove escape backslashes from String
position = 0;
sb = new StringBuffer();
while (position < value.length())
{
char checkWildcard = value.charAt(position);
if (checkWildcard == BACKSLASH
&& position + 1 < value.length())
{
position++;
// code below copies escaped character into sb
checkWildcard = value.charAt(position);
}
sb.append(checkWildcard);
position++;
}
value = sb.toString();
}
else
{
result.getSql().append(whereClausePart.getOperator());
}
String rValueSql = "?";
// handle ignoreCase if necessary
if (ignoreCase && (!(adapter.useIlike()) || replaceWithEquals))
{
rValueSql = adapter.ignoreCase(rValueSql);
}
// handle escape clause if necessary
if (!replaceWithEquals && adapter.useEscapeClauseForLike())
{
rValueSql = rValueSql + SqlEnum.ESCAPE + "'\\'";
}
result.getPreparedStatementReplacements().add(value);
result.getSql().append(rValueSql);
return result;
}