Public Member Functions | |
SelectRequest (String sqlQuery, boolean escapeProcessing, int timeout, String lineSeparator, DatabaseSchema schema, int granularity, boolean isCaseSensitive) throws SQLException | |
SelectRequest (String sqlQuery, boolean escapeProcessing, int timeout, String lineSeparator) | |
void | parse (DatabaseSchema schema, int granularity, boolean isCaseSensitive) throws SQLException |
void | cloneParsing (AbstractRequest request) |
ArrayList | getSelect () |
ArrayList | getFrom () |
ArrayList | getAliasedFrom () |
ArrayList | getWhere () |
ArrayList | getOrderBy () |
Hashtable | getWhereValues () |
boolean | isReadRequest () |
boolean | isWriteRequest () |
boolean | isUnknownRequest () |
String | getPkValue () |
void | setPkValue (String pkValue) |
String | getCursorName () |
void | setCursorName (String cursorName) |
void | debug () |
Public Attributes | |
transient int | funcType = 0 |
Static Public Attributes | |
final int | NO_FUNCTION = 0 |
final int | MAX_FUNCTION = 1 |
final int | MIN_FUNCTION = 2 |
final int | AVERAGE_FUNCTION = 3 |
final int | COUNT_FUNCTION = 4 |
final int | SUM_FUNCTION = 5 |
SelectRequest
is an SQL request of the following syntax:
SELECT [ALL|DISTINCT] select-item[,select-item]* FROM table-specification[,table-specification]* [WHERE search-condition] [GROUP BY grouping-column[,grouping-column]] [HAVING search-condition] [ORDER BY sort-specification[,sort-specification]] [LIMIT ignored]
Note that table-specification in the FROM
clause can be a sub-select. Everything after the end of the WHERE
clause is ignored.
Definition at line 63 of file SelectRequest.java.
|
Creates a new
The SQL request is parsed and selected tables and columns are retrieved using the given If the syntax is incorrect an exception is thrown.
Definition at line 133 of file SelectRequest.java. References org.objectweb.cjdbc.common.sql.SelectRequest.parse(). 00136 { 00137 this(sqlQuery, escapeProcessing, timeout, lineSeparator); 00138 parse(schema, granularity, isCaseSensitive); 00139 }
|
|
Creates a new The request is not parsed but it can be done later by a call to parse(DatabaseSchema, int, boolean).
Definition at line 156 of file SelectRequest.java. 00158 { 00159 super(sqlQuery, escapeProcessing, timeout, lineSeparator); 00160 cacheable = RequestType.CACHEABLE; 00161 isParsed = false; 00162 pkValue = null; 00163 }
|
|
Implements org.objectweb.cjdbc.common.sql.AbstractRequest. Definition at line 344 of file SelectRequest.java. References org.objectweb.cjdbc.common.sql.AbstractRequest.getCacheAbility(), org.objectweb.cjdbc.common.sql.SelectRequest.getFrom(), org.objectweb.cjdbc.common.sql.SelectRequest.getPkValue(), org.objectweb.cjdbc.common.sql.SelectRequest.getSelect(), org.objectweb.cjdbc.common.sql.SelectRequest.getWhere(), and org.objectweb.cjdbc.common.sql.AbstractRequest.isParsed. 00345 { 00346 if (!request.isParsed()) 00347 return; 00348 SelectRequest selectRequest = (SelectRequest) request; 00349 select = selectRequest.getSelect(); 00350 from = selectRequest.getFrom(); 00351 where = selectRequest.getWhere(); 00352 cacheable = selectRequest.getCacheAbility(); 00353 pkValue = selectRequest.getPkValue(); 00354 isParsed = true; 00355 }
|
|
Displays some debugging information about this request. Reimplemented from org.objectweb.cjdbc.common.sql.AbstractRequest. Definition at line 1065 of file SelectRequest.java. Referenced by org.objectweb.cjdbc.controller.requestmanager.RequestManager.execReadStoredProcedure(), org.objectweb.cjdbc.controller.requestmanager.RequestManager.execWriteStoredProcedure(), org.objectweb.cjdbc.controller.cache.result.ResultCache.getFromCache(), and org.objectweb.cjdbc.controller.cache.result.ResultCache.removeFromCache(). 01066 { 01067 super.debug(); 01068 if (select != null) 01069 { 01070 System.out.println("Selected columns:"); 01071 for (int i = 0; i < select.size(); i++) 01072 System.out 01073 .println(" " + ((TableColumn) select.get(i)).getColumnName()); 01074 } 01075 else 01076 System.out.println("No information on selected columns"); 01077 01078 if (select != null) 01079 { 01080 System.out.println(""); 01081 System.out.println("From tables:"); 01082 for (int i = 0; i < from.size(); i++) 01083 System.out.println(" " + from.get(i)); 01084 } 01085 else 01086 System.out.println("No information on from tables"); 01087 01088 System.out.println(""); 01089 System.out.println("Where columns:"); 01090 if (where == null) 01091 System.out.println(" No Where clause"); 01092 else 01093 for (int i = 0; i < where.size(); i++) 01094 System.out.print(" " + ((TableColumn) where.get(i)).getColumnName()); 01095 01096 System.out.println(""); 01097 System.out.println("PK value: " + pkValue); 01098 }
|
|
Returns an
Definition at line 958 of file SelectRequest.java. 00959 {
00960 return aliasFrom;
00961 }
|
|
Returns the cursorName value.
Definition at line 1047 of file SelectRequest.java. Referenced by org.objectweb.cjdbc.controller.virtualdatabase.ControllerResultSet.ControllerResultSet(). 01048 {
01049 return cursorName;
01050 }
|
|
Returns an
Definition at line 946 of file SelectRequest.java. Referenced by org.objectweb.cjdbc.common.sql.SelectRequest.cloneParsing(), org.objectweb.cjdbc.common.sql.CreateRequest.parse(), org.objectweb.cjdbc.controller.cache.result.ResultCacheTable.processAddToCache(), org.objectweb.cjdbc.controller.cache.result.ResultCacheColumnUnique.processAddToCache(), and org.objectweb.cjdbc.controller.cache.result.ResultCacheColumn.processAddToCache(). 00947 {
00948 return from;
00949 }
|
|
Returns an
Definition at line 982 of file SelectRequest.java. 00983 {
00984 return order;
00985 }
|
|
Definition at line 1029 of file SelectRequest.java. Referenced by org.objectweb.cjdbc.common.sql.SelectRequest.cloneParsing(), and org.objectweb.cjdbc.controller.cache.result.ResultCacheColumnUnique.processAddToCache(). 01030 {
01031 return pkValue;
01032 }
|
|
Returns an
Definition at line 934 of file SelectRequest.java. Referenced by org.objectweb.cjdbc.common.sql.SelectRequest.cloneParsing(), org.objectweb.cjdbc.common.sql.CreateRequest.parse(), org.objectweb.cjdbc.controller.cache.result.ResultCacheColumnUnique.processAddToCache(), and org.objectweb.cjdbc.controller.cache.result.ResultCacheColumn.processAddToCache(). 00935 {
00936 return select;
00937 }
|
|
Returns an
Definition at line 970 of file SelectRequest.java. Referenced by org.objectweb.cjdbc.common.sql.SelectRequest.cloneParsing(), org.objectweb.cjdbc.controller.cache.result.ResultCacheColumnUnique.processAddToCache(), and org.objectweb.cjdbc.controller.cache.result.ResultCacheColumn.processAddToCache(). 00971 {
00972 return where;
00973 }
|
|
Returns an
Definition at line 994 of file SelectRequest.java. Referenced by org.objectweb.cjdbc.controller.cache.result.schema.CacheDatabaseColumn.invalidateAllUniqueWithValuesAndAllNonUnique(). 00995 {
00996 return whereValues;
00997 }
|
|
Implements org.objectweb.cjdbc.common.sql.AbstractRequest. Definition at line 1003 of file SelectRequest.java. 01004 { 01005 return true; 01006 }
|
|
Implements org.objectweb.cjdbc.common.sql.AbstractRequest. Definition at line 1021 of file SelectRequest.java. 01022 { 01023 return false; 01024 }
|
|
Implements org.objectweb.cjdbc.common.sql.AbstractRequest. Definition at line 1012 of file SelectRequest.java. 01013 { 01014 return false; 01015 }
|
|
The result of the parsing is accessible through the getSelect(), getFrom()and getWhere()functions.
Implements org.objectweb.cjdbc.common.sql.AbstractRequest. Definition at line 173 of file SelectRequest.java. Referenced by org.objectweb.cjdbc.common.sql.CreateRequest.parse(), and org.objectweb.cjdbc.common.sql.SelectRequest.SelectRequest(). 00175 { 00176 if (granularity == ParsingGranularities.NO_PARSING) 00177 { 00178 cacheable = RequestType.CACHEABLE; 00179 isParsed = true; 00180 return; 00181 } 00182 00183 // Sanity check 00184 if (schema == null) 00185 throw new SQLException( 00186 "Unable to parse request with an undefined database schema"); 00187 00188 String originalSQL = this.trimCarriageReturn(); 00189 String sql = originalSQL.toLowerCase(); 00190 if (!isCaseSensitive) 00191 originalSQL = sql; 00192 00193 // Strip 'select' 00194 sql = sql.substring(6).trim(); 00195 00196 // Look for DISTINCT 00197 if (sql.startsWith("distinct")) 00198 sql = sql.substring(8).trim(); // Strip 'distinct ' 00199 00200 // Look for the begining of the FROM clause 00201 int fromIndex = sql.indexOf("from "); 00202 if (fromIndex == -1) 00203 throw new SQLException( 00204 "Unable to find the FROM keyword in this SELECT statement: '" + sql 00205 + "'"); 00206 00207 // Keep SELECT clause for later, we first have to check the 00208 // tables involved in the FROM clause 00209 int fshift = originalSQL.length() - sql.length(); 00210 String selectClause = (isCaseSensitive) ? originalSQL.substring(fshift, 00211 fshift + fromIndex) : sql.substring(0, fromIndex); 00212 00213 // Get rid of FROM 00214 sql = sql.substring(fromIndex + 5).trim(); 00215 00216 // Now find the boundaries of the FROM and WHERE clauses 00217 int whereIndex = 0; 00218 int parenthesis = 0; 00219 int lastParenthesisIdx = 0; 00220 boolean foundWhere = false; 00221 do 00222 { 00223 switch (sql.charAt(whereIndex)) 00224 { 00225 case '(' : 00226 parenthesis++; 00227 break; 00228 case ')' : 00229 parenthesis--; 00230 lastParenthesisIdx = whereIndex; 00231 break; 00232 case 'w' : 00233 if (parenthesis == 0) 00234 try 00235 { 00236 foundWhere = (sql.charAt(whereIndex + 1) == 'h') 00237 && (sql.charAt(whereIndex + 2) == 'e') 00238 && (sql.charAt(whereIndex + 3) == 'r') 00239 && (sql.charAt(whereIndex + 4) == 'e'); 00240 } 00241 catch (StringIndexOutOfBoundsException ignore) 00242 { 00243 foundWhere = false; 00244 } 00245 default : 00246 break; 00247 } 00248 whereIndex++; 00249 } 00250 while ((!foundWhere) && (whereIndex < sql.length())); 00251 if (foundWhere) 00252 whereIndex--; 00253 else 00254 whereIndex = -1; 00255 00256 // Warning! Here if whereIndex is -1 (no where clause) 00257 // endWhere is used to find the end of the FROM clause. 00258 // The variable name can be misleading but it's faster to do it this 00259 // way. 00260 int endWhere = sql.indexOf("group by ", lastParenthesisIdx); 00261 if (endWhere == -1) 00262 { 00263 endWhere = sql.indexOf("having ", lastParenthesisIdx); 00264 if (endWhere == -1) 00265 { 00266 endWhere = sql.indexOf("order by ", lastParenthesisIdx); 00267 if (endWhere == -1) 00268 { 00269 endWhere = sql.indexOf("limit ", lastParenthesisIdx); 00270 if (endWhere == -1) 00271 endWhere = sql.length(); 00272 } 00273 } 00274 } 00275 int endFrom; 00276 if (whereIndex == -1) 00277 endFrom = endWhere; 00278 else 00279 endFrom = whereIndex; 00280 00281 try 00282 { 00283 switch (granularity) 00284 { 00285 case ParsingGranularities.NO_PARSING : 00286 return; 00287 case ParsingGranularities.TABLE : 00288 int shift = originalSQL.length() - sql.length(); 00289 from = getFromTables(originalSQL.substring(shift, shift + endFrom) 00290 .trim(), schema, isCaseSensitive); 00291 break; 00292 case ParsingGranularities.COLUMN : 00293 case ParsingGranularities.COLUMN_UNIQUE : 00294 shift = originalSQL.length() - sql.length(); 00295 from = getFromTables(originalSQL.substring(shift, shift + endFrom) 00296 .trim(), schema, isCaseSensitive); 00297 // Find columns selected in the SELECT clause 00298 select = getSelectedColumns(selectClause, from, isCaseSensitive); 00299 if (whereIndex > 1) 00300 // Find columns involved in the WHERE clause (5="WHERE") 00301 where = getWhereColumns(originalSQL.substring( 00302 shift + whereIndex + 5, shift + endWhere).trim(), from, 00303 granularity == ParsingGranularities.COLUMN_UNIQUE, 00304 isCaseSensitive); 00305 break; 00306 default : 00307 throw new SQLException("Unsupported parsing granularity: '" 00308 + granularity + "'"); 00309 } 00310 } 00311 catch (SQLException e) 00312 { 00313 from = null; 00314 select = null; 00315 where = null; 00316 cacheable = RequestType.UNCACHEABLE; 00317 throw e; 00318 } 00319 00320 //Gokul added this 00321 //I need to have the aliases to determine if any of the OrderBy columns 00322 //are referenced using their alias 00323 00324 aliasFrom = from; 00325 00326 if (from != null) 00327 { 00328 // Convert 'from' to an ArrayList of String objects instead of 00329 // AliasedTables objects 00330 int size = from.size(); 00331 ArrayList unaliased = new ArrayList(size); 00332 for (int i = 0; i < size; i++) 00333 unaliased 00334 .add(((AliasedDatabaseTable) from.get(i)).getTable().getName()); 00335 from = unaliased; 00336 } 00337 00338 isParsed = true; 00339 }
|
|
Sets the cursorName value.
Definition at line 1057 of file SelectRequest.java. References org.objectweb.cjdbc.common.sql.SelectRequest.cursorName. Referenced by org.objectweb.cjdbc.driver.Statement.executeQuery(). 01058 {
01059 this.cursorName = cursorName;
01060 }
|
|
Definition at line 1037 of file SelectRequest.java. References org.objectweb.cjdbc.common.sql.SelectRequest.pkValue. 01038 {
01039 this.pkValue = pkValue;
01040 }
|
|
Represents a SQL average() macro Definition at line 87 of file SelectRequest.java. |
|
Represents a SQL count() macro Definition at line 89 of file SelectRequest.java. |
|
Need to keep track of type of query, e.g. MAX, COUNT, etc. Definition at line 94 of file SelectRequest.java. |
|
Represents a SQL max() macro Definition at line 83 of file SelectRequest.java. |
|
Represents a SQL min() macro Definition at line 85 of file SelectRequest.java. |
|
Some values to keep track of function in the SELECT request Definition at line 81 of file SelectRequest.java. |
|
Represents a SQL sum() macro Definition at line 91 of file SelectRequest.java. |