1 | /* |
2 | |
3 | Derby - Class org.apache.derby.client.net.NetPreparedStatement |
4 | |
5 | Copyright (c) 2001, 2005 The Apache Software Foundation or its licensors, where applicable. |
6 | |
7 | Licensed under the Apache License, Version 2.0 (the "License"); |
8 | you may not use this file except in compliance with the License. |
9 | You may obtain a copy of the License at |
10 | |
11 | http://www.apache.org/licenses/LICENSE-2.0 |
12 | |
13 | Unless required by applicable law or agreed to in writing, software |
14 | distributed under the License is distributed on an "AS IS" BASIS, |
15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | See the License for the specific language governing permissions and |
17 | limitations under the License. |
18 | |
19 | */ |
20 | package org.apache.derby.client.net; |
21 | |
22 | import org.apache.derby.client.am.ColumnMetaData; |
23 | import org.apache.derby.client.am.PreparedStatement; |
24 | import org.apache.derby.client.am.Section; |
25 | import org.apache.derby.client.am.SqlException; |
26 | import org.apache.derby.jdbc.ClientDriver; |
27 | import org.apache.derby.client.am.ClientJDBCObjectFactory; |
28 | import org.apache.derby.client.ClientPooledConnection; |
29 | |
30 | |
31 | public class NetPreparedStatement extends NetStatement |
32 | implements org.apache.derby.client.am.MaterialPreparedStatement { |
33 | |
34 | // Alias for (NetPreparedStatement) super.statement. |
35 | /*final*/ |
36 | org.apache.derby.client.am.PreparedStatement preparedStatement_; |
37 | |
38 | |
39 | // Relay constructor for NetCallableStatement. |
40 | NetPreparedStatement(org.apache.derby.client.am.PreparedStatement statement, |
41 | NetAgent netAgent, |
42 | NetConnection netConnection) { |
43 | super(statement, netAgent, netConnection); |
44 | initNetPreparedStatement(statement); |
45 | } |
46 | |
47 | void resetNetPreparedStatement(org.apache.derby.client.am.PreparedStatement statement, |
48 | NetAgent netAgent, |
49 | NetConnection netConnection) { |
50 | super.resetNetStatement(statement, netAgent, netConnection); |
51 | initNetPreparedStatement(statement); |
52 | } |
53 | |
54 | private void initNetPreparedStatement(org.apache.derby.client.am.PreparedStatement statement) { |
55 | preparedStatement_ = statement; |
56 | preparedStatement_.materialPreparedStatement_ = this; |
57 | } |
58 | |
59 | /** |
60 | * |
61 | * The constructor for the NetPreparedStatement class. Called by abstract |
62 | * Connection.prepareStatment().newPreparedStatement() |
63 | * for jdbc 2 prepared statements with scroll attributes. |
64 | * It has the ClientPooledConnection as one of its parameters |
65 | * this is used to raise the Statement Events when the prepared |
66 | * statement is closed. |
67 | * |
68 | * @param netAgent The instance of NetAgent associated with this |
69 | * CallableStatement object. |
70 | * @param netConnection The connection object associated with this |
71 | * PreparedStatement Object. |
72 | * @param sql A String object that is the SQL statement |
73 | * to be sent to the database. |
74 | * @param type One of the ResultSet type constants. |
75 | * @param concurrency One of the ResultSet concurrency constants. |
76 | * @param holdability One of the ResultSet holdability constants. |
77 | * @param autoGeneratedKeys a flag indicating whether auto-generated |
78 | * keys should be returned. |
79 | * @param columnNames A String array of column names indicating |
80 | * the columns that should be returned |
81 | * from the inserted row or rows. |
82 | * @param cpc The ClientPooledConnection wraps the underlying physical |
83 | * connection associated with this prepared statement |
84 | * it is used to pass the Statement closed and the Statement |
85 | * error occurred events that occur back to the |
86 | * ClientPooledConnection. |
87 | * @throws SqlException |
88 | * |
89 | */ |
90 | NetPreparedStatement(NetAgent netAgent, NetConnection netConnection, String sql, int type, int concurrency, int holdability, int autoGeneratedKeys, String[] columnNames, ClientPooledConnection cpc) throws SqlException { |
91 | this(ClientDriver.getFactory().newPreparedStatement(netAgent, |
92 | netConnection, sql, type, concurrency, holdability, |
93 | autoGeneratedKeys, columnNames, cpc), |
94 | netAgent, |
95 | netConnection |
96 | ); |
97 | } |
98 | |
99 | void resetNetPreparedStatement(NetAgent netAgent, NetConnection netConnection, String sql, int type, int concurrency, int holdability, int autoGeneratedKeys, String[] columnNames) throws SqlException { |
100 | preparedStatement_.resetPreparedStatement(netAgent, netConnection, sql, type, concurrency, holdability, autoGeneratedKeys, columnNames); |
101 | resetNetPreparedStatement(preparedStatement_, netAgent, netConnection); |
102 | } |
103 | |
104 | /** |
105 | * |
106 | * The constructor for the NetPreparedStatement class. For JDBC 3.0 |
107 | * positioned updates.It has the ClientPooledConnection as one of |
108 | * its parameters this is used to raise the Statement Events when the |
109 | * prepared statement is closed. |
110 | * |
111 | * @param netAgent The instance of NetAgent associated with this |
112 | * CallableStatement object. |
113 | * @param netConnection The connection object associated with this |
114 | * PreparedStatement Object. |
115 | * @param sql A String object that is the SQL statement to be |
116 | * sent to the database. |
117 | * @param section |
118 | * @param cpc The ClientPooledConnection wraps the underlying physical |
119 | * connection associated with this prepared statement |
120 | * it is used to pass the Statement closed and the Statement |
121 | * error occurred events that occur back to the |
122 | * ClientPooledConnection |
123 | * @throws SqlException |
124 | * |
125 | */ |
126 | NetPreparedStatement(NetAgent netAgent, |
127 | NetConnection netConnection, |
128 | String sql, |
129 | Section section,ClientPooledConnection cpc) |
130 | throws SqlException { |
131 | this(ClientDriver.getFactory().newPreparedStatement(netAgent, |
132 | netConnection, sql, section,cpc), |
133 | netAgent, |
134 | netConnection); |
135 | } |
136 | |
137 | void resetNetPreparedStatement(NetAgent netAgent, |
138 | NetConnection netConnection, |
139 | String sql, |
140 | Section section) throws SqlException { |
141 | preparedStatement_.resetPreparedStatement(netAgent, netConnection, sql, section); |
142 | resetNetPreparedStatement(preparedStatement_, netAgent, netConnection); |
143 | } |
144 | |
145 | void resetNetPreparedStatement(NetAgent netAgent, |
146 | NetConnection netConnection, |
147 | String sql, |
148 | Section section, |
149 | ColumnMetaData parameterMetaData, |
150 | ColumnMetaData resultSetMetaData) throws SqlException { |
151 | preparedStatement_.resetPreparedStatement(netAgent, netConnection, sql, section, parameterMetaData, resultSetMetaData); |
152 | this.resetNetPreparedStatement(preparedStatement_, netAgent, netConnection); |
153 | } |
154 | |
155 | protected void finalize() throws java.lang.Throwable { |
156 | super.finalize(); |
157 | } |
158 | |
159 | public void writeExecute_(Section section, |
160 | ColumnMetaData parameterMetaData, |
161 | Object[] inputs, |
162 | int numInputColumns, |
163 | boolean outputExpected, |
164 | // This is a hint to the material layer that more write commands will follow. |
165 | // It is ignored by the driver in all cases except when blob data is written, |
166 | // in which case this boolean is used to optimize the implementation. |
167 | // Otherwise we wouldn't be able to chain after blob data is sent. |
168 | // If we could always chain a no-op DDM after every execute that writes blobs |
169 | // then we could just always set the chaining flag to on for blob send data |
170 | boolean chainedWritesFollowingSetLob) throws SqlException { |
171 | netAgent_.statementRequest_.writeExecute(this, |
172 | section, |
173 | parameterMetaData, |
174 | inputs, |
175 | numInputColumns, |
176 | outputExpected, |
177 | chainedWritesFollowingSetLob); |
178 | } |
179 | |
180 | |
181 | public void readExecute_() throws SqlException { |
182 | netAgent_.statementReply_.readExecute(preparedStatement_); |
183 | } |
184 | |
185 | public void writeOpenQuery_(Section section, |
186 | int fetchSize, |
187 | int resultSetType, |
188 | int numInputColumns, |
189 | ColumnMetaData parameterMetaData, |
190 | Object[] inputs) throws SqlException { |
191 | netAgent_.statementRequest_.writeOpenQuery(this, |
192 | section, |
193 | fetchSize, |
194 | resultSetType, |
195 | numInputColumns, |
196 | parameterMetaData, |
197 | inputs); |
198 | } |
199 | // super.readOpenQuery() |
200 | |
201 | public void writeDescribeInput_(Section section) throws SqlException { |
202 | netAgent_.statementRequest_.writeDescribeInput(this, section); |
203 | } |
204 | |
205 | public void readDescribeInput_() throws SqlException { |
206 | netAgent_.statementReply_.readDescribeInput(preparedStatement_); |
207 | } |
208 | |
209 | public void writeDescribeOutput_(Section section) throws SqlException { |
210 | netAgent_.statementRequest_.writeDescribeOutput(this, section); |
211 | } |
212 | |
213 | public void readDescribeOutput_() throws SqlException { |
214 | netAgent_.statementReply_.readDescribeOutput(preparedStatement_); |
215 | } |
216 | } |