public static BaseCondition c(String field, WhereOperator whereOperator, Object comparison) { return new SimpleCondition(field, whereOperator, comparison); }
public SimpleCondition(String field, WhereOperator whereOperator, Object value) { this.field = field; this.whereOperator = whereOperator; this.whereValue = value; if (whereOperator == WhereOperator.IN) { assertIsList(value); } }
private void normalizeIdRefs() { if (isIdField()) { if (whereValue instanceof String) { whereValue = IdRef.parse(r, (String) whereValue); } else if (whereValue instanceof List) { whereValue = convertToIdRefs((List<?>) whereValue); } } }
private Filter createSimpleFilter(QueryBuilder<?> builder, SimpleCondition condition) throws FalsePredicateException { String field = condition.getField(); Class<?> clazz = builder.getModel().getClazz(); Object whereValue = condition.getWhereValue(); WhereOperator whereOperator = condition.getWhereOperator(); String actualFieldName = getActualFieldName(field, clazz); Object actualValue = getActualFieldValue(field, clazz, whereValue); if (whereOperator == WhereOperator.IN && listSize(whereValue) == 0) { throw new FalsePredicateException(); } return new FilterPredicate(actualFieldName, getFilterOperator(whereOperator), actualValue); }
@SuppressWarnings("unchecked") private T executeQueryById() { SimpleCondition c = (SimpleCondition) condition; IdRef<T> id = (IdRef<T>) c.getWhereValue(); executedQueryType = QueryType.FETCH; RepositoryHooks.beforeQuery(this); T retrieved = hasForcedResponse(executedQueryType) ? getForcedResultFetch() : doExecuteQueryById(id); executedResponse = retrieved; RepositoryHooks.afterQuery(this); return retrieved; }
@Override public boolean hasPostFilter() { return !hasPreFilter(); }
private String simpleWhere(SimpleCondition condition) throws FalsePredicateException { String fieldName = condition.getField(); Class<?> clazz = builder.getModel().getClazz(); Object whereValue = condition.getWhereValue(); WhereOperator whereOperator = condition.getWhereOperator(); String actualFieldName = getActualFieldName(fieldName, clazz); Object actualValue = getActualFieldValue(fieldName, clazz, whereValue); if (whereOperator == WhereOperator.IN) { if (listSize(whereValue) == 0) { throw new FalsePredicateException(); } return whereCollectionValue(fieldName, actualFieldName, whereOperator, (Collection<?>) actualValue); } return whereSingleValue(fieldName, actualFieldName, whereOperator, actualValue); }
private void assertSimpleCondition(BaseCondition c, String p, WhereOperator whereOperator, Object value) { assertEquals(SimpleCondition.class, c.getClass()); SimpleCondition condition = (SimpleCondition) c; assertEquals(p, condition.getField()); assertEquals(whereOperator, condition.getWhereOperator()); assertEquals(value, condition.getWhereValue()); }
@Override public BaseCondition not() { return new SimpleCondition(field, whereOperator.reverse(), whereValue); }