1 18 19 package org.apache.beehive.controls.system.jdbc.parser; 20 21 import org.apache.beehive.controls.api.ControlException; 22 23 import java.util.HashMap ; 24 import java.io.StringReader ; 25 26 44 public final class SqlParser { 45 46 private HashMap <String , SqlStatement> _cachedSqlStatements; 48 49 52 public SqlParser() { 53 _cachedSqlStatements = new HashMap <String , SqlStatement>(); 54 } 55 56 62 public SqlStatement parse(String sql) { 63 64 if (_cachedSqlStatements.containsKey(sql)) { 66 return _cachedSqlStatements.get(sql); 67 } 68 69 SqlGrammar _parser = new SqlGrammar(new StringReader (sql)); 70 SqlStatement parsed = null; 71 try { 72 parsed = _parser.parse(); 73 } catch (ParseException e) { 74 throw new ControlException("Error parsing SQL statment." + e.getMessage(), e); 75 } catch (TokenMgrError tme) { 76 throw new ControlException("Error parsing SQL statment. " + tme.getMessage(), tme); 77 } 78 79 if (parsed.isCacheable()) { 80 _cachedSqlStatements.put(sql, parsed); 81 } 82 return parsed; 83 } 84 } 85 | Popular Tags |