Criteria.Criterion crit5 =
c.getNewCriterion(table5, column5, value5, Criteria.EQUAL);
crit2.and(crit3).or(crit4.and(crit5));
c.add(crit2);
c.addSelectColumn(new ColumnImpl(null, "myTable2", null, "*"));
String expect =
"SELECT * FROM myTable2, myTable3, myTable4, myTable5 WHERE "
+ "((myTable2.myColumn2=? "
+ "AND myTable3.myColumn3=?) "
+ "OR (myTable4.myColumn4=? "
+ "AND myTable5.myColumn5=?))";
Query result = SqlBuilder.buildQuery(c);
assertEquals(expect, result.toString());
List<Object> preparedStatementReplacements
= result.getPreparedStatementReplacements();
assertEquals(4, preparedStatementReplacements.size());
assertEquals("myValue2", preparedStatementReplacements.get(0));
assertEquals("myValue3", preparedStatementReplacements.get(1));
assertEquals("myValue4", preparedStatementReplacements.get(2));
assertEquals("myValue5", preparedStatementReplacements.get(3));
c.clear();
Criteria.Criterion crit6 = c.getNewCriterion(
table2,
column2,
value2,
Criteria.LESS_THAN);
Criteria.Criterion crit7 = c.getNewCriterion(
table3,
column3,
value3,
Criteria.LESS_EQUAL);
Criteria.Criterion crit8 = c.getNewCriterion(
table4,
column4,
value4,
Criteria.GREATER_THAN);
Criteria.Criterion crit9 = c.getNewCriterion(
table5,
column5,
value5,
Criteria.GREATER_EQUAL);
crit6.and(crit7).or(crit8).and(crit9);
c.add(crit6);
c.addSelectColumn(new ColumnImpl(null, "myTable2", null, "*"));
expect =
"SELECT * FROM myTable2, myTable3, myTable4, myTable5 WHERE "
+ "(((myTable2.myColumn2<? "
+ "AND myTable3.myColumn3<=?) "
+ "OR myTable4.myColumn4>?) "