org.objectweb.cjdbc.common.sql
Class AbstractRequest

java.lang.Object
  extended byorg.objectweb.cjdbc.common.sql.AbstractRequest
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
AbstractWriteRequest, SelectRequest, StoredProcedure, UnknownRequest

public abstract class AbstractRequest
extends java.lang.Object
implements java.io.Serializable

An AbstractRequest defines the skeleton of an SQL request. Requests have to be serializable (at least) for inter-controller communications.

Version:
1.0
Author:
Emmanuel Cecchet , Julie Marguerite , Mathieu Peltier , Marc Herbert
See Also:
Serialized Form

Field Summary
protected  int cacheable
          Whether this request is cacheable or not.
(package private)  java.lang.String cursorName
           
private  boolean driverProcessed
          If set to true, this query is/was interpreted on the driver side, if false the various parameters are encoded and passed as is to the database native driver by the controller.
protected  boolean escapeProcessing
          Should the backend driver do escape processing before sending to the database?
(package private)  int fetchSize
           
protected  long id
          Request unique id (set by the controller).
protected  boolean isAutoCommit
          Whether this request has been sent in autocommit mode or not.
protected  boolean isParsed
          Whether the SQL content has been parsed or not.
protected  boolean isReadOnly
          True if the connection has been set to read-only
private  java.lang.String lineSeparator
          Set and sent by the driver to the controller.
protected  java.lang.String login
          Login used to issue this request (must be set by the VirtualDatabaseWorkerThread).
(package private)  int maxRows
           
(package private)  int requestType
           
protected  java.lang.String sqlQuery
          SQL query (should be set in constructor).
protected  java.lang.String sqlSkeleton
          SQL query skeleton as it appears in PreparedStatements.
protected  int timeoutInSeconds
          Timeout for this request in seconds, value 0 means no timeout (should be set in constructor).
protected  long transactionId
          Transaction identifier if this request belongs to a transaction.
protected  int transactionIsolation
          Transaction isolation level to use when executing the query inside a transaction.
 
Constructor Summary
AbstractRequest(CJDBCInputStream in, int requestType)
          Creates a new AbstractRequest object, deserializing it from an input stream.
AbstractRequest(java.lang.String sqlQuery, boolean escapeProcessing, int timeout, java.lang.String lineSeparator, int requestType)
          Default constructor Creates a new AbstractRequest object
 
Method Summary
abstract  void cloneParsing(AbstractRequest request)
          Clones the parsing of a request.
 void debug()
          Displays some debugging information about this request.
 boolean equals(java.lang.Object other)
          Two requests are equal if they have the same SQL statement, transaction id and login.
 int getCacheAbility()
          Returns the cacheable status of this request.
 java.lang.String getCursorName()
          Returns the cursorName value.
 boolean getEscapeProcessing()
          Returns true if the driver should escape processing before sending to the database?
 int getFetchSize()
          Returns the fetchSize value.
 long getId()
          Returns the unique id of this request.
 java.lang.String getLineSeparator()
          Returns the lineSeparator value.
 java.lang.String getLogin()
          Returns the login used to issue this request.
 int getMaxRows()
          Get the maximum number of rows the ResultSet can contain.
 java.lang.String getSQL()
          Gets the SQL code of this request.
 java.lang.String getSQLShortForm(int nbOfCharacters)
          Get a short form of this request if the SQL statement exceeds nbOfCharacters.
 java.lang.String getSqlSkeleton()
           
 int getTimeout()
          Gets the timeout for this request in seconds.
 long getTransactionId()
          Gets the identifier of the transaction if this request belongs to a transaction, or -1 if this request does not belong to a transaction.
 int getTransactionIsolation()
          Returns the transaction isolation level.
 boolean isAlter()
          Returns true if this request in a ALTER statement.
 boolean isAutoCommit()
          Returns true if the request should be executed in autocommit mode.
 boolean isCreate()
          Returns true if this request in a CREATE statement.
 boolean isDDL()
          Returns true if this request is a DDL (Data Definition Language) statement such as CREATE, ALTER or DROP.
 boolean isDelete()
          Returns true if this request in a DELETE statement.
 boolean isDML()
          Returns true if this request is a DML (Data Manipulation Language) statement such SELECT, INSERT, UPDATE or DELETE (see http://www.orafaq.com/faq/Server_Utilities/SQL/faq53.htm) Note that stored procedures are both considered as DDL and DML as they can include both.
 boolean isDriverProcessed()
          Returns the driverProcessed value.
 boolean isDrop()
          Returns true if this request in a DROP statement.
 boolean isInsert()
          Returns true if this request in an INSERT statement.
 boolean isParsed()
          Returns true if the request SQL content has been already parsed.
 boolean isReadOnly()
          Returns true if the connection is set to read-only
 boolean isSelect()
          Returns true if this request in a SELECT statement.
 boolean isUpdate()
          Returns true if this request in an UPDATE statement.
abstract  boolean needsMacroProcessing()
          Returns true if this request requires macro (RAND(), NOW(), ...) processing.
abstract  void parse(DatabaseSchema schema, int granularity, boolean isCaseSensitive)
          Parses the SQL request and extract the selected columns and tables given the DatabaseSchema of the database targeted by this request.
(package private)  void receiveResultSetParams(CJDBCInputStream in)
          Also fetch ResultSet parameters from the stream.
private  java.lang.String replaceStringWithSpace(java.lang.String s, java.lang.String toReplace)
          Replaces any given String by a space in a given String.
abstract  boolean returnsResultSet()
          Does this request returns a ResultSet?
(package private)  void sendResultSetParams(CJDBCOutputStream out)
          Also serialize ResultSet parameters to the stream.
 void sendToStream(CJDBCOutputStream out, boolean controllerWantsSqlSkeleton)
          Serialize the request on the output stream by sending only the needed parameters to reconstruct it on the controller.
 void setCacheAbility(int cacheAbility)
          Set the cacheable status of this request.
 void setCursorName(java.lang.String cursorName)
          Sets the cursorName value.
 void setDriverProcessed(boolean driverProcessed)
          Sets the driverProcessed value.
 void setFetchSize(int fetchSize)
          Sets the fetchSize value.
 void setId(long id)
          Sets the unique id of this request.
 void setIsAutoCommit(boolean isAutoCommit)
          Sets the autocommit mode for this request.
 void setIsReadOnly(boolean isReadOnly)
          Sets the read-only mode for this request.
 void setLogin(java.lang.String login)
          Sets the login to use to issue this request.
 void setMaxRows(int rows)
          Set the maximum number of rows in the ResultSet.
 void setSQL(java.lang.String sql)
          Set the SQL code of this request.
 void setSqlSkeleton(java.lang.String skel)
           
 void setTimeout(int timeout)
          Sets the new timeout in seconds for this request.
 void setTransactionId(long id)
          Sets the transaction identifier this request belongs to.
 void setTransactionIsolation(int isolationLevel)
          Sets the transaction isolation level that must be used to execute this request
 java.lang.String trimCarriageReturnAndTabs()
          If the query has a skeleton defined, return the skeleton with all carriage returns and tabs replaced with spaces.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

requestType

int requestType
See Also:
RequestType

id

protected transient long id
Request unique id (set by the controller).


sqlQuery

protected java.lang.String sqlQuery
SQL query (should be set in constructor).


sqlSkeleton

protected java.lang.String sqlSkeleton
SQL query skeleton as it appears in PreparedStatements.


login

protected java.lang.String login
Login used to issue this request (must be set by the VirtualDatabaseWorkerThread).


cacheable

protected int cacheable
Whether this request is cacheable or not.


isParsed

protected boolean isParsed
Whether the SQL content has been parsed or not.


maxRows

int maxRows

fetchSize

int fetchSize

cursorName

java.lang.String cursorName

isReadOnly

protected boolean isReadOnly
True if the connection has been set to read-only


isAutoCommit

protected boolean isAutoCommit
Whether this request has been sent in autocommit mode or not.


transactionId

protected long transactionId
Transaction identifier if this request belongs to a transaction. The value is set by the VirtualDatabaseWorkerThread.


transactionIsolation

protected int transactionIsolation
Transaction isolation level to use when executing the query inside a transaction. The value is set by the VirtualDatabaseWorkerThread.


timeoutInSeconds

protected int timeoutInSeconds
Timeout for this request in seconds, value 0 means no timeout (should be set in constructor). This timeout is in seconds, reflecting the jdbc-spec, and is passed as-is to the backends jdbc-driver. Internally converted to ms via getTimeoutMs().


escapeProcessing

protected boolean escapeProcessing
Should the backend driver do escape processing before sending to the database? Simply forwarded to backend driver. No setter for this member, should be set in constructor.

See Also:
Statement.setEscapeProcessing(boolean)

lineSeparator

private java.lang.String lineSeparator
Set and sent by the driver to the controller. Required for parsing the request.


driverProcessed

private boolean driverProcessed
If set to true, this query is/was interpreted on the driver side, if false the various parameters are encoded and passed as is to the database native driver by the controller. Look for "proxy mode" in the documentation.

Constructor Detail

AbstractRequest

public AbstractRequest(java.lang.String sqlQuery,
                       boolean escapeProcessing,
                       int timeout,
                       java.lang.String lineSeparator,
                       int requestType)
Default constructor Creates a new AbstractRequest object

Parameters:
sqlQuery - the SQL query
escapeProcessing - should the driver to escape processing before sending to the database ?
timeout - an int value
lineSeparator - the line separator used in the query
requestType - the request type as defined in RequestType class
See Also:
RequestType

AbstractRequest

public AbstractRequest(CJDBCInputStream in,
                       int requestType)
                throws java.io.IOException
Creates a new AbstractRequest object, deserializing it from an input stream. Has to mirror the serialization method below.

Parameters:
in - the input stream to read from
requestType - the request type as defined in RequestType class
Throws:
java.io.IOException - if a network error occurs
See Also:
RequestType
Method Detail

sendToStream

public void sendToStream(CJDBCOutputStream out,
                         boolean controllerWantsSqlSkeleton)
                  throws java.io.IOException
Serialize the request on the output stream by sending only the needed parameters to reconstruct it on the controller. Has to mirror the deserialization method above.

Parameters:
out - destination CJDBCOutputStream
controllerWantsSqlSkeleton - true if controller wants SQL templates
Throws:
java.io.IOException - if fails

receiveResultSetParams

void receiveResultSetParams(CJDBCInputStream in)
                      throws java.io.IOException
Also fetch ResultSet parameters from the stream. Optionally used by deserializers of those derived requests that expect a ResultSet.

Parameters:
in - input stream
Throws:
java.io.IOException - stream error

sendResultSetParams

void sendResultSetParams(CJDBCOutputStream out)
                   throws java.io.IOException
Also serialize ResultSet parameters to the stream. Optionally used by serializers of those derived requests that expect a ResultSet.

Parameters:
out - output stream
Throws:
java.io.IOException - stream error

needsMacroProcessing

public abstract boolean needsMacroProcessing()
Returns true if this request requires macro (RAND(), NOW(), ...) processing.

Returns:
true if macro processing is required
See Also:
AbstractLoadBalancer.handleMacros(AbstractRequest)

returnsResultSet

public abstract boolean returnsResultSet()
Does this request returns a ResultSet?

Returns:
true is this request will return a ResultSet

isAlter

public final boolean isAlter()
Returns true if this request in a ALTER statement.

Returns:
a boolean value

isCreate

public final boolean isCreate()
Returns true if this request in a CREATE statement.

Returns:
a boolean value

isDelete

public final boolean isDelete()
Returns true if this request in a DELETE statement.

Returns:
a boolean value

isDDL

public final boolean isDDL()
Returns true if this request is a DDL (Data Definition Language) statement such as CREATE, ALTER or DROP. Not supported yet are: TRUNCATE, COMMENT, GRANT and REVOKE (see http://www.orafaq.com/faq/Server_Utilities/SQL/faq53.htm)

Note that stored procedures are both considered as DDL and DML as they can include both.

Returns:
true if this request is a DDL

isDML

public final boolean isDML()
Returns true if this request is a DML (Data Manipulation Language) statement such SELECT, INSERT, UPDATE or DELETE (see http://www.orafaq.com/faq/Server_Utilities/SQL/faq53.htm)

Note that stored procedures are both considered as DDL and DML as they can include both.

Returns:
true if this request is a DDL

isDrop

public final boolean isDrop()
Returns true if this request in a DROP statement.

Returns:
a boolean value

isInsert

public final boolean isInsert()
Returns true if this request in an INSERT statement.

Returns:
a boolean value

isParsed

public boolean isParsed()
Returns true if the request SQL content has been already parsed.

Returns:
a boolean value

isReadOnly

public boolean isReadOnly()
Returns true if the connection is set to read-only

Returns:
a boolean value

isSelect

public final boolean isSelect()
Returns true if this request in a SELECT statement.

Returns:
a boolean value

isUpdate

public final boolean isUpdate()
Returns true if this request in an UPDATE statement.

Returns:
a boolean value

setIsReadOnly

public void setIsReadOnly(boolean isReadOnly)
Sets the read-only mode for this request.

Parameters:
isReadOnly - true if connection is read-only

getCacheAbility

public int getCacheAbility()
Returns the cacheable status of this request. It can be: RequestType.CACHEABLE, RequestType.UNCACHEABLEor RequestType.UNIQUE_CACHEABLE

Returns:
a int value

setCacheAbility

public void setCacheAbility(int cacheAbility)
Set the cacheable status of this request. It can be: RequestType.CACHEABLE, RequestType.UNCACHEABLEor RequestType.UNIQUE_CACHEABLE

Parameters:
cacheAbility - a int value

getEscapeProcessing

public boolean getEscapeProcessing()
Returns true if the driver should escape processing before sending to the database?

Returns:
a boolean value

getId

public long getId()
Returns the unique id of this request.

Returns:
the request id

setId

public void setId(long id)
Sets the unique id of this request.

Parameters:
id - the id to set

isAutoCommit

public boolean isAutoCommit()
Returns true if the request should be executed in autocommit mode.

Returns:
a boolean value

setIsAutoCommit

public void setIsAutoCommit(boolean isAutoCommit)
Sets the autocommit mode for this request.

Parameters:
isAutoCommit - true if autocommit should be used

getLogin

public java.lang.String getLogin()
Returns the login used to issue this request.

Returns:
a String value

getLineSeparator

public java.lang.String getLineSeparator()
Returns the lineSeparator value.

Returns:
Returns the lineSeparator.

setLogin

public void setLogin(java.lang.String login)
Sets the login to use to issue this request.

Parameters:
login - a String value

getSQL

public java.lang.String getSQL()
Gets the SQL code of this request.

Returns:
the SQL query

getSQLShortForm

public java.lang.String getSQLShortForm(int nbOfCharacters)
Get a short form of this request if the SQL statement exceeds nbOfCharacters.

Parameters:
nbOfCharacters - number of characters to include in the short form.
Returns:
the nbOfCharacters first characters of the SQL statement

getMaxRows

public int getMaxRows()
Get the maximum number of rows the ResultSet can contain.

Returns:
maximum number of rows
See Also:
Statement.getMaxRows()

setMaxRows

public void setMaxRows(int rows)
Set the maximum number of rows in the ResultSet. Used only by Statement.

Parameters:
rows - maximum number of rows
See Also:
Statement.setMaxRows(int)

setSQL

public void setSQL(java.lang.String sql)
Set the SQL code of this request. Warning! The request parsing validity is not checked. The caller has to recall parse(DatabaseSchema, int, boolean)if needed.

Parameters:
sql - SQL statement
See Also:
AbstractLoadBalancer.handleMacros(AbstractRequest)

getTimeout

public int getTimeout()
Gets the timeout for this request in seconds.

Returns:
timeout in seconds (0 means no timeout)

setTimeout

public void setTimeout(int timeout)
Sets the new timeout in seconds for this request.

Parameters:
timeout - an int value
See Also:
org.objectweb.cjdbc.controller.scheduler

getTransactionId

public long getTransactionId()
Gets the identifier of the transaction if this request belongs to a transaction, or -1 if this request does not belong to a transaction.

Returns:
transaction identifier or -1

setTransactionId

public void setTransactionId(long id)
Sets the transaction identifier this request belongs to.

Parameters:
id - transaction id

equals

public boolean equals(java.lang.Object other)
Two requests are equal if they have the same SQL statement, transaction id and login.

Parameters:
other - an object
Returns:
a boolean value

parse

public abstract void parse(DatabaseSchema schema,
                           int granularity,
                           boolean isCaseSensitive)
                    throws java.sql.SQLException
Parses the SQL request and extract the selected columns and tables given the DatabaseSchema of the database targeted by this request.

An exception is thrown when the parsing fails. Warning, this method does not check the validity of the request. In particular, invalid request could be parsed without throwing an exception. However, valid SQL request should never throw an exception.

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

cloneParsing

public abstract void cloneParsing(AbstractRequest request)
Clones the parsing of a request.

Parameters:
request - the parsed request to clone

trimCarriageReturnAndTabs

public java.lang.String trimCarriageReturnAndTabs()
If the query has a skeleton defined, return the skeleton with all carriage returns and tabs replaced with spaces. If no SQL skeleton is defined, we perform the same processing on the instanciated SQL statement.

Note that if no modification has to be done, the original string is returned else a new string is constructed with the replaced elements.

Returns:
statement with CR replaced by spaces

replaceStringWithSpace

private java.lang.String replaceStringWithSpace(java.lang.String s,
                                                java.lang.String toReplace)
Replaces any given String by a space in a given String.

Parameters:
s - the String to transform
toReplace - the String to replace with spaces
Returns:
the transformed String

getSqlSkeleton

public java.lang.String getSqlSkeleton()
Returns:
the SQL query skeleton given in a PreparedStatement.

setSqlSkeleton

public void setSqlSkeleton(java.lang.String skel)
Parameters:
skel - set the SQL query skeleton given in a PreparedStatement.

isDriverProcessed

public boolean isDriverProcessed()
Returns the driverProcessed value.

Returns:
Returns the driverProcessed.

setDriverProcessed

public void setDriverProcessed(boolean driverProcessed)
Sets the driverProcessed value.

Parameters:
driverProcessed - The driverProcessed to set.

setFetchSize

public void setFetchSize(int fetchSize)
Sets the fetchSize value.

Parameters:
fetchSize - The fetchSize to set.
See Also:
Statement

getFetchSize

public int getFetchSize()
Returns the fetchSize value.

Returns:
Returns the fetchSize.

getTransactionIsolation

public int getTransactionIsolation()
Returns the transaction isolation level.

Returns:
Returns the transaction isolation.

setTransactionIsolation

public void setTransactionIsolation(int isolationLevel)
Sets the transaction isolation level that must be used to execute this request

Parameters:
isolationLevel - the transaction isolation level

getCursorName

public java.lang.String getCursorName()
Returns the cursorName value.

Returns:
Returns the cursorName.

setCursorName

public void setCursorName(java.lang.String cursorName)
Sets the cursorName value.

Parameters:
cursorName - The cursorName to set.

debug

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



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