MentaBean

Compare Revisions

Ignore whitespace Rev 204 → Rev 203

/trunk/src/test/java/org/mentabean/jdbc/QueryBuilderTest.java
1201,121 → 1201,9
.closePar()
.executeQuery().size());
assertEquals(6, builder
.select(p, e, c)
.from(p)
.leftJoin(c).on(c.pxy().getId()).eq(p.pxy().getCompany().getId())
.eqProperty(p.pxy().getCompany())
.leftJoin(e).on(e.pxy().getNumber()).eq(p.pxy().getEmployee().getNumber())
.eqProperty(p.pxy().getEmployee())
.where()
.openPar()
.clauseIf(false, c.pxy().getName())
.condition(new Like("Google"))
.or()
.clauseIf(true, c.pxy().getName())
.condition(new Like("%"))
.or()
.clauseIf(false, c.pxy().getName())
.condition(new Like("Oracle"))
.closePar()
.executeQuery().size());
assertEquals(4, builder
.select(p, e, c)
.from(p)
.leftJoin(c).on(c.pxy().getId()).eq(p.pxy().getCompany().getId())
.eqProperty(p.pxy().getCompany())
.leftJoin(e).on(e.pxy().getNumber()).eq(p.pxy().getEmployee().getNumber())
.eqProperty(p.pxy().getEmployee())
.where()
.openPar()
.clauseIf(true, c.pxy().getName())
.condition(new Like("Google"))
.or()
.clauseIf(false, c.pxy().getName())
.condition(new Like("Oracle"))
.closePar()
.and()
.openPar()
.clauseIf(false, c.pxy().getName())
.condition(new Like("Oracle"))
.closePar()
.executeQuery().size());
assertEquals(4, builder
.select(p, e, c)
.from(p)
.leftJoin(c).on(c.pxy().getId()).eq(p.pxy().getCompany().getId())
.eqProperty(p.pxy().getCompany())
.leftJoin(e).on(e.pxy().getNumber()).eq(p.pxy().getEmployee().getNumber())
.eqProperty(p.pxy().getEmployee())
.where()
.openPar()
.clauseIf(true, c.pxy().getName())
.condition(new Like("Google"))
.or()
.clauseIf(false, c.pxy().getName())
.condition(new Like("Oracle"))
.closePar()
.and()
.openPar()
.clauseIf(false, c.pxy().getName())
.condition(new Like("Oracle"))
.and()
.clauseIf(true, c.pxy().getName())
.condition(new Like("Google"))
.closePar()
.executeQuery().size());
assertEquals(4, builder
.select(p, e, c)
.from(p)
.leftJoin(c).on(c.pxy().getId()).eq(p.pxy().getCompany().getId())
.eqProperty(p.pxy().getCompany())
.leftJoin(e).on(e.pxy().getNumber()).eq(p.pxy().getEmployee().getNumber())
.eqProperty(p.pxy().getEmployee())
.where()
.openPar()
.clauseIf(true, c.pxy().getName())
.condition(new Like("Google"))
.or()
.clauseIf(false, c.pxy().getName())
.condition(new Like("Oracle"))
.closePar()
.and()
.openPar()
.clauseIf(false, c.pxy().getName())
.condition(new Like("Oracle"))
.and()
.clauseIf(false, c.pxy().getName())
.condition(new Like("Google"))
.closePar()
.executeQuery().size());
assertEquals(0, builder
.select(p, e, c)
.from(p)
.leftJoin(c).on(c.pxy().getId()).eq(p.pxy().getCompany().getId())
.eqProperty(p.pxy().getCompany())
.leftJoin(e).on(e.pxy().getNumber()).eq(p.pxy().getEmployee().getNumber())
.eqProperty(p.pxy().getEmployee())
.where()
.openPar()
.clauseIf(true, c.pxy().getName())
.condition(new Like("Google"))
.or()
.clauseIf(false, c.pxy().getName())
.condition(new Like("Oracle"))
.closePar()
.and()
.clause(c.pxy().getName())
.condition(new Like("Oracle"))
.executeQuery().size());
assertEquals(4, builder
.select(p, e, c)
.from(p)
.leftJoin(c).pkOf(c).in(p)
.inProperty(p.pxy().getCompany())
.leftJoin(e).pkOf(e).in(p)
/trunk/src/main/java/org/mentabean/jdbc/QueryBuilder.java
31,7 → 31,6
*/
public class QueryBuilder {
 
private static final String REGEX = "(AND|OR|\\([\\s]*?\\)|WHERE|HAVING)[\\s]*?$";
private StringBuilder sb = new StringBuilder();
private final AnsiSQLBeanSession session;
private List<Object> paramValues = new ArrayList<Object>();
175,7 → 174,7
}
private void applyRegex() {
remove(REGEX);
remove("(AND|OR|\\([\\s]*?\\)|WHERE|HAVING)[\\s]*?$");
}
private void remove(String regex) {
208,7 → 207,6
parenthesis--;
sb.append(')');
applyRegex();
clauseIf = true;
}
private Alias<?> findAlias() {