1 15 package org.josql.utils; 16 17 import java.util.List ; 18 import java.util.Comparator ; 19 20 import org.josql.Query; 21 import org.josql.QueryParseException; 22 import org.josql.QueryExecutionException; 23 24 import org.josql.internal.ListExpressionComparator; 25 26 78 public class JoSQLComparator implements Comparator 79 { 80 81 private Query q = null; 82 private Exception exp = null; 83 private ListExpressionComparator c = null; 84 85 90 public void doExecuteOn (List l) 91 throws QueryExecutionException 92 { 93 94 this.q.doExecuteOn (l, 95 Query.ALL); 96 97 } 98 99 104 public void clearCache () 105 { 106 107 if (this.q != null) 108 { 109 110 this.c.clearCache (); 111 112 } 113 114 } 115 116 122 public boolean isCaching () 123 throws IllegalStateException 124 { 125 126 if ((this.q == null) 127 || 128 (!this.q.parsed ()) 129 ) 130 { 131 132 throw new IllegalStateException ("Query has not yet been parsed."); 133 134 } 135 136 return this.c.isCaching (); 137 138 } 139 140 146 public void setCaching (boolean b) 147 throws IllegalStateException 148 { 149 150 if ((this.q == null) 151 || 152 (!this.q.parsed ()) 153 ) 154 { 155 156 throw new IllegalStateException ("Query has not yet been parsed."); 157 158 } 159 160 this.c.setCaching (b); 161 162 } 163 164 170 public JoSQLComparator (String q) 171 throws QueryParseException 172 { 173 174 this.setQuery (q); 175 176 } 177 178 184 public int compare (Object o1, 185 Object o2) 186 { 187 188 try 189 { 190 191 return c.ci (o1, 192 o2); 193 194 } catch (Exception e) { 195 196 this.exp = e; 197 198 return 0; 199 200 } 201 202 } 203 204 211 public JoSQLComparator (Query q) 212 throws IllegalStateException , 213 QueryParseException 214 { 215 216 this.setQuery (q); 217 218 } 219 220 229 public Exception getException () 230 { 231 232 return this.exp; 233 234 } 235 236 243 public void setQuery (String q) 244 throws QueryParseException 245 { 246 247 this.q = new Query (); 248 this.q.parse (q); 249 250 this.c = (ListExpressionComparator) this.q.getOrderByComparator (); 251 252 this.exp = null; 253 254 } 255 256 263 public void setQuery (Query q) 264 throws IllegalStateException , 265 QueryParseException 266 { 267 268 if (!q.parsed ()) 269 { 270 271 throw new IllegalStateException ("Query has not yet been parsed."); 272 273 } 274 275 this.q = q; 276 277 this.c = (ListExpressionComparator) this.q.getOrderByComparator (); 278 279 this.exp = null; 280 281 } 282 283 288 public Query getQuery () 289 { 290 291 return this.q; 292 293 } 294 295 } 296 | Popular Tags |