/** * 测试使用复杂的子查询过滤条件 * * @throws SQLException */ @Test public void testComplextFilterCondition() throws SQLException { System.out.println("=========== testComplextFilterCondition End =========="); // // 添加过滤条件的 Person p = new Person(); p.getQuery().addCondition(Person.Field.id, 1); Condition or = QB.or( QB.eq(Score.Field.subject, "语文"), QB.eq(Score.Field.subject, "化学"), QB.eq(Score.Field.subject, "英语")); p.getQuery().addCascadeCondition("scores", or); Person result = db.load(p); System.out.println("loaded"); assertEquals(3, result.getScores().size()); System.out.println("=========== testComplextFilterCondition End =========="); }
/** * 在复杂条件中使用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 =========="); }