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.

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

Field Summary
protected  int cacheable
          Whether this request is cacheable or not.
private  boolean driverProcessed
          If set to true, the query is 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 driver do escape processing before sending to the database?
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
          Should match System.getProperty("line.separator") on the driver side.
protected  java.lang.String login
          Login used to issue this request (must be set by the VirtualDatabaseWorkerThread).
protected  int maxRows
          Maximum number of rows in the ResultSet.
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 timeout
          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.
 
Constructor Summary
AbstractRequest(java.lang.String sqlQuery, boolean escapeProcessing, int timeout, java.lang.String lineSeparator)
          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 code.
 int getCacheAbility()
          Returns the cacheable status of this request.
 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.
 boolean isAutoCommit()
          Returns true if the request should be executed in autocommit mode.
 boolean isDriverProcessed()
          Returns the driverProcessed value.
 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
abstract  boolean isReadRequest()
          Returns true if this request is a read request ( SELECT requests for example perform a read).
abstract  boolean isUnknownRequest()
          Returns true if the resulting operation on this request is unknown (some non-standard command or stored procedure for example).
abstract  boolean isWriteRequest()
          Returns true if this request is a write request ( INSERT or UPDATE for example perform writes).
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.
 void setCacheAbility(int cacheAbility)
          Set the cacheable status of this request.
 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 setLineSeparator(java.lang.String lineSeparator)
          Sets the lineSeparator value.
 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.
 java.lang.String trimCarriageReturn()
          If the query has a skeleton defined, return the skeleton wth all carriage returns replaces with spaces.
private  java.lang.String trimCarriageReturn(java.lang.String s)
          Replaces any carriage returns by a space in a given String.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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

protected int maxRows
Maximum number of rows in the ResultSet.

See Also:
Statement.setMaxRows(int)

fetchSize

private int fetchSize

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.


timeout

protected int timeout
Timeout for this request in seconds, value 0 means no timeout (should be set in constructor).


escapeProcessing

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


lineSeparator

private java.lang.String lineSeparator
Should match System.getProperty("line.separator") on the driver side. Required for parsing.


driverProcessed

private boolean driverProcessed
If set to true, the query is interpreted on the driver side, if false the various parameters are encoded and passed as is to the database native driver by the controller.

Constructor Detail

AbstractRequest

public AbstractRequest(java.lang.String sqlQuery,
                       boolean escapeProcessing,
                       int timeout,
                       java.lang.String lineSeparator)
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
Method Detail

isReadRequest

public abstract boolean isReadRequest()
Returns true if this request is a read request ( SELECT requests for example perform a read).

Returns:
true if this request is a read request

isWriteRequest

public abstract boolean isWriteRequest()
Returns true if this request is a write request ( INSERT or UPDATE for example perform writes).

Returns:
true if this requests is a write request

isUnknownRequest

public abstract boolean isUnknownRequest()
Returns true if the resulting operation on this request is unknown (some non-standard command or stored procedure for example).

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

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.

setLineSeparator

public void setLineSeparator(java.lang.String lineSeparator)
Sets the lineSeparator value.

Parameters:
lineSeparator - The lineSeparator to set.

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.

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

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

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 code.

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

trimCarriageReturn

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

Returns:
statement with CR replaces by spaces

trimCarriageReturn

private java.lang.String trimCarriageReturn(java.lang.String s)
Replaces any carriage returns by a space in a given String.

Parameters:
s - the String to transform
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.

getFetchSize

public int getFetchSize()
Returns the fetchSize value.

Returns:
Returns the fetchSize.

debug

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



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