This is the same question as:
How to dynamically generate SQL query based on user's selections?
The only difference is, that I\'m interested in seeing soluti
In my code, I'm using AND and OR objects for this. They take lists as parameters (looks nice with Java 5's variadic arguments) and concatenate them in Strings with the necessary spaces and parentheses. Pseudo code:
AND(WhereCond ... conds) { this.conds = conds; }
toString() { return conds.length == 0 ? "" : "(" + join(conds, " AND ") + ")" };
where join() converts the object array to string array and then joins the elements with the parameter.