KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > client > net > NetPreparedStatement


1 /*
2
3    Derby - Class org.apache.derby.client.net.NetPreparedStatement
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20 */

21 package org.apache.derby.client.net;
22
23 import org.apache.derby.client.am.ColumnMetaData;
24 import org.apache.derby.client.am.PreparedStatement;
25 import org.apache.derby.client.am.Section;
26 import org.apache.derby.client.am.SqlException;
27 import org.apache.derby.jdbc.ClientDriver;
28 import org.apache.derby.client.am.ClientJDBCObjectFactory;
29 import org.apache.derby.client.ClientPooledConnection;
30
31
32 public class NetPreparedStatement extends NetStatement
33         implements org.apache.derby.client.am.MaterialPreparedStatement {
34
35     // Alias for (NetPreparedStatement) super.statement.
36
/*final*/
37     org.apache.derby.client.am.PreparedStatement preparedStatement_;
38
39
40     // Relay constructor for NetCallableStatement.
41
NetPreparedStatement(org.apache.derby.client.am.PreparedStatement statement,
42                          NetAgent netAgent,
43                          NetConnection netConnection) {
44         super(statement, netAgent, netConnection);
45         initNetPreparedStatement(statement);
46     }
47
48     void resetNetPreparedStatement(org.apache.derby.client.am.PreparedStatement statement,
49                                    NetAgent netAgent,
50                                    NetConnection netConnection) {
51         super.resetNetStatement(statement, netAgent, netConnection);
52         initNetPreparedStatement(statement);
53     }
54
55     private void initNetPreparedStatement(org.apache.derby.client.am.PreparedStatement statement) {
56         preparedStatement_ = statement;
57         preparedStatement_.materialPreparedStatement_ = this;
58     }
59
60     /**
61      *
62      * The constructor for the NetPreparedStatement class. Called by abstract
63      * Connection.prepareStatment().newPreparedStatement()
64      * for jdbc 2 prepared statements with scroll attributes.
65      * It has the ClientPooledConnection as one of its parameters
66      * this is used to raise the Statement Events when the prepared
67      * statement is closed.
68      *
69      * @param netAgent The instance of NetAgent associated with this
70      * CallableStatement object.
71      * @param netConnection The connection object associated with this
72      * PreparedStatement Object.
73      * @param sql A String object that is the SQL statement
74      * to be sent to the database.
75      * @param type One of the ResultSet type constants.
76      * @param concurrency One of the ResultSet concurrency constants.
77      * @param holdability One of the ResultSet holdability constants.
78      * @param autoGeneratedKeys a flag indicating whether auto-generated
79      * keys should be returned.
80      * @param columnNames A String array of column names indicating
81      * the columns that should be returned
82      * from the inserted row or rows.
83      * @param cpc The ClientPooledConnection wraps the underlying physical
84      * connection associated with this prepared statement
85      * it is used to pass the Statement closed and the Statement
86      * error occurred events that occur back to the
87      * ClientPooledConnection.
88      * @throws SqlException
89      *
90      */

91     NetPreparedStatement(NetAgent netAgent, NetConnection netConnection, String JavaDoc sql, int type, int concurrency, int holdability, int autoGeneratedKeys, String JavaDoc[] columnNames, ClientPooledConnection cpc) throws SqlException {
92         this(ClientDriver.getFactory().newPreparedStatement(netAgent,
93                 netConnection, sql, type, concurrency, holdability,
94                 autoGeneratedKeys, columnNames, cpc),
95                 netAgent,
96                 netConnection
97                 );
98     }
99
100     void resetNetPreparedStatement(NetAgent netAgent, NetConnection netConnection, String JavaDoc sql, int type, int concurrency, int holdability, int autoGeneratedKeys, String JavaDoc[] columnNames) throws SqlException {
101         preparedStatement_.resetPreparedStatement(netAgent, netConnection, sql, type, concurrency, holdability, autoGeneratedKeys, columnNames);
102         resetNetPreparedStatement(preparedStatement_, netAgent, netConnection);
103     }
104
105     /**
106      *
107      * The constructor for the NetPreparedStatement class. For JDBC 3.0
108      * positioned updates.It has the ClientPooledConnection as one of
109      * its parameters this is used to raise the Statement Events when the
110      * prepared statement is closed.
111      *
112      * @param netAgent The instance of NetAgent associated with this
113      * CallableStatement object.
114      * @param netConnection The connection object associated with this
115      * PreparedStatement Object.
116      * @param sql A String object that is the SQL statement to be
117      * sent to the database.
118      * @param section
119      * @param cpc The ClientPooledConnection wraps the underlying physical
120      * connection associated with this prepared statement
121      * it is used to pass the Statement closed and the Statement
122      * error occurred events that occur back to the
123      * ClientPooledConnection
124      * @throws SqlException
125      *
126      */

127     NetPreparedStatement(NetAgent netAgent,
128                          NetConnection netConnection,
129                          String JavaDoc sql,
130                          Section section,ClientPooledConnection cpc)
131                          throws SqlException {
132         this(ClientDriver.getFactory().newPreparedStatement(netAgent,
133                 netConnection, sql, section,cpc),
134                 netAgent,
135                 netConnection);
136     }
137
138     void resetNetPreparedStatement(NetAgent netAgent,
139                                    NetConnection netConnection,
140                                    String JavaDoc sql,
141                                    Section section) throws SqlException {
142         preparedStatement_.resetPreparedStatement(netAgent, netConnection, sql, section);
143         resetNetPreparedStatement(preparedStatement_, netAgent, netConnection);
144     }
145
146     void resetNetPreparedStatement(NetAgent netAgent,
147                                    NetConnection netConnection,
148                                    String JavaDoc sql,
149                                    Section section,
150                                    ColumnMetaData parameterMetaData,
151                                    ColumnMetaData resultSetMetaData) throws SqlException {
152         preparedStatement_.resetPreparedStatement(netAgent, netConnection, sql, section, parameterMetaData, resultSetMetaData);
153         this.resetNetPreparedStatement(preparedStatement_, netAgent, netConnection);
154     }
155
156     protected void finalize() throws java.lang.Throwable JavaDoc {
157         super.finalize();
158     }
159
160     public void writeExecute_(Section section,
161                               ColumnMetaData parameterMetaData,
162                               Object JavaDoc[] inputs,
163                               int numInputColumns,
164                               boolean outputExpected,
165                               // This is a hint to the material layer that more write commands will follow.
166
// It is ignored by the driver in all cases except when blob data is written,
167
// in which case this boolean is used to optimize the implementation.
168
// Otherwise we wouldn't be able to chain after blob data is sent.
169
// If we could always chain a no-op DDM after every execute that writes blobs
170
// then we could just always set the chaining flag to on for blob send data
171
boolean chainedWritesFollowingSetLob) throws SqlException {
172         netAgent_.statementRequest_.writeExecute(this,
173                 section,
174                 parameterMetaData,
175                 inputs,
176                 numInputColumns,
177                 outputExpected,
178                 chainedWritesFollowingSetLob);
179     }
180
181
182     public void readExecute_() throws SqlException {
183         netAgent_.statementReply_.readExecute(preparedStatement_);
184     }
185
186     public void writeOpenQuery_(Section section,
187                                 int fetchSize,
188                                 int resultSetType,
189                                 int numInputColumns,
190                                 ColumnMetaData parameterMetaData,
191                                 Object JavaDoc[] inputs) throws SqlException {
192         netAgent_.statementRequest_.writeOpenQuery(this,
193                 section,
194                 fetchSize,
195                 resultSetType,
196                 numInputColumns,
197                 parameterMetaData,
198                 inputs);
199     }
200     // super.readOpenQuery()
201

202     public void writeDescribeInput_(Section section) throws SqlException {
203         netAgent_.statementRequest_.writeDescribeInput(this, section);
204     }
205
206     public void readDescribeInput_() throws SqlException {
207         netAgent_.statementReply_.readDescribeInput(preparedStatement_);
208     }
209
210     public void writeDescribeOutput_(Section section) throws SqlException {
211         netAgent_.statementRequest_.writeDescribeOutput(this, section);
212     }
213
214     public void readDescribeOutput_() throws SqlException {
215         netAgent_.statementReply_.readDescribeOutput(preparedStatement_);
216     }
217 }
218
Popular Tags