use of com.amplifyframework.core.model.query.predicate.ContainsQueryOperator in project amplify-android by aws-amplify.
the class SQLPredicate method parsePredicateOperation.
@SuppressWarnings("fallthrough")
private // Utility method to recursively parse a given predicate operation.
StringBuilder parsePredicateOperation(QueryPredicateOperation<?> operation) throws DataStoreException {
final StringBuilder builder = new StringBuilder();
final String model = Wrap.inBackticks(operation.modelName());
final String field = Wrap.inBackticks(operation.field());
final String column = model == null ? operation.field() : model + "." + field;
final QueryOperator<?> op = operation.operator();
switch(op.type()) {
case BETWEEN:
BetweenQueryOperator<?> betweenOp = (BetweenQueryOperator<?>) op;
addBinding(betweenOp.start());
addBinding(betweenOp.end());
return builder.append(column).append(SqlKeyword.DELIMITER).append(SqlKeyword.BETWEEN).append(SqlKeyword.DELIMITER).append("?").append(SqlKeyword.DELIMITER).append(SqlKeyword.AND).append(SqlKeyword.DELIMITER).append("?");
case CONTAINS:
ContainsQueryOperator containsOp = (ContainsQueryOperator) op;
addBinding(containsOp.value());
return builder.append("instr(").append(column).append(",").append("?").append(")").append(SqlKeyword.DELIMITER).append(SqlKeyword.fromQueryOperator(QueryOperator.Type.GREATER_THAN)).append(SqlKeyword.DELIMITER).append("0");
case NOT_CONTAINS:
NotContainsQueryOperator notContainsOp = (NotContainsQueryOperator) op;
addBinding(notContainsOp.value());
return builder.append("instr(").append(column).append(",").append("?").append(")").append(SqlKeyword.DELIMITER).append(SqlKeyword.fromQueryOperator(QueryOperator.Type.EQUAL)).append(SqlKeyword.DELIMITER).append("0");
case BEGINS_WITH:
BeginsWithQueryOperator beginsWithOp = (BeginsWithQueryOperator) op;
addBinding(beginsWithOp.value() + "%");
return builder.append(column).append(SqlKeyword.DELIMITER).append(SqlKeyword.LIKE).append(SqlKeyword.DELIMITER).append("?");
case EQUAL:
case NOT_EQUAL:
Object operatorValue = getOperatorValue(op);
if (operatorValue == null) {
SqlKeyword sqlNullCheck = op.type() == QueryOperator.Type.EQUAL ? SqlKeyword.IS_NULL : SqlKeyword.IS_NOT_NULL;
return builder.append(column).append(SqlKeyword.DELIMITER).append(sqlNullCheck.toString());
}
case LESS_THAN:
case GREATER_THAN:
case LESS_OR_EQUAL:
case GREATER_OR_EQUAL:
addBinding(getOperatorValue(op));
return builder.append(column).append(SqlKeyword.DELIMITER).append(SqlKeyword.fromQueryOperator(op.type())).append(SqlKeyword.DELIMITER).append("?");
default:
throw new DataStoreException("Tried to parse an unsupported QueryPredicateOperation", "Try changing to one of the supported values from " + "QueryPredicateOperation.Type enum.");
}
}
Aggregations