org.objectweb.cjdbc.common.sql
Class DeleteRequest

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

public class DeleteRequest
extends AbstractWriteRequest
implements java.io.Serializable

An DeleteRequest is an SQL request with the following syntax:

DELETE [table1,table2,...] FROM table1,table2,table3,... WHERE search-condition
 

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  boolean isUnique
          true if this query only deletes a single row.
protected  java.util.ArrayList whereValues
          ArrayList of values String associated with the unique columns involved in this delete query.
 
Fields inherited from class org.objectweb.cjdbc.common.sql.AbstractWriteRequest
blocking, columns, pkValue, tableName
 
Fields inherited from class org.objectweb.cjdbc.common.sql.AbstractRequest
cacheable, escapeProcessing, id, isAutoCommit, isParsed, isReadOnly, login, maxRows, sqlQuery, sqlSkeleton, timeout, transactionId
 
Constructor Summary
DeleteRequest(java.lang.String sqlQuery, boolean escapeProcessing, int timeout, java.lang.String lineSeparator)
          Creates a new DeleteRequest instance.
DeleteRequest(java.lang.String sqlQuery, boolean escapeProcessing, int timeout, java.lang.String lineSeparator, DatabaseSchema schema, int granularity, boolean isCaseSensitive)
          Creates a new DeleteRequest instance.
 
Method Summary
 void cloneParsing(AbstractRequest request)
          Clones the parsing of a request.
 void debug()
          Displays some debugging information about this request.
private  java.util.ArrayList getFromTables(java.lang.String fromClause, DatabaseSchema dbs)
          Extracts the tables from the given FROM clause and retrieves their alias if any.
 java.util.ArrayList getValues()
          Returns an ArrayList of String objects representing the values associated with the unique columns involved in this request.
private  java.util.ArrayList getWhereColumns(java.lang.String whereClause, java.util.ArrayList aliasedFrom)
          Gets all the columns involved in the given WHERE clause.
 boolean isAlter()
          Returns true if this request in a ALTER statement.
 boolean isCreate()
          Returns true if this request in a CREATE statement.
 boolean isDelete()
          Returns true if this request in a DELETE statement.
 boolean isDrop()
          Returns true if this request in a DROP statement.
 boolean isInsert()
          Returns true if this request in an INSERT statement.
 boolean isUnique()
          Returns true if this query only deletes a single row.
 boolean isUpdate()
          Returns true if this request in an UPDATE statement.
 void parse(DatabaseSchema schema, int granularity, boolean isCaseSensitive)
          Parses the SQL request and extracts the selected columns and tables given the DatabaseSchema of the database targeted by this request.
 
Methods inherited from class org.objectweb.cjdbc.common.sql.AbstractWriteRequest
cloneTableNameAndColumns, getColumns, getPk, getTableName, isReadRequest, isUnknownRequest, isWriteRequest, mightBlock, setBlocking
 
Methods inherited from class org.objectweb.cjdbc.common.sql.AbstractRequest
equals, getCacheAbility, getEscapeProcessing, getFetchSize, getId, getLineSeparator, getLogin, getMaxRows, getSQL, getSQLShortForm, getSqlSkeleton, getTimeout, getTransactionId, isAutoCommit, isDriverProcessed, isParsed, isReadOnly, setCacheAbility, setDriverProcessed, setFetchSize, setId, setIsAutoCommit, setIsReadOnly, setLineSeparator, 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

isUnique

private transient boolean isUnique
true if this query only deletes a single row.


from

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


whereValues

protected java.util.ArrayList whereValues
ArrayList of values String associated with the unique columns involved in this delete query.

The values instance variable is only used when a COLUMN_UNIQUE_DELETE granularity is applied. Here, the DELETE request is UNIQUE: all columns of the WHERE clause are UNIQUE and used in the left part of an equality. When such a granularity is used, the columns instance variable contains only UNIQUE columns.

See Also:
CachingGranularities
Constructor Detail

DeleteRequest

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

If the syntax is incorrect an exception is thrown.

Parameters:
sqlQuery - the SQL request
escapeProcessing - should the driver to escape processing before sending to the database ?
timeout - an int value
lineSeparator - the line separator used in the query
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

DeleteRequest

public DeleteRequest(java.lang.String sqlQuery,
                     boolean escapeProcessing,
                     int timeout,
                     java.lang.String lineSeparator)
Creates a new DeleteRequest instance. The caller must give an SQL request, without any leading or trailing spaces and beginning with 'create table ' (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 request
escapeProcessing - should the driver to escape processing before sending to the database ?
timeout - an int value
lineSeparator - the line separator used in the query
See Also:
parse(org.objectweb.cjdbc.common.sql.schema.DatabaseSchema, int, boolean)
Method Detail

parse

public void parse(DatabaseSchema schema,
                  int granularity,
                  boolean isCaseSensitive)
           throws java.sql.SQLException
Parses the SQL request and extracts 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.

Specified by:
parse in class AbstractRequest
Parameters:
schema - a DatabaseSchema value
granularity - parsing granularity as defined in ParsingGranularities
isCaseSensitive - if parsing must be case sensitive
Throws:
java.sql.SQLException - if the parsing fails

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 dbs)
                                   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)
dbs - the DatabaseSchema this request refers to
Returns:
an ArrayList of AliasedDatabaseTable objects
Throws:
an - SQLException if an error occurs
java.sql.SQLException

getWhereColumns

private java.util.ArrayList getWhereColumns(java.lang.String whereClause,
                                            java.util.ArrayList aliasedFrom)
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
Returns:
an ArrayList of TableColumn

getValues

public java.util.ArrayList getValues()
Returns an ArrayList of String objects representing the values associated with the unique columns involved in this request.

Returns:
an ArrayList value

isUnique

public boolean isUnique()
Returns true if this query only deletes a single row.

Returns:
a boolean value

isInsert

public boolean isInsert()
Description copied from class: AbstractWriteRequest
Returns true if this request in an INSERT statement.

Specified by:
isInsert in class AbstractWriteRequest
Returns:
false
See Also:
AbstractWriteRequest.isInsert()

isUpdate

public boolean isUpdate()
Description copied from class: AbstractWriteRequest
Returns true if this request in an UPDATE statement.

Specified by:
isUpdate in class AbstractWriteRequest
Returns:
false
See Also:
AbstractWriteRequest.isUpdate()

isDelete

public boolean isDelete()
Description copied from class: AbstractWriteRequest
Returns true if this request in a DELETE statement.

Specified by:
isDelete in class AbstractWriteRequest
Returns:
true
See Also:
AbstractWriteRequest.isDelete()

isCreate

public boolean isCreate()
Description copied from class: AbstractWriteRequest
Returns true if this request in a CREATE statement.

Specified by:
isCreate in class AbstractWriteRequest
Returns:
false
See Also:
AbstractWriteRequest.isCreate()

isDrop

public boolean isDrop()
Description copied from class: AbstractWriteRequest
Returns true if this request in a DROP statement.

Specified by:
isDrop in class AbstractWriteRequest
Returns:
false
See Also:
AbstractWriteRequest.isDrop()

debug

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

Overrides:
debug in class AbstractRequest

isAlter

public boolean isAlter()
Description copied from class: AbstractWriteRequest
Returns true if this request in a ALTER statement.

Specified by:
isAlter in class AbstractWriteRequest
Returns:
a boolean value
See Also:
AbstractWriteRequest.isAlter()


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