Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

org.objectweb.cjdbc.common.sql.DeleteRequest Class Reference

Inheritance diagram for org.objectweb.cjdbc.common.sql.DeleteRequest:

Inheritance graph
[legend]
Collaboration diagram for org.objectweb.cjdbc.common.sql.DeleteRequest:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 DeleteRequest (String sqlQuery, boolean escapeProcessing, int timeout, String lineSeparator, DatabaseSchema schema, int granularity, boolean isCaseSensitive) throws SQLException
 DeleteRequest (String sqlQuery, boolean escapeProcessing, int timeout, String lineSeparator)
void parse (DatabaseSchema schema, int granularity, boolean isCaseSensitive) throws SQLException
void cloneParsing (AbstractRequest request)
ArrayList getValues ()
boolean isUnique ()
boolean isInsert ()
boolean isUpdate ()
boolean isDelete ()
boolean isCreate ()
boolean isDrop ()
void debug ()
boolean isAlter ()

Protected Attributes

ArrayList whereValues

Detailed Description

An DeleteRequest is an SQL request with the following syntax:

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

Note that DELETE from multiple tables are not supported but this is not part of the SQL standard.

Author:
Emmanuel Cecchet

Julie Marguerite

Mathieu Peltier

Sara Bouchenak

Version:
1.0

Definition at line 54 of file DeleteRequest.java.


Constructor & Destructor Documentation

org.objectweb.cjdbc.common.sql.DeleteRequest.DeleteRequest String  sqlQuery,
boolean  escapeProcessing,
int  timeout,
String  lineSeparator,
DatabaseSchema  schema,
int  granularity,
boolean  isCaseSensitive
throws SQLException
 

Creates a new DeleteRequest instance. The caller must give an SQL request, without any leading or trailing spaces and beginning with 'delete ' (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
Exceptions:
SQLException if an error occurs

Definition at line 95 of file DeleteRequest.java.

References org.objectweb.cjdbc.common.sql.DeleteRequest.parse().

00098   {
00099     this(sqlQuery, escapeProcessing, timeout, lineSeparator);
00100     parse(schema, granularity, isCaseSensitive);
00101   }

org.objectweb.cjdbc.common.sql.DeleteRequest.DeleteRequest String  sqlQuery,
boolean  escapeProcessing,
int  timeout,
String  lineSeparator
 

Creates a new DeleteRequest instance. The caller must give an SQL request, without any leading or trailing spaces and beginning with 'delete ' (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

Definition at line 118 of file DeleteRequest.java.

00120   {
00121     super(sqlQuery, escapeProcessing, timeout, lineSeparator);
00122     cacheable = RequestType.UNCACHEABLE;
00123     isParsed = false;
00124     isUnique = false;
00125   }


Member Function Documentation

void org.objectweb.cjdbc.common.sql.DeleteRequest.cloneParsing AbstractRequest  request  )  [virtual]
 

See also:
AbstractRequest.cloneParsing(AbstractRequest)

Implements org.objectweb.cjdbc.common.sql.AbstractRequest.

Definition at line 263 of file DeleteRequest.java.

References org.objectweb.cjdbc.common.sql.AbstractWriteRequest.cloneTableNameAndColumns(), and org.objectweb.cjdbc.common.sql.AbstractRequest.isParsed.

00264   {
00265     if (!request.isParsed())
00266       return;
00267     cloneTableNameAndColumns((AbstractWriteRequest) request);
00268     isParsed = true;
00269   }

void org.objectweb.cjdbc.common.sql.DeleteRequest.debug  ) 
 

Displays some debugging information about this request.

Reimplemented from org.objectweb.cjdbc.common.sql.AbstractRequest.

Definition at line 435 of file DeleteRequest.java.

00436   {
00437     super.debug();
00438     System.out.println("Is unique: " + isUnique);
00439     if (tableName != null)
00440       System.out.println("Deleted table: " + tableName);
00441     else
00442       System.out.println("No information about deleted table");
00443 
00444     if (columns != null)
00445     {
00446       System.out.println("Columns columns:");
00447       for (int i = 0; i < columns.size(); i++)
00448         System.out.println("  "
00449             + ((TableColumn) columns.get(i)).getColumnName());
00450     }
00451     else
00452       System.out.println("No information about updated columns");
00453 
00454     System.out.println();
00455   }

ArrayList org.objectweb.cjdbc.common.sql.DeleteRequest.getValues  ) 
 

Returns an ArrayList of String objects representing the values associated with the unique columns involved in this request.

Returns:
an ArrayList value

Definition at line 372 of file DeleteRequest.java.

00373   {
00374     return whereValues;
00375   }

boolean org.objectweb.cjdbc.common.sql.DeleteRequest.isAlter  )  [virtual]
 

See also:
org.objectweb.cjdbc.common.sql.AbstractWriteRequest.isAlter()

Implements org.objectweb.cjdbc.common.sql.AbstractWriteRequest.

Definition at line 460 of file DeleteRequest.java.

00461   {
00462     return false;
00463   }

boolean org.objectweb.cjdbc.common.sql.DeleteRequest.isCreate  )  [virtual]
 

Returns:
false
See also:
org.objectweb.cjdbc.common.sql.AbstractWriteRequest.isCreate()

Implements org.objectweb.cjdbc.common.sql.AbstractWriteRequest.

Definition at line 418 of file DeleteRequest.java.

00419   {
00420     return false;
00421   }

boolean org.objectweb.cjdbc.common.sql.DeleteRequest.isDelete  )  [virtual]
 

Returns:
true
See also:
org.objectweb.cjdbc.common.sql.AbstractWriteRequest.isDelete()

Implements org.objectweb.cjdbc.common.sql.AbstractWriteRequest.

Definition at line 409 of file DeleteRequest.java.

00410   {
00411     return true;
00412   }

boolean org.objectweb.cjdbc.common.sql.DeleteRequest.isDrop  )  [virtual]
 

Returns:
false
See also:
org.objectweb.cjdbc.common.sql.AbstractWriteRequest.isDrop()

Implements org.objectweb.cjdbc.common.sql.AbstractWriteRequest.

Definition at line 427 of file DeleteRequest.java.

00428   {
00429     return false;
00430   }

boolean org.objectweb.cjdbc.common.sql.DeleteRequest.isInsert  )  [virtual]
 

Returns:
false
See also:
org.objectweb.cjdbc.common.sql.AbstractWriteRequest.isInsert()

Implements org.objectweb.cjdbc.common.sql.AbstractWriteRequest.

Definition at line 391 of file DeleteRequest.java.

00392   {
00393     return false;
00394   }

boolean org.objectweb.cjdbc.common.sql.DeleteRequest.isUnique  ) 
 

Returns true if this query only deletes a single row.

Returns:
a boolean value

Definition at line 382 of file DeleteRequest.java.

00383   {
00384     return isUnique;
00385   }

boolean org.objectweb.cjdbc.common.sql.DeleteRequest.isUpdate  )  [virtual]
 

Returns:
false
See also:
org.objectweb.cjdbc.common.sql.AbstractWriteRequest.isUpdate()

Implements org.objectweb.cjdbc.common.sql.AbstractWriteRequest.

Definition at line 400 of file DeleteRequest.java.

00401   {
00402     return false;
00403   }

void org.objectweb.cjdbc.common.sql.DeleteRequest.parse DatabaseSchema  schema,
int  granularity,
boolean  isCaseSensitive
throws SQLException [virtual]
 

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.

Parameters:
schema a DatabaseSchema value
granularity parsing granularity as defined in ParsingGranularities
isCaseSensitive if parsing must be case sensitive
Exceptions:
SQLException if the parsing fails

Implements org.objectweb.cjdbc.common.sql.AbstractRequest.

Definition at line 142 of file DeleteRequest.java.

References org.objectweb.cjdbc.common.sql.DeleteRequest.whereValues.

Referenced by org.objectweb.cjdbc.common.sql.DeleteRequest.DeleteRequest().

00144   {
00145     if (granularity == ParsingGranularities.NO_PARSING)
00146     {
00147       isParsed = true;
00148       return;
00149     }
00150 
00151     // Sanity check
00152     if (schema == null)
00153       throw new SQLException(
00154           "Unable to parse request with an undefined database schema");
00155 
00156     String originalSQL = this.trimCarriageReturn();
00157     String sql = originalSQL.toLowerCase();
00158 
00159     int fromIdx = sql.indexOf("from ");
00160     if (fromIdx == -1)
00161     {
00162       // For queries like: DELETE t WHERE ... used by Oracle
00163       fromIdx = 6; // 6 = "delete".length()
00164     }
00165     else
00166     {
00167       // Syntax is usually DELETE FROM t WHERE ... but it can be
00168       // DELETE t1 FROM t1,t2,.... WHERE ...
00169       // If there is something between DELETE and FROM, tableName will use this
00170       // name but the FROM clause will have all tables.
00171       String tableBetweenDeleteAndFrom;
00172       if (isCaseSensitive)
00173         tableBetweenDeleteAndFrom = originalSQL.substring(6, fromIdx).trim();
00174       else
00175         tableBetweenDeleteAndFrom = sql.substring(6, fromIdx).trim();
00176       if (tableBetweenDeleteAndFrom.length() == 0)
00177         tableName = null;
00178       else
00179         tableName = tableBetweenDeleteAndFrom;
00180       fromIdx += 5; // 5 = "from".length()
00181     }
00182 
00183     sql = sql.substring(fromIdx).trim();
00184 
00185     // Look for the WHERE clause
00186     int whereIdx = sql.indexOf("where ");
00187 
00188     if (isCaseSensitive)
00189       sql = originalSQL.substring(originalSQL.length() - sql.length());
00190     if (tableName == null)
00191     { // It was not a DELETE t1 FROM xxx type of query
00192       if (whereIdx == -1)
00193         tableName = sql;
00194       else
00195         tableName = sql.substring(0, whereIdx).trim();
00196     }
00197 
00198     // Get the table on which DELETE occurs
00199     DatabaseTable t = schema.getTable(tableName, isCaseSensitive);
00200     if (t == null)
00201       throw new SQLException("Unknown table '" + tableName
00202           + "' in this DELETE statement: " + sqlQuery + "'");
00203 
00204     try
00205     {
00206       switch (granularity)
00207       {
00208         case ParsingGranularities.NO_PARSING :
00209           return;
00210         case ParsingGranularities.TABLE :
00211           break;
00212         case ParsingGranularities.COLUMN :
00213           from = getFromTables(tableName, schema);
00214           columns = getWhereColumns(sql.substring(whereIdx + 6).trim(), from);
00215 
00216           if (from != null)
00217           {
00218             // Convert 'from' to an ArrayList of String objects instead of
00219             // AliasedTables objects
00220             int size = from.size();
00221             ArrayList unaliased = new ArrayList(size);
00222             for (int i = 0; i < size; i++)
00223               unaliased.add(((AliasedDatabaseTable) from.get(i)).getTable()
00224                   .getName());
00225             from = unaliased;
00226           }
00227           break;
00228         case ParsingGranularities.COLUMN_UNIQUE :
00229           from = getFromTables(tableName, schema);
00230           columns = getWhereColumns(sql.substring(whereIdx + 6).trim(), from);
00231 
00232           if (from != null)
00233           {
00234             // Convert 'from' to an ArrayList of String objects instead of
00235             // AliasedTables objects
00236             int size = from.size();
00237             ArrayList unaliased = new ArrayList(size);
00238             for (int i = 0; i < size; i++)
00239               unaliased.add(((AliasedDatabaseTable) from.get(i)).getTable()
00240                   .getName());
00241             from = unaliased;
00242           }
00243           break;
00244         default :
00245           throw new SQLException("Unsupported parsing granularity: '"
00246               + granularity + "'");
00247       }
00248     }
00249     catch (SQLException e)
00250     {
00251       from = null;
00252       columns = null;
00253       whereValues = null;
00254       throw e;
00255     }
00256 
00257     isParsed = true;
00258   }


Member Data Documentation

ArrayList org.objectweb.cjdbc.common.sql.DeleteRequest.whereValues [protected]
 

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:
org.objectweb.cjdbc.controller.cache.result.CachingGranularities

Definition at line 75 of file DeleteRequest.java.

Referenced by org.objectweb.cjdbc.common.sql.DeleteRequest.parse().


The documentation for this class was generated from the following file:
Generated on Mon Apr 11 22:02:06 2005 for C-JDBC by  doxygen 1.3.9.1