Beispiel #1
0
  /**
   * 在复杂条件中使用REF字段,并且测试在对一情况下,FilterField自动转换为RefField.
   *
   * @throws SQLException
   */
  @Test
  public void testComplextRefCondition() throws SQLException {
    System.out.println("=========== testComplextRefCondition Start ==========");
    Person q = new Person();
    q.getQuery().addCondition(Person.Field.age, Operator.GREAT, 16);

    Or or = new Or();
    or.addCondition(new RefField(School.Field.id), 2);
    or.addCondition(new RefField(School.Field.name), Operator.MATCH_ANY, "国");
    q.getQuery().addCondition(or); // 凡是引用一个其他表的条件要用RefField包裹
    q.getQuery().addCascadeCondition(QB.eq(School.Field.name, "战国高校"));

    List<Person> result = db.select(q);
    assertEquals(2, result.size());
    System.out.println("=========== testComplextRefCondition End ==========");
  }
Beispiel #2
0
  /**
   * 当分属多个对象的条件之间要实现Or,And等复合关系时:
   *
   * @throws SQLException
   */
  @Test
  public void testOrAndConditionWithDiffQueryObj() throws SQLException {
    System.out.println("=========== testOrAndConditionWithDiffQueryObj Begin ==========");
    Person q = new Person();
    And and = new And();
    and.addCondition(Person.Field.age, Operator.GREAT, 6);
    and.addCondition(new RefField(School.Field.id), 1);

    Or or = new Or();
    or.addCondition(and);
    or.addCondition(Person.Field.age, Operator.GREAT_EQUALS, 99);

    q.getQuery().addCondition(or);

    List<Person> result = db.select(q);
    for (Person p : result) {
      printPerson(p);
    }
    System.out.println("=========== testOrAndConditionWithDiffQueryObj End ==========");
  }