MentaBean

Compare Revisions

Ignore whitespace Rev 204 → Rev 205

/trunk/src/test/java/org/mentabean/jdbc/QueryBuilderTest.java
1293,6 → 1293,31
.closePar()
.executeQuery().size());
assertEquals(2, 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(false, c.pxy().getName())
.condition(new Like("Oracle"))
.closePar()
.or()
.openPar()
.clauseIf(true, 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)
/trunk/src/main/java/org/mentabean/jdbc/QueryBuilder.java
29,9 → 29,11
* @author erico
*
*/
@SuppressWarnings({"rawtypes", "unchecked"})
public class QueryBuilder {
 
private static final String REGEX = "(AND|OR|\\([\\s]*?\\)|WHERE|HAVING)[\\s]*?$";
private static final String NO_CLAUSE_REGEX = ".*(WHERE|HAVING)[\\s]*?$";
private StringBuilder sb = new StringBuilder();
private final AnsiSQLBeanSession session;
private List<Object> paramValues = new ArrayList<Object>();
186,6 → 188,9
private void addAnd() {
if (clauseIf) {
if (sb.toString().matches(NO_CLAUSE_REGEX)) {
return;
}
applyRegex();
sb.append(" AND ");
}
193,6 → 198,9
private void addOr() {
if (clauseIf) {
if (sb.toString().matches(NO_CLAUSE_REGEX)) {
return;
}
applyRegex();
sb.append(" OR ");
}
1614,7 → 1622,6
}
}
@SuppressWarnings("unchecked")
public <T> T getValueFromResultSet(ResultSet rs, String name) throws SQLException {
Sentence s = sentences.get(name);