1 package org.apache.ojb.jdo; 2 3 17 18 import javax.jdo.Extent; 19 import javax.jdo.JDOUserException; 20 import javax.jdo.PersistenceManager; 21 import javax.jdo.Query; 22 23 import org.apache.ojb.jdo.jdoql.Expression; 24 import org.apache.ojb.jdo.jdoql.LocalVariable; 25 import org.apache.ojb.jdo.jdoql.QueryParsingHelper; 26 import org.apache.ojb.jdo.jdoql.QueryTreeResolver; 27 28 import java.util.*; 29 30 46 47 public class QueryImpl implements Query 48 { 49 50 private PersistenceManagerImpl _persistenceManager; 51 52 private Class _searchedClass; 53 54 private Collection _candidateInstances; 55 56 private String _filterString; 57 58 private Expression _filterExpression; 59 60 private String _importString; 61 62 private Collection _imports; 63 64 private String _parameterString; 65 66 private Map _parameters; 67 68 private String _variableString; 69 70 private Map _variables; 71 72 private String _orderingString; 73 74 private Collection _orderings; 75 76 private boolean _ignoreCache; 77 78 private boolean _needsCompilation = true; 79 80 85 public QueryImpl(PersistenceManagerImpl pm) 86 { 87 _persistenceManager = pm; 88 _candidateInstances = null; 89 } 90 91 96 public PersistenceManager getPersistenceManager() 97 { 98 return _persistenceManager; 99 } 100 101 106 public void setClass(Class searchedClass) 107 { 108 _searchedClass = searchedClass; 109 _needsCompilation = true; 110 } 111 112 117 public Class getSearchedClass() 118 { 119 return _searchedClass; 120 } 121 122 125 public void setCandidates(Extent extent) 126 { 127 _searchedClass = ((ExtentImpl)extent).ojbGetClass(); 128 _needsCompilation = true; 129 } 130 131 public void setCandidates(Collection candidates) 132 { 133 _candidateInstances = candidates; 134 _needsCompilation = true; 135 } 136 137 142 public void setFilter(String filter) throws JDOUserException 143 { 144 _filterString = filter; 145 _filterExpression = new QueryParsingHelper().parseFilter(filter); 146 _needsCompilation = true; 147 } 148 149 154 public Expression getFilterExpression() 155 { 156 return _filterExpression; 157 } 158 159 165 public void declareImports(String imports) throws JDOUserException 166 { 167 _importString = imports; 168 _imports = new QueryParsingHelper().parseImports(imports); 169 _needsCompilation = true; 170 } 171 172 177 public Collection getImports() 178 { 179 return _imports; 180 } 181 182 187 public void declareParameters(String params) throws JDOUserException 188 { 189 _parameterString = params; 190 _parameters = new QueryParsingHelper().parseParameters(params); 191 _needsCompilation = true; 192 } 193 194 200 public Map getParameters() 201 { 202 return _parameters; 203 } 204 205 211 public LocalVariable getParameter(String name) 212 { 213 return (LocalVariable)_variables.get(name); 214 } 215 216 221 public void declareVariables(String variables) throws JDOUserException 222 { 223 _variableString = variables; 224 _variables = new QueryParsingHelper().parseVariables(variables); 225 _needsCompilation = true; 226 } 227 228 234 public Map getVariables() 235 { 236 return _variables; 237 } 238 239 245 public LocalVariable getVariable(String name) 246 { 247 return (LocalVariable)_variables.get(name); 248 } 249 250 255 public void setOrdering(String orderings) throws JDOUserException 256 { 257 _orderingString = orderings; 258 _orderings = new QueryParsingHelper().parseOrderings(orderings); 259 _needsCompilation = true; 260 } 261 262 267 public Collection getOrderings() 268 { 269 return _orderings; 270 } 271 272 277 public void setIgnoreCache(boolean shouldIgnoreCache) 278 { 279 _ignoreCache = shouldIgnoreCache; 280 } 281 282 287 public boolean getIgnoreCache() 288 { 289 return _ignoreCache; 290 } 291 292 297 public void compile() 298 { 299 if (_needsCompilation) 300 { 301 new QueryTreeResolver().resolveAndCheck(this); 303 throw new UnsupportedOperationException ("Not yet implemented"); 309 310 } 312 } 313 314 319 public Object execute() 320 { 321 if (_needsCompilation) 322 { 323 compile(); 324 } 325 throw new UnsupportedOperationException ("Not yet implemented"); 326 } 327 328 331 public Object execute(Object o) 332 { 333 throw new UnsupportedOperationException ("Not yet implemented!"); 334 } 335 336 public Object execute(Object o, Object o1) 337 { 338 throw new UnsupportedOperationException ("Not yet implemented!"); 339 } 340 341 public Object execute(Object o, Object o1, Object o2) 342 { 343 throw new UnsupportedOperationException ("Not yet implemented!"); 344 } 345 346 public Object executeWithMap(Map map) 347 { 348 throw new UnsupportedOperationException ("Not yet implemented!"); 349 } 350 351 public Object executeWithArray(Object [] objects) 352 { 353 throw new UnsupportedOperationException ("Not yet implemented!"); 354 } 355 356 359 public void close(Object o) 360 { 361 } 362 363 public void closeAll() 364 { 365 } 366 367 372 QueryImpl ojbClone() 373 { 374 QueryImpl query = new QueryImpl(_persistenceManager); 375 376 query.setClass(_searchedClass); 377 query.setCandidates(_candidateInstances); 378 query.declareImports(_importString); 379 query.declareParameters(_parameterString); 380 query.declareVariables(_variableString); 381 query.setFilter(_filterString); 382 query.setOrdering(_orderingString); 383 384 return query; 385 } 386 387 } 388 | Popular Tags |