org.objectweb.cjdbc.sql
Class SelectRequest

java.lang.Object
  extended byorg.objectweb.cjdbc.sql.AbstractRequest
      extended byorg.objectweb.cjdbc.sql.SelectRequest
All Implemented Interfaces:
java.io.Serializable

public class SelectRequest
extends AbstractRequest
implements java.io.Serializable

A 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]
 
Everything after the end of the WHERE clause is ignored.

Version:
1.0
Author:
Emmanuel Cecchet, Julie Marguerite, Mathieu Peltier, Sara Bouchenak
See Also:
Serialized Form

Field Summary
private  java.util.ArrayList from
          ArrayList of String objects.
private  java.util.ArrayList select
          ArrayList of TableColumn objects.
private  java.util.ArrayList where
          ArrayList of TableColumn objects.
private  java.util.Hashtable whereValues
          Hashtable of String keys corresponding to column names and String values corresponding to the values associated with the UNIQUE columns of a UNIQUE SELECT.
 
Fields inherited from class org.objectweb.cjdbc.sql.AbstractRequest
cacheable, escapeProcessing, id, isAutoCommit, isParsed, isReadOnly, login, maxRows, sqlQuery, sqlSkeleton, timeout, transactionId
 
Constructor Summary
SelectRequest(java.lang.String sqlQuery, boolean escapeProcessing, int timeout)
          Creates a new SelectRequest instance.
SelectRequest(java.lang.String sqlQuery, boolean escapeProcessing, int timeout, DatabaseSchema schema, int granularity, boolean isCaseSensitive)
          Creates a new SelectRequest instance.
 
Method Summary
private  void buildValues(java.util.ArrayList dbColumns, java.lang.String whereClause, java.util.ArrayList aliasedFrom)
          Gets all the columns involved in the given WHERE clause and builds the values associated with UNIQUE columns.
private  boolean buildWhereColumns(java.util.ArrayList dbColumns, java.lang.String whereClause, java.util.ArrayList aliasedFrom, boolean isCaseSensitive)
          Gets all the columns involved in the given WHERE clause.
 void cloneParsing(AbstractRequest request)
          Clones the parsing of a request.
 void debug()
          Displays some debugging information about this request.
 java.util.ArrayList getFrom()
          Returns an ArrayList of String objects representing the table names found in the FROM clause of this request.
private  java.util.ArrayList getFromTables(java.lang.String fromClause, DatabaseSchema schema, boolean isCaseSensitive)
          Extracts the tables from the given FROM clause and retrieves their alias if any.
 java.util.ArrayList getSelect()
          Returns an ArrayList of DatabaseColumn objects representing the columns selected in the SELECT clause of this request.
private  java.util.ArrayList getSelectedColumns(java.lang.String selectClause, java.util.ArrayList aliasedFrom, boolean isCaseSensitive)
          Gets all the columns selected in the given SELECT clause.
 java.util.ArrayList getWhere()
          Returns an ArrayList of TableColumn objects representing the columns involved in the WHERE clause of this request.
private  java.util.ArrayList getWhereColumns(java.lang.String whereClause, java.util.ArrayList aliasedFrom, boolean setUniqueCacheable, boolean isCaseSensitive)
          Gets all the columns involved in the given WHERE clause.
 java.util.Hashtable getWhereValues()
          Returns an Hashtable of String keys representing unique column names and String values associated with the columns involved in this request.
 boolean isReadRequest()
          Returns true if this request is a read request (SELECT requests for example perform a read).
private  boolean isSqlFunction(java.lang.String str)
          Checks if the string parameter represents an SQL function, e. g., MAX, COUNT, SUM, etc.
 boolean isUnknownRequest()
          Returns true if the resulting operation on this request is unknown (some non-standard command or stored procedure for example).
 boolean isWriteRequest()
          Returns true if this request is a write request (INSERT or UPDATE for example perform writes).
 void parse(DatabaseSchema schema, int granularity, boolean isCaseSensitive)
          The result of the parsing is accessible through the getSelect(), getFrom() and getWhere() functions.
 
Methods inherited from class org.objectweb.cjdbc.sql.AbstractRequest
equals, getCacheAbility, getEscapeProcessing, getId, getLogin, getMaxRows, getSQL, getSqlSkeleton, getTimeout, getTransactionId, isAutoCommit, isParsed, isReadOnly, setCacheAbility, setId, setIsAutoCommit, setIsReadOnly, setLogin, setMaxRows, setSQL, setSqlSkeleton, setTimeout, setTransactionId, trimCarriageReturn
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

select

private java.util.ArrayList select
ArrayList of TableColumn objects.


from

private java.util.ArrayList from
ArrayList of String objects.


where

private java.util.ArrayList where
ArrayList of TableColumn objects.


whereValues

private java.util.Hashtable whereValues
Hashtable of String keys corresponding to column names and String values corresponding to the values associated with the UNIQUE columns of a UNIQUE SELECT.

Used with the COLUMN_UNIQUE_DELETE granularity.

See Also:
CachingGranularities
Constructor Detail

SelectRequest

public SelectRequest(java.lang.String sqlQuery,
                     boolean escapeProcessing,
                     int timeout,
                     DatabaseSchema schema,
                     int granularity,
                     boolean isCaseSensitive)
              throws java.sql.SQLException
Creates a new SelectRequest instance. The caller must give an SQL request, without any leading or trailing spaces and beginning with 'select ' (it will not be checked).

The SQL request is parsed and selected tables and columns are retrieved using the given DatabaseSchema.

If the syntax is incorrect an exception is thrown.

Parameters:
sqlQuery - the SQL query
escapeProcessing - should the driver to escape processing before sending to the database ?
timeout - an int value
schema - a DatabaseSchema value
granularity - parsing granularity as defined in ParsingGranularities
isCaseSensitive - true if parsing is case sensitive
Throws:
java.sql.SQLException - if an error occurs

SelectRequest

public SelectRequest(java.lang.String sqlQuery,
                     boolean escapeProcessing,
                     int timeout)
Creates a new SelectRequest instance. The caller must give an SQL request, without any leading or trailing spaces and beginning with the 'select' keyword (it will not be checked).

The request is not parsed but it can be done later by a call to parse(DatabaseSchema, int, boolean).

Parameters:
sqlQuery - the SQL query
escapeProcessing - should the driver to escape processing before sending to the database ?
timeout - an int value
See Also:
parse(org.objectweb.cjdbc.sql.schema.DatabaseSchema, int, boolean)
Method Detail

parse

public void parse(DatabaseSchema schema,
                  int granularity,
                  boolean isCaseSensitive)
           throws java.sql.SQLException

The result of the parsing is accessible through the getSelect(), getFrom() and getWhere() functions.

Specified by:
parse in class AbstractRequest
Parameters:
schema - a DatabaseSchema value
granularity - parsing granularity as defined in ParsingGranularities
isCaseSensitive - true if parsing must be case sensitive
Throws:
java.sql.SQLException - if the parsing fails
See Also:
AbstractRequest.parse(org.objectweb.cjdbc.sql.schema.DatabaseSchema, int, boolean)

cloneParsing

public void cloneParsing(AbstractRequest request)
Description copied from class: AbstractRequest
Clones the parsing of a request.

Specified by:
cloneParsing in class AbstractRequest
Parameters:
request - the parsed request to clone
See Also:
AbstractRequest.cloneParsing(AbstractRequest)

getFromTables

private java.util.ArrayList getFromTables(java.lang.String fromClause,
                                          DatabaseSchema schema,
                                          boolean isCaseSensitive)
                                   throws java.sql.SQLException
Extracts the tables from the given FROM clause and retrieves their alias if any.

Parameters:
fromClause - the FROM clause of the request (without the FROM keyword)
schema - the DatabaseSchema this request refers to
isCaseSensitive - true if table name parsing is case sensitive
Returns:
an ArrayList of AliasedDatabaseTable objects
Throws:
java.sql.SQLException - if an error occurs

getSelectedColumns

private java.util.ArrayList getSelectedColumns(java.lang.String selectClause,
                                               java.util.ArrayList aliasedFrom,
                                               boolean isCaseSensitive)
Gets all the columns selected in the given SELECT clause.

The selected columns or tables must be found in the given ArrayList of AliasedDatabaseTable representing the FROM clause of the same request.

Parameters:
selectClause - SELECT clause of the request (without the SELECT keyword)
aliasedFrom - an ArrayList of AliasedDatabaseTable
isCaseSensitive - true if column name parsing is case sensitive
Returns:
an ArrayList of TableColumn

isSqlFunction

private boolean isSqlFunction(java.lang.String str)
Checks if the string parameter represents an SQL function, e. g., MAX, COUNT, SUM, etc.

Parameters:
str - A lower-case string that may represent an SQL function
Returns:
boolean true if it is an SQL function and false otherwise.

getWhereColumns

private java.util.ArrayList getWhereColumns(java.lang.String whereClause,
                                            java.util.ArrayList aliasedFrom,
                                            boolean setUniqueCacheable,
                                            boolean isCaseSensitive)
Gets all the columns involved in the given WHERE clause.

The selected columns or tables must be found in the given ArrayList of AliasedDatabaseTable representing the FROM clause of the same request.

Parameters:
whereClause - WHERE clause of the request (without the WHERE keyword)
aliasedFrom - an ArrayList of AliasedDatabaseTable
setUniqueCacheable - true if we have to check is this select is UNIQUE or not
isCaseSensitive - true if column name parsing is case sensitive
Returns:
an ArrayList of TableColumn

buildWhereColumns

private boolean buildWhereColumns(java.util.ArrayList dbColumns,
                                  java.lang.String whereClause,
                                  java.util.ArrayList aliasedFrom,
                                  boolean isCaseSensitive)
Gets all the columns involved in the given WHERE clause.

The selected columns or tables must be found in the given ArrayList of AliasedDatabaseTable representing the FROM clause of the same request.

Parameters:
dbColumns - an ArrayList of TableColumn
whereClause - WHERE clause of the request (without the WHERE keyword)
aliasedFrom - an ArrayList of AliasedDatabaseTable
isCaseSensitive - a boolean tha is true if column name parsing is case sensitive
Returns:
true if the request is UNIQUE_CACHEABLE and false otherwise.

buildValues

private void buildValues(java.util.ArrayList dbColumns,
                         java.lang.String whereClause,
                         java.util.ArrayList aliasedFrom)
                  throws java.sql.SQLException
Gets all the columns involved in the given WHERE clause and builds the values associated with UNIQUE columns.

The selected columns or tables must be found in the given ArrayList of AliasedDatabaseTable representing the FROM clause of the same request.

Parameters:
whereClause - WHERE clause of the request (without the WHERE keyword)
aliasedFrom - an ArrayList of AliasedDatabaseTable
Returns:
an ArrayList of TableColumn
Throws:
java.sql.SQLException

getSelect

public java.util.ArrayList getSelect()
Returns an ArrayList of DatabaseColumn objects representing the columns selected in the SELECT clause of this request.

Returns:
an ArrayList of TableColumn

getFrom

public java.util.ArrayList getFrom()
Returns an ArrayList of String objects representing the table names found in the FROM clause of this request.

Returns:
an ArrayList of String

getWhere

public java.util.ArrayList getWhere()
Returns an ArrayList of TableColumn objects representing the columns involved in the WHERE clause of this request.

Returns:
an ArrayList of TableColumn

getWhereValues

public java.util.Hashtable getWhereValues()
Returns an Hashtable of String keys representing unique column names and String values associated with the columns involved in this request.

Returns:
an Hashtable value

isReadRequest

public boolean isReadRequest()
Description copied from class: AbstractRequest
Returns true if this request is a read request (SELECT requests for example perform a read).

Specified by:
isReadRequest in class AbstractRequest
Returns:
true
See Also:
AbstractRequest.isReadRequest()

isWriteRequest

public boolean isWriteRequest()
Description copied from class: AbstractRequest
Returns true if this request is a write request (INSERT or UPDATE for example perform writes).

Specified by:
isWriteRequest in class AbstractRequest
Returns:
false
See Also:
AbstractRequest.isWriteRequest()

isUnknownRequest

public boolean isUnknownRequest()
Description copied from class: AbstractRequest
Returns true if the resulting operation on this request is unknown (some non-standard command or stored procedure for example).

Specified by:
isUnknownRequest in class AbstractRequest
Returns:
false
See Also:
AbstractRequest.isUnknownRequest()

debug

public void debug()
Displays some debugging information about this request.

Overrides:
debug in class AbstractRequest


Copyright © 2002, 2003 - ObjectWeb Consortium - All Rights Reserved.