MentaBean

Compare Revisions

Ignore whitespace Rev 203 → Rev 204

/trunk/src/test/java/org/mentabean/jdbc/QueryBuilderTest.java
1201,9 → 1201,121
.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,6 → 31,7
*/
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>();
174,7 → 175,7
}
private void applyRegex() {
remove("(AND|OR|\\([\\s]*?\\)|WHERE|HAVING)[\\s]*?$");
remove(REGEX);
}
private void remove(String regex) {
207,6 → 208,7
parenthesis--;
sb.append(')');
applyRegex();
clauseIf = true;
}
private Alias<?> findAlias() {