Changeset 37 for trunk/fmgVen/src/com/fmguler/ven/Criteria.java
- Timestamp:
- Mar 20, 2012, 2:40:52 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/fmgVen/src/com/fmguler/ven/Criteria.java
r32 r37 43 43 public class Criteria { 44 44 private StringBuffer criteriaStringBuffer = new StringBuffer(); //for string criteria 45 private StringBuffer orderStringBuffer = new StringBuffer(); //for ordering 45 46 private LinkedList criterionList = new LinkedList(); //for typed criteria 46 47 private Map parameters = new HashMap(); //the parameters used in criteria string … … 99 100 } 100 101 102 /** 103 * Return order string to SQL 104 */ 105 public String orderStringToSQL() { 106 if (orderStringBuffer.length() == 0) return ""; 107 orderStringBuffer.insert(0, " order by"); 108 return orderStringBuffer.toString(); 109 } 110 101 111 //-------------------------------------------------------------------------- 102 112 //Typed Criteria Methods … … 153 163 */ 154 164 public Criteria orderAsc(String attribute) { 155 //Not implemented yet. 165 if (this.orderStringBuffer.length() != 0) this.orderStringBuffer.append(","); 166 this.orderStringBuffer.append(" ").append(convertAttributeToAlias(attribute)).append(" asc"); 156 167 return this; 157 168 } … … 161 172 */ 162 173 public Criteria orderDesc(String attribute) { 163 //Not implemented yet. 174 if (this.orderStringBuffer.length() != 0) this.orderStringBuffer.append(","); 175 this.orderStringBuffer.append(" ").append(convertAttributeToAlias(attribute)).append(" desc"); 164 176 return this; 165 177 } … … 223 235 stack.push(sr); 224 236 } else if (conn.equals(Criterion.CONN_OR)) { 225 226 227 228 229 230 231 232 233 237 String s1 = (String)stack.pop(); 238 String s2 = (String)stack.pop(); 239 String sr = "(" + s1 + " or " + s2 + ")"; 240 stack.push(sr); 241 } else if (conn.equals(Criterion.CONN_NOT)) { 242 String s = (String)stack.pop(); 243 String sr = "not (" + s + ")"; 244 stack.push(sr); 245 } 234 246 } 235 247 } … … 284 296 .and() //connect previous criteria with and 285 297 .isNull("SomeDomainObject.description") //attribute is null 286 .or(); //connect previous criteria with and 298 .or() //connect previous criteria with or 299 .orderDesc("SomeDomainObject.name"); //order by some attribute 287 300 288 301 //print the resulting where clause SQL 289 302 System.out.println(criteria.criteriaToSQL()); 303 304 //print the resulting order clause SQL 305 System.out.println(criteria.orderStringToSQL()); 290 306 291 307 //the result is;
Note: See TracChangeset
for help on using the changeset viewer.