1 30 package com.genimen.djeneric.repository.sqlparser; 31 32 import java.io.BufferedReader ; 33 import java.io.File ; 34 import java.io.FileReader ; 35 36 import com.genimen.djeneric.repository.sqlparser.core.ParseException; 37 import com.genimen.djeneric.repository.sqlparser.core.SqlParserEngine; 38 import com.genimen.djeneric.repository.sqlparser.core.TokenContext; 39 import com.genimen.djeneric.util.DjLogger; 40 41 public class SqlParser implements SqlParserEngineListener 42 { 43 String _theStatement = null; 44 45 public SqlParser() 46 { 47 } 48 49 public SqlParser(String stmt) 50 { 51 setStatement(stmt); 52 } 53 54 public void setStatement(String stmt) 55 { 56 _theStatement = stmt; 57 } 58 59 public String parse() throws Exception 60 { 61 SqlParserEngine parser = SqlParserEngine.parse(_theStatement, this); 62 return parser.getResult(); 63 } 64 65 public void handleTable(TokenContext ctxt, StringBuffer tableName, StringBuffer tableAlias) throws ParseException 66 { 67 } 69 70 public void handleColumn(TokenContext ctxt, StringBuffer tableAlias, StringBuffer columnName) throws ParseException 71 { 72 } 74 75 public void handleParameter(TokenContext ctxt, StringBuffer parameterName) throws ParseException 76 { 77 } 79 80 public void handleColumnExpression(TokenContext ctxt, StringBuffer expression) throws ParseException 81 { 82 } 84 85 public void handleSelectedColumnExpression(TokenContext ctxt, StringBuffer expression, StringBuffer aliasName) 86 throws ParseException 87 { 88 } 90 91 public void handleSelectList(TokenContext ctxt, StringBuffer selectList) throws ParseException 92 { 93 } 95 96 public void handleTableList(TokenContext ctxt, StringBuffer tableList) throws ParseException 97 { 98 } 100 101 public void handleGroupBy(TokenContext ctxt, StringBuffer groupBy) throws ParseException 102 { 103 } 105 106 public void handleWhereClause(TokenContext ctxt, StringBuffer where) throws ParseException 107 { 108 } 110 111 public void handleHaving(TokenContext ctxt, StringBuffer having) throws ParseException 112 { 113 } 115 116 public void handleOrderBy(TokenContext ctxt, StringBuffer orderBy) throws ParseException 117 { 118 } 120 121 public void handleFunction(TokenContext ctxt, StringBuffer functionName, StringBuffer args) throws ParseException 122 { 123 } 125 126 public void enterStatement(TokenContext ctxt, int 127 statementType) 128 { 129 } 130 131 public void exitStatement(TokenContext ctxt, int 132 statementType, StringBuffer theStatement) 133 { 134 } 135 136 public void handleInsertColumnList(TokenContext ctxt, StringBuffer insertColumns) throws ParseException 137 { 138 } 139 140 public void handleInsertValueList(TokenContext ctxt, StringBuffer insertColumns) throws ParseException 141 { 142 } 143 144 public void handleSelectFullRecord(TokenContext ctxt, String tableAlias, StringBuffer fullRecordSelect) 145 throws ParseException 146 { 147 } 148 149 public static void main(String [] args) 150 { 151 try 152 { 153 if (args.length < 1) 154 { 155 System.out.println("Usage: java " + SqlParser.class.getName() + " <input file>"); 156 return; 157 } 158 File inFile = new File (args[0]); 159 BufferedReader br = new BufferedReader (new FileReader (inFile)); 160 StringBuffer src = new StringBuffer (100); 161 String ln; 162 while ((ln = br.readLine()) != null) 163 { 164 src.append(ln); 165 src.append("\n"); 166 } 167 br.close(); 168 169 SqlParser parser = new SqlParser(); 170 parser.setStatement(src.toString()); 171 172 System.err.println(parser.parse()); 173 } 174 catch (Exception x) 175 { 176 DjLogger.log(x); 177 } 178 } 179 } | Popular Tags |