00001 /** 00002 * C-JDBC: Clustered JDBC. 00003 * Copyright (C) 2002-2004 French National Institute For Research In Computer 00004 * Science And Control (INRIA). 00005 * Contact: c-jdbc@objectweb.org 00006 * 00007 * This library is free software; you can redistribute it and/or modify it 00008 * under the terms of the GNU Lesser General Public License as published by the 00009 * Free Software Foundation; either version 2.1 of the License, or any later 00010 * version. 00011 * 00012 * This library is distributed in the hope that it will be useful, but WITHOUT 00013 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00014 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 00015 * for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public License 00018 * along with this library; if not, write to the Free Software Foundation, 00019 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 00020 * 00021 * Initial developer(s): Julie Marguerite. 00022 * Contributor(s): Mathieu Peltier. 00023 */ 00024 00025 package org.objectweb.cjdbc.common.sql; 00026 00027 import java.io.Serializable; 00028 import java.sql.SQLException; 00029 00030 import org.objectweb.cjdbc.common.sql.schema.DatabaseSchema; 00031 import org.objectweb.cjdbc.common.sql.schema.DatabaseTable; 00032 00033 /** 00034 * An <code>DropRequest</code> is an SQL request with the following syntax: 00035 * 00036 * <pre> 00037 * DROP TABLE table-name 00038 * </pre> 00039 * 00040 * @author <a href="mailto:Julie.Marguerite@inria.fr">Julie Marguerite </a> 00041 * @author <a href="mailto:Mathieu.Peltier@inrialpes.fr">Mathieu Peltier </a> 00042 * @version 1.0 00043 */ 00044 public class DropRequest extends AbstractWriteRequest implements Serializable 00045 { 00046 00047 /** 00048 * Creates a new <code>DropRequest</code> instance. The caller must give an 00049 * SQL request, without any leading or trailing spaces and beginning with 00050 * 'drop table ' (it will not be checked). 00051 * <p> 00052 * If the syntax is incorrect an exception is thrown. 00053 * 00054 * @param sqlQuery a <code>String</code> value 00055 * @param escapeProcessing should the driver to escape processing before 00056 * sending to the database ? 00057 * @param timeout an <code>int</code> value 00058 * @param lineSeparator the line separator used in the query 00059 * @param schema a <code>DatabaseSchema</code> value 00060 * @param granularity parsing granularity as defined in 00061 * <code>ParsingGranularities</code> 00062 * @param isCaseSensitive true if parsing is case sensitive 00063 * @exception SQLException if an error occurs 00064 */ 00065 public DropRequest(String sqlQuery, boolean escapeProcessing, int timeout, 00066 String lineSeparator, DatabaseSchema schema, int granularity, 00067 boolean isCaseSensitive) throws SQLException 00068 { 00069 this(sqlQuery, escapeProcessing, timeout, lineSeparator); 00070 parse(schema, granularity, isCaseSensitive); 00071 } 00072 00073 /** 00074 * Creates a new <code>DropRequest</code> instance. The caller must give an 00075 * SQL request, without any leading or trailing spaces and beginning with 00076 * 'create table ' (it will not be checked). 00077 * <p> 00078 * The request is not parsed but it can be done later by a call to 00079 * {@link #parse(DatabaseSchema, int, boolean)}. 00080 * 00081 * @param sqlQuery the SQL request 00082 * @param escapeProcessing should the driver to escape processing before 00083 * sending to the database ? 00084 * @param timeout an <code>int</code> value 00085 * @param lineSeparator the line separator used in the query 00086 * @see #parse 00087 */ 00088 public DropRequest(String sqlQuery, boolean escapeProcessing, int timeout, 00089 String lineSeparator) 00090 { 00091 super(sqlQuery, escapeProcessing, timeout, lineSeparator); 00092 cacheable = RequestType.UNCACHEABLE; 00093 isParsed = false; 00094 } 00095 00096 /** 00097 * @see org.objectweb.cjdbc.common.sql.AbstractRequest#parse(org.objectweb.cjdbc.common.sql.schema.DatabaseSchema, 00098 * int, boolean) 00099 */ 00100 public void parse(DatabaseSchema schema, int granularity, 00101 boolean isCaseSensitive) throws SQLException 00102 { 00103 if (granularity == ParsingGranularities.NO_PARSING) 00104 { 00105 isParsed = true; 00106 return; 00107 } 00108 00109 String originalSQL = this.trimCarriageReturn(); 00110 String dropTable = originalSQL.toLowerCase(); 00111 00112 // Strip 'drop (temporary) table ' 00113 int tableIdx = dropTable.indexOf("table"); 00114 if (isCaseSensitive) 00115 dropTable = originalSQL.substring(tableIdx + 5).trim(); 00116 else 00117 dropTable = dropTable.substring(tableIdx + 5).trim(); 00118 00119 if (schema == null) 00120 tableName = dropTable; 00121 else 00122 { 00123 // Get the table on which DROP occurs 00124 DatabaseTable t = schema.getTable(dropTable, isCaseSensitive); 00125 if (t == null) 00126 throw new SQLException("Unknown table '" + dropTable 00127 + "' in this DROP statement '" + sqlQuery + "'"); 00128 else 00129 tableName = t.getName(); 00130 } 00131 isParsed = true; 00132 } 00133 00134 /** 00135 * @see AbstractRequest#cloneParsing(AbstractRequest) 00136 */ 00137 public void cloneParsing(AbstractRequest request) 00138 { 00139 if (!request.isParsed()) 00140 return; 00141 cloneTableNameAndColumns((AbstractWriteRequest) request); 00142 isParsed = true; 00143 } 00144 00145 /** 00146 * @return <code>false</code> 00147 * @see org.objectweb.cjdbc.common.sql.AbstractWriteRequest#isInsert() 00148 */ 00149 public boolean isInsert() 00150 { 00151 return false; 00152 } 00153 00154 /** 00155 * @return <code>false</code> 00156 * @see org.objectweb.cjdbc.common.sql.AbstractWriteRequest#isUpdate() 00157 */ 00158 public boolean isUpdate() 00159 { 00160 return false; 00161 } 00162 00163 /** 00164 * @return <code>false</code> 00165 * @see org.objectweb.cjdbc.common.sql.AbstractWriteRequest#isDelete() 00166 */ 00167 public boolean isDelete() 00168 { 00169 return false; 00170 } 00171 00172 /** 00173 * @return <code>false</code> 00174 * @see org.objectweb.cjdbc.common.sql.AbstractWriteRequest#isCreate() 00175 */ 00176 public boolean isCreate() 00177 { 00178 return false; 00179 } 00180 00181 /** 00182 * @return <code>true</code> 00183 * @see org.objectweb.cjdbc.common.sql.AbstractWriteRequest#isDrop() 00184 */ 00185 public boolean isDrop() 00186 { 00187 return true; 00188 } 00189 00190 /** 00191 * Displays some debugging information about this request. 00192 */ 00193 public void debug() 00194 { 00195 super.debug(); 00196 if (tableName != null) 00197 System.out.println("Dropped table '" + tableName + "'"); 00198 else 00199 System.out.println("No information about dropped table"); 00200 00201 System.out.println(); 00202 } 00203 /** 00204 * @see org.objectweb.cjdbc.common.sql.AbstractWriteRequest#isAlter() 00205 */ 00206 public boolean isAlter() 00207 { 00208 return false; 00209 } 00210 }