Created
June 20, 2016 19:44
-
-
Save yonilevy/1ff55f776bc7fb81ebdddb91a8269926 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class QueryWhereBuilder<T,U> { | |
private final Map<String, Object> whereTerms = new HashMap<>(); | |
private final QueryBuilder<T, U> qb; | |
public QueryWhereBuilder(QueryBuilder<T,U> qb) { | |
this.qb = qb; | |
} | |
public void add(String key, Object val) { | |
whereTerms.put(key, val); | |
} | |
public void build() throws SQLException { | |
if (whereTerms.isEmpty()) { | |
return; | |
} | |
Where<T, U> where = qb.where(); | |
boolean first = true; | |
for (final String key : whereTerms.keySet()) { | |
if (!first) { | |
where.and(); | |
} | |
where.eq(key, whereTerms.get(key)); | |
first = false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment