--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.iapi.jdbc.BrokeredPreparedStatement\r
+\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to you under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+\r
+ */\r
+\r
+package org.apache.derby.iapi.jdbc;\r
+\r
+import java.io.InputStream;\r
+import java.io.Reader;\r
+import java.util.Calendar;\r
+\r
+import java.sql.*;\r
+import java.net.URL;\r
+\r
+/**\r
+ JDBC 2 brokered PreparedStatement. Forwards calls off to a real prepared statement\r
+ obtained through the BrokeredStatementControl getRealPreparedStatement method.\r
+ */\r
+public abstract class BrokeredPreparedStatement extends BrokeredStatement\r
+ implements EnginePreparedStatement\r
+{\r
+\r
+ /**\r
+ SQL used to create me.\r
+ */\r
+ final String sql;\r
+\r
+ public BrokeredPreparedStatement(BrokeredStatementControl control, String sql) throws SQLException\r
+ {\r
+ super(control);\r
+ this.sql = sql;\r
+ }\r
+\r
+ /**\r
+ * A prepared SQL query is executed and its ResultSet is returned.\r
+ *\r
+ * @return a ResultSet that contains the data produced by the\r
+ * query; never null\r
+ * @exception SQLException thrown on failure.\r
+ */\r
+ public final ResultSet executeQuery() throws SQLException\r
+ {\r
+ return wrapResultSet(getPreparedStatement().executeQuery());\r
+ } \r
+\r
+ /**\r
+ * Execute a SQL INSERT, UPDATE or DELETE statement. In addition,\r
+ * SQL statements that return nothing such as SQL DDL statements\r
+ * can be executed.\r
+ *\r
+ * @return either the row count for INSERT, UPDATE or DELETE; or 0\r
+ * for SQL statements that return nothing\r
+ * @exception SQLException thrown on failure.\r
+ */\r
+ public final int executeUpdate() throws SQLException\r
+ {\r
+ return getPreparedStatement().executeUpdate();\r
+ }\r
+\r
+ /**\r
+ * Set a parameter to SQL NULL.\r
+ *\r
+ * <P><B>Note:</B> You must specify the parameter's SQL type.\r
+ *\r
+ * @param parameterIndex the first parameter is 1, the second is 2, ...\r
+ * @param sqlType SQL type code defined by java.sql.Types\r
+ * @exception SQLException thrown on failure.\r
+ */\r
+ public final void setNull(int parameterIndex, int sqlType) throws SQLException\r
+ {\r
+ getPreparedStatement().setNull( parameterIndex, sqlType);\r
+ } \r
+\r
+ /**\r
+ * Set a parameter to SQL NULL.\r
+ *\r
+ * <P><B>Note:</B> You must specify the parameter's SQL type.\r
+ *\r
+ * @param parameterIndex the first parameter is 1, the second is 2, ...\r
+ * @param sqlType SQL type code defined by java.sql.Types\r
+ * @exception SQLException thrown on failure.\r
+ */\r
+ public final void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException\r
+ {\r
+ getPreparedStatement().setNull( parameterIndex, sqlType, typeName);\r
+ } \r
+\r
+ /**\r
+ * Set a parameter to a Java boolean value. According to the JDBC API spec,\r
+ * the driver converts this to a SQL BIT value when it sends it to the\r
+ * database. But we don't have to do this, since the database engine\r
+ * supports a boolean type.\r
+ *\r
+ * @param parameterIndex the first parameter is 1, the second is 2, ...\r
+ * @param x the parameter value\r
+ * @exception SQLException thrown on failure.\r
+ */\r
+ public final void setBoolean(int parameterIndex, boolean x) throws SQLException\r
+ {\r
+ getPreparedStatement().setBoolean( parameterIndex, x);\r
+ } \r
+\r
+ /**\r
+ * Set a parameter to a Java byte value. The driver converts this\r
+ * to a SQL TINYINT value when it sends it to the database.\r
+ *\r
+ * @param parameterIndex the first parameter is 1, the second is 2, ...\r
+ * @param x the parameter value\r
+ * @exception SQLException thrown on failure.\r
+ */\r
+ public final void setByte(int parameterIndex, byte x) throws SQLException\r
+ {\r
+ getPreparedStatement().setByte( parameterIndex, x);\r
+ } \r
+\r
+ /**\r
+ * Set a parameter to a Java short value. The driver converts this\r
+ * to a SQL SMALLINT value when it sends it to the database.\r
+ *\r
+ * @param parameterIndex the first parameter is 1, the second is 2, ...\r
+ * @param x the parameter value\r
+ * @exception SQLException thrown on failure.\r
+ */\r
+ public final void setShort(int parameterIndex, short x) throws SQLException\r
+ {\r
+ getPreparedStatement().setShort( parameterIndex, x);\r
+ } \r
+\r
+ /**\r
+ * Set a parameter to a Java int value. The driver converts this\r
+ * to a SQL INTEGER value when it sends it to the database.\r
+ *\r
+ * @param parameterIndex the first parameter is 1, the second is 2, ...\r
+ * @param x the parameter value\r
+ * @exception SQLException thrown on failure.\r
+ */\r
+ public final void setInt(int parameterIndex, int x) throws SQLException\r
+ {\r
+ getPreparedStatement().setInt( parameterIndex, x);\r
+ } \r
+\r
+ /**\r
+ * Set a parameter to a Java long value. The driver converts this\r
+ * to a SQL BIGINT value when it sends it to the database.\r
+ *\r
+ * @param parameterIndex the first parameter is 1, the second is 2, ...\r
+ * @param x the parameter value\r
+ * @exception SQLException thrown on failure.\r
+ */\r
+ public final void setLong(int parameterIndex, long x) throws SQLException\r
+ {\r
+ getPreparedStatement().setLong( parameterIndex, x);\r
+ } \r
+\r
+ /**\r
+ * Set a parameter to a Java float value. The driver converts this\r
+ * to a SQL FLOAT value when it sends it to the database.\r
+ *\r
+ * @param parameterIndex the first parameter is 1, the second is 2, ...\r
+ * @param x the parameter value\r
+ * @exception SQLException thrown on failure.\r
+ */\r
+ public final void setFloat(int parameterIndex, float x) throws SQLException\r
+ {\r
+ getPreparedStatement().setFloat( parameterIndex, x);\r
+ } \r
+\r
+ /**\r
+ * Set a parameter to a Java double value. The driver converts this\r
+ * to a SQL DOUBLE value when it sends it to the database.\r
+ *\r
+ * @param parameterIndex the first parameter is 1, the second is 2, ...\r
+ * @param x the parameter value\r
+ * @exception SQLException thrown on failure.\r
+ */\r
+ public final void setDouble(int parameterIndex, double x) throws SQLException\r
+ {\r
+ getPreparedStatement().setDouble( parameterIndex, x);\r
+ } \r
+\r
+\r
+ /**\r
+ * Set a parameter to a java.math.BigDecimal value. \r
+ * The driver converts this to a SQL NUMERIC value when\r
+ * it sends it to the database.\r
+ *\r
+ * @param parameterIndex the first parameter is 1, the second is 2, ...\r
+ * @param x the parameter value\r
+ * @exception SQLException thrown on failure.\r
+ */\r
+ public final void setBigDecimal(int parameterIndex, java.math.BigDecimal x) throws SQLException\r
+ {\r
+ getPreparedStatement().setBigDecimal( parameterIndex, x);\r
+ } \r
+\r
+ /**\r
+ * Set a parameter to a Java String value. The driver converts this\r
+ * to a SQL VARCHAR or LONGVARCHAR value (depending on the arguments\r
+ * size relative to the driver's limits on VARCHARs) when it sends\r
+ * it to the database.\r
+ *\r
+ * @param parameterIndex the first parameter is 1, the second is 2, ...\r
+ * @param x the parameter value\r
+ * @exception SQLException thrown on failure.\r
+ */\r
+ public final void setString(int parameterIndex, String x) throws SQLException\r
+ {\r
+ getPreparedStatement().setString( parameterIndex, x);\r
+ } \r
+\r
+ /**\r
+ * Set a parameter to a Java array of bytes. The driver converts\r
+ * this to a SQL VARBINARY or LONGVARBINARY (depending on the\r
+ * argument's size relative to the driver's limits on VARBINARYs)\r
+ * when it sends it to the database.\r
+ *\r
+ * @param parameterIndex the first parameter is 1, the second is 2, ...\r
+ * @param x the parameter value \r
+ * @exception SQLException thrown on failure.\r
+ */\r
+ public final void setBytes(int parameterIndex, byte[] x) throws SQLException\r
+ {\r
+ getPreparedStatement().setBytes( parameterIndex, x);\r
+ } \r
+\r
+ /**\r
+ * Set a parameter to a java.sql.Date value. The driver converts this\r
+ * to a SQL DATE value when it sends it to the database.\r
+ *\r
+ * @param parameterIndex the first parameter is 1, the second is 2, ...\r
+ * @param x the parameter value\r
+ * @exception SQLException thrown on failure.\r
+ */\r
+ public final void setDate(int parameterIndex, Date x) throws SQLException\r
+ {\r
+ getPreparedStatement().setDate( parameterIndex, x);\r
+ } \r
+\r
+ /**\r
+ * Set a parameter to a java.sql.Time value. The driver converts this\r
+ * to a SQL TIME value when it sends it to the database.\r
+ *\r
+ * @param parameterIndex the first parameter is 1, the second is 2, ...\r
+ * @param x the parameter value\r
+ * @exception SQLException thrown on failure.\r
+ */\r
+ public final void setTime(int parameterIndex, Time x) throws SQLException\r
+ {\r
+ getPreparedStatement().setTime( parameterIndex, x);\r
+ } \r
+\r
+ /**\r
+ * Set a parameter to a java.sql.Timestamp value. The driver\r
+ * converts this to a SQL TIMESTAMP value when it sends it to the\r
+ * database.\r
+ *\r
+ * @param parameterIndex the first parameter is 1, the second is 2, ...\r
+ * @param x the parameter value \r
+ * @exception SQLException thrown on failure.\r
+ */\r
+ public final void setTimestamp(int parameterIndex, Timestamp x) throws SQLException\r
+ {\r
+ getPreparedStatement().setTimestamp( parameterIndex, x);\r
+ } \r
+\r
+ /**\r
+ * We do this inefficiently and read it all in here. The target type\r
+ * is assumed to be a String.\r
+ * \r
+ * @param parameterIndex the first parameter is 1, the second is 2, ...\r
+ * @param x the java input stream which contains the ASCII parameter value\r
+ * @param length the number of bytes in the stream \r
+ * @exception SQLException thrown on failure.\r
+ */\r
+ public final void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException\r
+ {\r
+ getPreparedStatement().setAsciiStream( parameterIndex, x, length);\r
+ } \r
+\r
+ /**\r
+ * We do this inefficiently and read it all in here. The target type\r
+ * is assumed to be a String. The unicode source is assumed to be\r
+ * in char[]. RESOLVE: might it be in UTF, instead? that'd be faster!\r
+ * \r
+ * @param parameterIndex the first parameter is 1, the second is 2, ... \r
+ * @param x the java input stream which contains the\r
+ * UNICODE parameter value \r
+ * @param length the number of bytes in the stream \r
+ * @exception SQLException thrown on failure.\r
+ */\r
+ public final void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException\r
+ {\r
+ getPreparedStatement().setUnicodeStream( parameterIndex, x, length);\r
+ } \r
+\r
+ /**\r
+ * @param parameterIndex the first parameter is 1, the second is 2, ...\r
+ * @param x the java input stream which contains the binary parameter value\r
+ * @param length the number of bytes in the stream \r
+ * @exception SQLException thrown on failure.\r
+ */\r
+ public final void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException\r
+ {\r
+ getPreparedStatement().setBinaryStream( parameterIndex, x, length);\r
+ } \r
+\r
+ /**\r
+ * JDBC 2.0\r
+ *\r
+ * Add a set of parameters to the batch.\r
+ * \r
+ * @exception SQLException if a database-access error occurs.\r
+ */\r
+ public final void addBatch() throws SQLException\r
+ {\r
+ getPreparedStatement().addBatch( );\r
+ } \r
+\r
+ /**\r
+ * <P>In general, parameter values remain in force for repeated use of a\r
+ * Statement. Setting a parameter value automatically clears its\r
+ * previous value. However, in some cases it is useful to immediately\r
+ * release the resources used by the current parameter values; this can\r
+ * be done by calling clearParameters.\r
+ * @exception SQLException thrown on failure.\r
+ */\r
+ public final void clearParameters() throws SQLException\r
+ {\r
+ getPreparedStatement().clearParameters( );\r
+ } \r
+\r
+ /**\r
+ * JDBC 2.0\r
+ *\r
+ * The number, types and properties of a ResultSet's columns\r
+ * are provided by the getMetaData method.\r
+ *\r
+ * @return the description of a ResultSet's columns\r
+ * @exception SQLException Feature not implemented for now.\r
+ */\r
+ public final java.sql.ResultSetMetaData getMetaData() throws SQLException\r
+ {\r
+ return getPreparedStatement().getMetaData();\r
+ }\r
+\r
+ /**\r
+ * The interface says that the type of the Object parameter must\r
+ * be compatible with the type of the targetSqlType. We check that,\r
+ * and if it flies, we expect the underlying engine to do the\r
+ * required conversion once we pass in the value using its type.\r
+ * So, an Integer converting to a CHAR is done via setInteger()\r
+ * support on the underlying CHAR type.\r
+ *\r
+ * <p>If x is null, it won't tell us its type, so we pass it on to setNull\r
+ *\r
+ * @param parameterIndex The first parameter is 1, the second is 2, ...\r
+ * @param x The object containing the input parameter value\r
+ * @param targetSqlType The SQL type (as defined in java.sql.Types) to be \r
+ * sent to the database. The scale argument may further qualify this type.\r
+ * @param scale For java.sql.Types.DECIMAL or java.sql.Types.NUMERIC types\r
+ * this is the number of digits after the decimal. For all other\r
+ * types this value will be ignored,\r
+ * @exception SQLException thrown on failure.\r
+ */\r
+ public final void setObject(int parameterIndex, Object x, int targetSqlType, int scale)\r
+ throws SQLException\r
+ {\r
+ getPreparedStatement().setObject( parameterIndex, x, targetSqlType, scale);\r
+ } \r
+ \r
+ /**\r
+ * This method is like setObject above, but assumes a scale of zero.\r
+ * @exception SQLException thrown on failure.\r
+ */\r
+ public final void setObject(int parameterIndex, Object x, int targetSqlType)\r
+ throws SQLException\r
+ {\r
+ getPreparedStatement().setObject( parameterIndex, x, targetSqlType);\r
+ } \r
+\r
+ /**\r
+ * <p>Set the value of a parameter using an object; use the\r
+ * java.lang equivalent objects for integral values.\r
+ *\r
+ * <p>The JDBC specification specifies a standard mapping from\r
+ * Java Object types to SQL types. The given argument java object\r
+ * will be converted to the corresponding SQL type before being\r
+ * sent to the database.\r
+ *\r
+ * <p>Note that this method may be used to pass datatabase\r
+ * specific abstract data types, by using a Driver specific Java\r
+ * type.\r
+ *\r
+ * @param parameterIndex The first parameter is 1, the second is 2, ...\r
+ * @param x The object containing the input parameter value \r
+ * @exception SQLException thrown on failure.\r
+ */\r
+ public final void setObject(int parameterIndex, Object x)\r
+ throws SQLException\r
+ {\r
+ getPreparedStatement().setObject( parameterIndex, x);\r
+ } \r
+\r
+ /**\r
+ * @see java.sql.Statement#execute\r
+ * @exception SQLException thrown on failure.\r
+ */\r
+ public final boolean execute() throws SQLException\r
+ {\r
+ return getPreparedStatement().execute();\r
+ }\r
+\r
+ public final void setCharacterStream(int parameterIndex,\r
+ Reader reader,\r
+ int length)\r
+ throws SQLException\r
+ {\r
+ getPreparedStatement().setCharacterStream( parameterIndex, reader, length);\r
+ }\r
+\r
+ public final void setRef(int i,\r
+ Ref x)\r
+ throws SQLException\r
+ {\r
+ getPreparedStatement().setRef( i, x);\r
+ }\r
+\r
+ public final void setBlob(int i,\r
+ Blob x)\r
+ throws SQLException\r
+ {\r
+ getPreparedStatement().setBlob( i, x);\r
+ }\r
+\r
+ public final void setClob(int i,\r
+ Clob x)\r
+ throws SQLException\r
+ {\r
+ getPreparedStatement().setClob( i, x);\r
+ }\r
+\r
+ public final void setArray(int i,\r
+ Array x)\r
+ throws SQLException\r
+ {\r
+ getPreparedStatement().setArray( i, x);\r
+ }\r
+\r
+ public final void setDate(int i,\r
+ Date x,\r
+ Calendar cal)\r
+ throws SQLException\r
+ {\r
+ getPreparedStatement().setDate( i, x, cal);\r
+ }\r
+\r
+ public final void setTime(int i,\r
+ Time x,\r
+ Calendar cal)\r
+ throws SQLException\r
+ {\r
+ getPreparedStatement().setTime( i, x, cal);\r
+ }\r
+\r
+ public final void setTimestamp(int i,\r
+ Timestamp x,\r
+ Calendar cal)\r
+ throws SQLException\r
+ {\r
+ getPreparedStatement().setTimestamp( i, x, cal);\r
+ }\r
+ \r
+ \r
+ public void setBinaryStream(int parameterIndex, \r
+ InputStream x)\r
+ throws SQLException {\r
+ \r
+ final EnginePreparedStatement engnps = \r
+ (EnginePreparedStatement) getPreparedStatement(); \r
+\r
+ engnps.setBinaryStream(parameterIndex, x);\r
+\r
+ }\r
+ \r
+ \r
+ public void setCharacterStream(int parameterIndex, \r
+ Reader reader)\r
+ throws SQLException{\r
+ \r
+ final EnginePreparedStatement engnps = \r
+ (EnginePreparedStatement) getPreparedStatement(); \r
+\r
+ engnps.setCharacterStream(parameterIndex, reader);\r
+ \r
+ }\r
+\r
+ /*\r
+ ** Control methods.\r
+ */\r
+\r
+ /**\r
+ * Access the underlying PreparedStatement. This method\r
+ * is package protected to restrict access to the underlying\r
+ * object to the brokered objects. Allowing the application to\r
+ * access the underlying object thtough a public method would\r
+ * \r
+ */\r
+ PreparedStatement getPreparedStatement() throws SQLException {\r
+ return control.getRealPreparedStatement();\r
+ }\r
+\r
+ /**\r
+ Override the BrokeredStatement's getStatement() to always return a PreparedStatement.\r
+ */\r
+ public final Statement getStatement() throws SQLException {\r
+ return getPreparedStatement();\r
+ }\r
+\r
+ /**\r
+ Create a duplicate PreparedStatement to this, including state, from the passed in Connection.\r
+ */\r
+ public PreparedStatement createDuplicateStatement(Connection conn, PreparedStatement oldStatement) throws SQLException {\r
+\r
+ PreparedStatement newStatement = conn.prepareStatement(sql, resultSetType, resultSetConcurrency);\r
+\r
+ setStatementState(oldStatement, newStatement);\r
+\r
+ return newStatement;\r
+ }\r
+}\r