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

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

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

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

Collaboration graph
[legend]
List of all members.

Public Member Functions

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

Detailed Description

An InsertRequest is an SQL request of the following syntax:

  INSERT INTO table-name [(column-name[,column-name]*)] {VALUES (constant|null[,constant|null]*)}|{SELECT query}
 
VALUES are ignored. *
Author:
Emmanuel Cecchet
Version:
1.0

Definition at line 48 of file InsertRequest.java.


Constructor & Destructor Documentation

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

Creates a new InsertRequest instance. The caller must give an SQL request, without any leading or trailing spaces and beginning with 'insert into ' (it will not be checked).

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
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 68 of file InsertRequest.java.

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

00071   {
00072     this(sqlQuery, escapeProcessing, timeout, lineSeparator);
00073     parse(schema, granularity, isCaseSensitive);
00074   }

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

Creates a new DropRequest 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

Definition at line 91 of file InsertRequest.java.

00093   {
00094     super(sqlQuery, escapeProcessing, timeout, lineSeparator);
00095     cacheable = RequestType.UNCACHEABLE;
00096     isParsed = false;
00097   }


Member Function Documentation

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

See also:
AbstractRequest.cloneParsing(AbstractRequest)

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

Definition at line 224 of file InsertRequest.java.

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

00225   {
00226     if (!request.isParsed())
00227       return;
00228     cloneTableNameAndColumns((AbstractWriteRequest) request);
00229     isParsed = true;
00230   }

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

Displays some debugging information about this request.

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

Definition at line 280 of file InsertRequest.java.

00281   {
00282     super.debug();
00283     if (tableName != null)
00284       System.out.println("Inserted table: " + tableName);
00285     else
00286       System.out.println("No information about inserted table");
00287 
00288     if (columns != null)
00289     {
00290       System.out.println("Inserted columns:");
00291       for (int i = 0; i < columns.size(); i++)
00292         System.out.println("  "
00293             + ((TableColumn) columns.get(i)).getColumnName());
00294     }
00295     else
00296       System.out.println("No information about inserted columns");
00297 
00298     System.out.println("");
00299   }

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

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

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

Definition at line 304 of file InsertRequest.java.

00305   {
00306     return false;
00307   }

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

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

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

Definition at line 263 of file InsertRequest.java.

00264   {
00265     return false;
00266   }

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

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

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

Definition at line 254 of file InsertRequest.java.

00255   {
00256     return false;
00257   }

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

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

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

Definition at line 272 of file InsertRequest.java.

00273   {
00274     return false;
00275   }

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

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

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

Definition at line 236 of file InsertRequest.java.

00237   {
00238     return true;
00239   }

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

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

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

Definition at line 245 of file InsertRequest.java.

00246   {
00247     return false;
00248   }

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

Parse the query to know which table is affected. Also checks for the columns if the parsing granularity requires it.

See also:
org.objectweb.cjdbc.common.sql.AbstractRequest.parse(org.objectweb.cjdbc.common.sql.schema.DatabaseSchema, int, boolean)

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

Definition at line 106 of file InsertRequest.java.

References org.objectweb.cjdbc.common.sql.schema.DatabaseTable.getColumn(), org.objectweb.cjdbc.common.sql.schema.DatabaseTable.getColumns(), org.objectweb.cjdbc.common.sql.schema.DatabaseColumn.getName(), and org.objectweb.cjdbc.common.sql.schema.DatabaseTable.getName().

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

00108   {
00109     if (granularity == ParsingGranularities.NO_PARSING)
00110     {
00111       isParsed = true;
00112       return;
00113     }
00114 
00115     // Sanity check
00116     if (schema == null)
00117       throw new SQLException(
00118           "Unable to parse request with an undefined database schema");
00119 
00120     String originalSQL = this.trimCarriageReturn();
00121     String sql = originalSQL.toLowerCase();
00122 
00123     // Strip 'insert into '
00124     sql = sql.substring(7).trim().substring(5).trim();
00125 
00126     // Look for the VALUES or SELECT clause
00127     int endIdx = sql.indexOf(" values ");
00128     if (endIdx == -1)
00129     {
00130       endIdx = sql.indexOf(" values(");
00131       if (endIdx == -1)
00132       {
00133         endIdx = sql.indexOf("select ");
00134         if (endIdx == -1)
00135           throw new SQLException(
00136               "Unable to find the VALUES or SELECT keyword in this INSERT statement: '"
00137                   + sqlQuery + "'");
00138       }
00139     }
00140 
00141     if (isCaseSensitive)
00142     {
00143       int shift = originalSQL.length() - sql.length();
00144       sql = originalSQL.substring(shift, shift + endIdx).trim();
00145     }
00146     else
00147       sql = sql.substring(0, endIdx).trim();
00148 
00149     int openParenthesisIdx = sql.indexOf("(");
00150 
00151     // Get the table on which INSERT occurs
00152     String insertTable;
00153     if (openParenthesisIdx == -1)
00154       // Query like INSERT INTO table VALUES(...)
00155       insertTable = sql;
00156     else
00157       // Query of the form INSERT INTO table(column1, ...) VALUES(...)
00158       insertTable = sql.substring(0, openParenthesisIdx).trim();
00159 
00160     DatabaseTable t = schema.getTable(insertTable, isCaseSensitive);
00161     if (t == null)
00162       throw new SQLException("Unknown table '" + insertTable
00163           + "' in this INSERT statement: '" + sqlQuery + "'");
00164     else
00165       tableName = t.getName();
00166 
00167     if ((granularity == ParsingGranularities.COLUMN)
00168         || (granularity == ParsingGranularities.COLUMN_UNIQUE))
00169     {
00170       if (openParenthesisIdx != -1)
00171       {
00172         // Fetch the affected columns
00173         int closingParenthesisIdx = sql.indexOf(")");
00174         if ((closingParenthesisIdx == -1) || (closingParenthesisIdx > endIdx))
00175         {
00176           tableName = null;
00177           columns = null;
00178           throw new SQLException(
00179               "Syntax error in columns definition for this INSERT statement: '"
00180                   + sqlQuery + "'");
00181         }
00182 
00183         // Column names are separated by comas
00184         StringTokenizer columnTokens = new StringTokenizer(sql.substring(
00185             openParenthesisIdx + 1, closingParenthesisIdx), ",");
00186         columns = new ArrayList();
00187         DatabaseColumn col = null;
00188         while (columnTokens.hasMoreTokens())
00189         {
00190           String token = columnTokens.nextToken().trim();
00191           if ((col = t.getColumn(token)) == null)
00192           {
00193             tableName = null;
00194             columns = null;
00195             throw new SQLException("Unknown column name '" + token
00196                 + "' in this INSERT statement: '" + sqlQuery + "'");
00197           }
00198           else
00199           {
00200             columns.add(new TableColumn(tableName, col.getName()));
00201           }
00202         }
00203       }
00204       else
00205       {
00206         // All columns are affected
00207         columns = new ArrayList();
00208         ArrayList cols = t.getColumns();
00209         int size = cols.size();
00210         for (int j = 0; j < size; j++)
00211         {
00212           columns.add(new TableColumn(tableName, ((DatabaseColumn) cols.get(j))
00213               .getName()));
00214         }
00215       }
00216     }
00217 
00218     isParsed = true;
00219   }


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