1 7 package com.jofti.parser; 8 9 import com.jofti.api.IndexQuery; 10 import com.jofti.core.IParsedQuery; 11 import com.jofti.exception.JoftiException; 12 import com.jofti.introspect.ClassIntrospector; 13 import com.jofti.query.EJBQuery; 14 import com.jofti.query.SQLQuery; 15 16 20 public class ParserManager { 21 22 23 24 private IQueryParser nativeQueryParser = null; 25 private IQueryParser ejb3QueryParser = null; 26 27 public ParserManager(ClassIntrospector introspector){ 28 nativeQueryParser = new NativeQueryParser(introspector); 29 ejb3QueryParser = new EJBQueryParser(introspector); 30 } 31 32 39 public IParsedQuery parseQuery(IndexQuery originalQuery) throws JoftiException{ 40 if (originalQuery instanceof EJBQuery){ 41 return ejb3QueryParser.parseQuery(originalQuery); 42 }else if (originalQuery instanceof SQLQuery) { 43 return nativeQueryParser.parseQuery(originalQuery); 44 45 }else{ 46 return new ConvenienceQueryWrapper(originalQuery); 47 } 48 49 50 } 51 52 public IndexQuery addQuery(String name, IndexQuery originalQuery) throws JoftiException{ 53 54 if (originalQuery instanceof EJBQuery){ 55 return ejb3QueryParser.parseQuery(name,originalQuery); 56 }else if (originalQuery instanceof SQLQuery){ 57 return nativeQueryParser.parseQuery(name, originalQuery); 58 } else{ 59 throw new JoftiException("Only " + EJBQuery.class + " or " + SQLQuery.class + " are allowed to be added"); 60 61 } 62 63 } 64 65 public IndexQuery addQuery(String name, String query) throws JoftiException{ 66 67 return addQuery(name, new EJBQuery(query)); 68 69 } 70 public IndexQuery getQuery(String name){ 71 IndexQuery query = ejb3QueryParser.getQuery(name); 72 if (query ==null){ 73 query = nativeQueryParser.getQuery(name); 74 } 75 return query; 76 } 77 78 } 79 | Popular Tags |