Tabnine Logo
BaseCondition
Code IndexAdd Tabnine to your IDE (free)

How to use
BaseCondition
in
io.yawp.repository.query.condition

Best Java code snippets using io.yawp.repository.query.condition.BaseCondition (Showing top 20 results out of 315)

origin: feroult/yawp

@Override
public void init(Repository r, Class<?> clazz) {
  boolean allSubConditionsHasPreFilter = true;
  boolean oneSubConditionHasPreFilter = false;
  for (BaseCondition c : conditions) {
    c.init(r, clazz);
    if (!c.hasPreFilter()) {
      allSubConditionsHasPreFilter = false;
    } else {
      oneSubConditionHasPreFilter = true;
    }
    if (c.hasPostFilter()) {
      hasPostFilter = true;
    }
  }
  hasPreFilter = (oneSubConditionHasPreFilter && logicalOperator == LogicalOperator.AND)
      || (allSubConditionsHasPreFilter && logicalOperator == LogicalOperator.OR);
}
origin: feroult/yawp

private boolean evaluateOr(Object object) {
  for (BaseCondition condition : conditions) {
    if (condition.evaluate(object)) {
      return true;
    }
  }
  return false;
}
origin: feroult/yawp

public static BaseCondition not(BaseCondition c) {
  return c.not();
}
origin: feroult/yawp

@Test
public void testJoinedConditions() {
  BasicObject object = new BasicObject();
  object.setIntValue(10);
  object.setStringValue("ccc");
  object.setLongValue(100l);
  assertTrue(c("intValue", "=", 10).and(c("stringValue", "=", "ccc")).evaluate(object));
  assertFalse(c("intValue", "=", 10).and(c("stringValue", "!=", "ccc")).evaluate(object));
  assertTrue(c("intValue", "=", 9).or(c("stringValue", "=", "ccc")).evaluate(object));
  assertFalse(c("intValue", "=", 10).not().evaluate(object));
  assertTrue(c("intValue", "=", 9).not().evaluate(object));
  assertTrue(c("intValue", "=", 9).or(c("stringValue", "=", "bbb").or(c("longValue", "=", 100l))).evaluate(object));
}
origin: feroult/yawp

private boolean hasPropertyFilter() {
  return builder.getCondition() != null && builder.getCondition().hasPreFilter();
}
origin: feroult/yawp

@Test
public void testParentRef() {
  Parent parent = new Parent("parent");
  yawp.save(parent);
  Child child = new Child("child", parent.getId());
  yawp.save(child);
  Grandchild grandchild = new Grandchild("grandchild", child.getId());
  yawp.save(grandchild);
  BaseCondition c = c("parent->parent->name", "=", "parent");
  c.init(yawp, Grandchild.class);
  assertTrue(c.evaluate(grandchild));
  assertTrue(c.evaluate(child));
  assertTrue(c.evaluate(parent));
}
origin: feroult/yawp

@Test
public void testWhereWithoutIndexComplexConditions() {
  yawp.save(new BasicObject("a", 1l));
  yawp.save(new BasicObject("a", 2l));
  yawp.save(new BasicObject("c", 3l));
  yawp.save(new BasicObject("c", 4l));
  yawp.save(new BasicObject("d", 5l));
  yawp.save(new BasicObject("e", 6l));
  BaseCondition c2 = c("stringValue", "=", "c").and(c("longValue", "=", 3l));
  List<BasicObject> objects = yawp(BasicObject.class).where(c("stringValue", "=", "a").or(c2)).list();
  assertObjects(objects, "a", "a", "c");
}
origin: feroult/yawp

private void initConditions() {
  if (condition == null) {
    return;
  }
  condition.init(r, endpointClazz);
}
origin: feroult/yawp

@Test
public void testWhereWithoutIndexAndCondition() {
  yawp.save(new BasicObject("a", 1l));
  yawp.save(new BasicObject("a", 2l));
  yawp.save(new BasicObject("b", 1l));
  List<BasicObject> objects = yawp(BasicObject.class).where(c("stringValue", "=", "a").and(c("longValue", "=", 1l))).list();
  assertObjects(objects, "a");
}
origin: feroult/yawp

@Override
public Map<String, Object> toMap() {
  Map<String, Object> map = new HashMap<>();
  map.put("logicalOperator", logicalOperator.toString());
  List<Map<String, Object>> cs = new ArrayList<>();
  for (BaseCondition c : conditions) {
    cs.add(c.toMap());
  }
  map.put("conditions", cs);
  return map;
}
origin: feroult/yawp

private boolean hasPostFilter() {
  return condition != null && condition.hasPostFilter();
}
origin: feroult/yawp

private List<T> postFilter(List<T> objects) {
  if (!hasPostFilter()) {
    return objects;
  }
  return condition.applyPostFilter(objects);
}
origin: feroult/yawp

@Test
public void testWhereWithoutIndexOrCondition() {
  yawp.save(new BasicObject("a", 1l));
  yawp.save(new BasicObject("b", 2l));
  yawp.save(new BasicObject("c", 1l));
  List<BasicObject> objects = yawp(BasicObject.class).where(c("stringValue", "=", "a").or(c("longValue", "=", 1l))).list();
  assertObjects(objects, "a", "c");
}
origin: feroult/yawp

private void prepareQueryWhere(QueryBuilder<?> builder, Query q) throws FalsePredicateException {
  BaseCondition condition = builder.getCondition();
  if (condition != null && condition.hasPreFilter()) {
    q.setFilter(createFilter(builder, condition));
  }
}
origin: feroult/yawp

  @Test
  public void testIgnoreConditionForChildFields() {
    Parent parent = new Parent("parent");
    yawp.save(parent);

    Child child = new Child("child", parent.getId());
    yawp.save(child);

    Grandchild grandchild = new Grandchild("grandchild", child.getId());
    grandchild.setAge(10);
    yawp.save(grandchild);

    BaseCondition c = c("age", "=", 11);
    c.init(yawp, Grandchild.class);

    assertFalse(c.evaluate(grandchild));
    assertTrue(c.evaluate(child));
    assertTrue(c.evaluate(parent));

  }
}
origin: feroult/yawp

@Test
public void testWhereWithoutIndexWithId() {
  yawp.save(setId(new BasicObject("a", 1l), 1l));
  yawp.save(setId(new BasicObject("b", 2l), 2l));
  yawp.save(setId(new BasicObject("c", 3l), 3l));
  IdRef<BasicObject> id = IdRef.create(yawp, BasicObject.class, 1l);
  List<BasicObject> objects = yawp(BasicObject.class).where(c("id", "=", id).or(c("longValue", "=", 3l))).list();
  assertObjects(objects, "a", "c");
  objects = yawp(BasicObject.class).where(c("id", "=", id).and(c("longValue", "=", 1l))).list();
  assertObjects(objects, "a");
  objects = yawp(BasicObject.class).where(c("id", "=", id).and(c("longValue", "=", 3l))).list();
  assertObjects(objects);
}
origin: feroult/yawp

public QueryBuilder<T> where(BaseCondition c) {
  if (condition == null) {
    condition = c;
  } else {
    condition = Condition.and(condition, c);
  }
  condition.init(r, clazz);
  return this;
}
origin: feroult/yawp

@Test
public void testQueryRefWithPreFilter() {
  BasicObject ref1 = new BasicObject("right");
  BasicObject ref2 = new BasicObject("right");
  yawp.save(ref1);
  yawp.save(ref2);
  yawp.save(new BasicObject("a", ref1.getId()));
  yawp.save(new BasicObject("b", ref2.getId()));
  BasicObject object = yawp(BasicObject.class).where(c("objectId->stringValue", "=", "right").and(c("stringValue", "=", "a"))).only();
  assertEquals("a", object.getStringValue());
}
origin: feroult/yawp

  public Map<String, Object> toMap() {
    Map<String, Object> result = new HashMap<>();
    result.put("clazz", clazz.getCanonicalName());
    result.put("parentId", parentId == null ? null : parentId.toString());
    result.put("condition", condition == null ? null : condition.toMap());
    result.put("preOrders", preOrders);
    result.put("postOrders", postOrders);
    result.put("limit", limit);
    return result;
  }
}
origin: feroult/yawp

private String joinedWhere(JoinedCondition joinedCondition) throws FalsePredicateException {
  BaseCondition[] conditions = joinedCondition.getConditions();
  LogicalOperator logicalOperator = joinedCondition.getLogicalOperator();
  List<String> wheres = new ArrayList<>();
  for (int i = 0; i < conditions.length; i++) {
    try {
      BaseCondition condition = conditions[i];
      if (!condition.hasPreFilter()) {
        continue;
      }
      wheres.add(where(condition));
    } catch (FalsePredicateException e) {
      if (logicalOperator == LogicalOperator.AND) {
        throw e;
      }
    }
  }
  if (wheres.isEmpty()) {
    throw new FalsePredicateException();
  }
  if (wheres.size() == 1) {
    return wheres.get(0);
  }
  return applyLogicalOperator(logicalOperator, wheres);
}
io.yawp.repository.query.conditionBaseCondition

Most used methods

  • hasPreFilter
  • evaluate
  • init
  • not
  • and
  • applyPostFilter
  • hasPostFilter
  • or
  • toMap

Popular in Java

  • Finding current android device location
  • getResourceAsStream (ClassLoader)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • addToBackStack (FragmentTransaction)
  • Path (java.nio.file)
  • Locale (java.util)
    Locale represents a language/country/variant combination. Locales are used to alter the presentatio
  • PriorityQueue (java.util)
    A PriorityQueue holds elements on a priority heap, which orders the elements according to their natu
  • ThreadPoolExecutor (java.util.concurrent)
    An ExecutorService that executes each submitted task using one of possibly several pooled threads, n
  • Response (javax.ws.rs.core)
    Defines the contract between a returned instance and the runtime when an application needs to provid
  • IsNull (org.hamcrest.core)
    Is the value null?
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now