001: /*
002:
003: Derby - Class org.apache.derby.client.net.NetPreparedStatement
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to You under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021: package org.apache.derby.client.net;
022:
023: import org.apache.derby.client.am.ColumnMetaData;
024: import org.apache.derby.client.am.PreparedStatement;
025: import org.apache.derby.client.am.Section;
026: import org.apache.derby.client.am.SqlException;
027: import org.apache.derby.jdbc.ClientDriver;
028: import org.apache.derby.client.am.ClientJDBCObjectFactory;
029: import org.apache.derby.client.ClientPooledConnection;
030:
031: public class NetPreparedStatement extends NetStatement implements
032: org.apache.derby.client.am.MaterialPreparedStatement {
033:
034: // Alias for (NetPreparedStatement) super.statement.
035: /*final*/
036: org.apache.derby.client.am.PreparedStatement preparedStatement_;
037:
038: // Relay constructor for NetCallableStatement.
039: NetPreparedStatement(
040: org.apache.derby.client.am.PreparedStatement statement,
041: NetAgent netAgent, NetConnection netConnection) {
042: super (statement, netAgent, netConnection);
043: initNetPreparedStatement(statement);
044: }
045:
046: void resetNetPreparedStatement(
047: org.apache.derby.client.am.PreparedStatement statement,
048: NetAgent netAgent, NetConnection netConnection) {
049: super .resetNetStatement(statement, netAgent, netConnection);
050: initNetPreparedStatement(statement);
051: }
052:
053: private void initNetPreparedStatement(
054: org.apache.derby.client.am.PreparedStatement statement) {
055: preparedStatement_ = statement;
056: preparedStatement_.materialPreparedStatement_ = this ;
057: }
058:
059: /**
060: *
061: * The constructor for the NetPreparedStatement class. Called by abstract
062: * Connection.prepareStatment().newPreparedStatement()
063: * for jdbc 2 prepared statements with scroll attributes.
064: * It has the ClientPooledConnection as one of its parameters
065: * this is used to raise the Statement Events when the prepared
066: * statement is closed.
067: *
068: * @param netAgent The instance of NetAgent associated with this
069: * CallableStatement object.
070: * @param netConnection The connection object associated with this
071: * PreparedStatement Object.
072: * @param sql A String object that is the SQL statement
073: * to be sent to the database.
074: * @param type One of the ResultSet type constants.
075: * @param concurrency One of the ResultSet concurrency constants.
076: * @param holdability One of the ResultSet holdability constants.
077: * @param autoGeneratedKeys a flag indicating whether auto-generated
078: * keys should be returned.
079: * @param columnNames A String array of column names indicating
080: * the columns that should be returned
081: * from the inserted row or rows.
082: * @param cpc The ClientPooledConnection wraps the underlying physical
083: * connection associated with this prepared statement
084: * it is used to pass the Statement closed and the Statement
085: * error occurred events that occur back to the
086: * ClientPooledConnection.
087: * @throws SqlException
088: *
089: */
090: NetPreparedStatement(NetAgent netAgent,
091: NetConnection netConnection, String sql, int type,
092: int concurrency, int holdability, int autoGeneratedKeys,
093: String[] columnNames, ClientPooledConnection cpc)
094: throws SqlException {
095: this (ClientDriver.getFactory().newPreparedStatement(netAgent,
096: netConnection, sql, type, concurrency, holdability,
097: autoGeneratedKeys, columnNames, cpc), netAgent,
098: netConnection);
099: }
100:
101: void resetNetPreparedStatement(NetAgent netAgent,
102: NetConnection netConnection, String sql, int type,
103: int concurrency, int holdability, int autoGeneratedKeys,
104: String[] columnNames) throws SqlException {
105: preparedStatement_.resetPreparedStatement(netAgent,
106: netConnection, sql, type, concurrency, holdability,
107: autoGeneratedKeys, columnNames);
108: resetNetPreparedStatement(preparedStatement_, netAgent,
109: netConnection);
110: }
111:
112: /**
113: *
114: * The constructor for the NetPreparedStatement class. For JDBC 3.0
115: * positioned updates.It has the ClientPooledConnection as one of
116: * its parameters this is used to raise the Statement Events when the
117: * prepared statement is closed.
118: *
119: * @param netAgent The instance of NetAgent associated with this
120: * CallableStatement object.
121: * @param netConnection The connection object associated with this
122: * PreparedStatement Object.
123: * @param sql A String object that is the SQL statement to be
124: * sent to the database.
125: * @param section
126: * @param cpc The ClientPooledConnection wraps the underlying physical
127: * connection associated with this prepared statement
128: * it is used to pass the Statement closed and the Statement
129: * error occurred events that occur back to the
130: * ClientPooledConnection
131: * @throws SqlException
132: *
133: */
134: NetPreparedStatement(NetAgent netAgent,
135: NetConnection netConnection, String sql, Section section,
136: ClientPooledConnection cpc) throws SqlException {
137: this (ClientDriver.getFactory().newPreparedStatement(netAgent,
138: netConnection, sql, section, cpc), netAgent,
139: netConnection);
140: }
141:
142: void resetNetPreparedStatement(NetAgent netAgent,
143: NetConnection netConnection, String sql, Section section)
144: throws SqlException {
145: preparedStatement_.resetPreparedStatement(netAgent,
146: netConnection, sql, section);
147: resetNetPreparedStatement(preparedStatement_, netAgent,
148: netConnection);
149: }
150:
151: void resetNetPreparedStatement(NetAgent netAgent,
152: NetConnection netConnection, String sql, Section section,
153: ColumnMetaData parameterMetaData,
154: ColumnMetaData resultSetMetaData) throws SqlException {
155: preparedStatement_.resetPreparedStatement(netAgent,
156: netConnection, sql, section, parameterMetaData,
157: resultSetMetaData);
158: this .resetNetPreparedStatement(preparedStatement_, netAgent,
159: netConnection);
160: }
161:
162: protected void finalize() throws java.lang.Throwable {
163: super .finalize();
164: }
165:
166: public void writeExecute_(Section section,
167: ColumnMetaData parameterMetaData, Object[] inputs,
168: int numInputColumns, boolean outputExpected,
169: // This is a hint to the material layer that more write commands will follow.
170: // It is ignored by the driver in all cases except when blob data is written,
171: // in which case this boolean is used to optimize the implementation.
172: // Otherwise we wouldn't be able to chain after blob data is sent.
173: // If we could always chain a no-op DDM after every execute that writes blobs
174: // then we could just always set the chaining flag to on for blob send data
175: boolean chainedWritesFollowingSetLob) throws SqlException {
176: netAgent_.statementRequest_.writeExecute(this , section,
177: parameterMetaData, inputs, numInputColumns,
178: outputExpected, chainedWritesFollowingSetLob);
179: }
180:
181: public void readExecute_() throws SqlException {
182: netAgent_.statementReply_.readExecute(preparedStatement_);
183: }
184:
185: public void writeOpenQuery_(Section section, int fetchSize,
186: int resultSetType, int numInputColumns,
187: ColumnMetaData parameterMetaData, Object[] inputs)
188: throws SqlException {
189: netAgent_.statementRequest_.writeOpenQuery(this , section,
190: fetchSize, resultSetType, numInputColumns,
191: parameterMetaData, inputs);
192: }
193:
194: // super.readOpenQuery()
195:
196: public void writeDescribeInput_(Section section)
197: throws SqlException {
198: netAgent_.statementRequest_.writeDescribeInput(this , section);
199: }
200:
201: public void readDescribeInput_() throws SqlException {
202: netAgent_.statementReply_.readDescribeInput(preparedStatement_);
203: }
204:
205: public void writeDescribeOutput_(Section section)
206: throws SqlException {
207: netAgent_.statementRequest_.writeDescribeOutput(this , section);
208: }
209:
210: public void readDescribeOutput_() throws SqlException {
211: netAgent_.statementReply_
212: .readDescribeOutput(preparedStatement_);
213: }
214: }
|