001 /*
002 
003    Derby - Class org.apache.derby.client.net.NetPreparedStatement
004 
005    Copyright (c) 2001, 2005 The Apache Software Foundation or its licensors, where applicable.
006 
007    Licensed under the Apache License, Version 2.0 (the "License");
008    you may not use this file except in compliance with the License.
009    You may obtain a copy of the License at
010 
011       http://www.apache.org/licenses/LICENSE-2.0
012 
013    Unless required by applicable law or agreed to in writing, software
014    distributed under the License is distributed on an "AS IS" BASIS,
015    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016    See the License for the specific language governing permissions and
017    limitations under the License.
018 
019 */
020 package org.apache.derby.client.net;
021 
022 import org.apache.derby.client.am.ColumnMetaData;
023 import org.apache.derby.client.am.PreparedStatement;
024 import org.apache.derby.client.am.Section;
025 import org.apache.derby.client.am.SqlException;
026 
027 
028 public class NetPreparedStatement extends NetStatement
029         implements org.apache.derby.client.am.MaterialPreparedStatement {
030 
031     // Alias for (NetPreparedStatement) super.statement.
032     /*final*/
033     org.apache.derby.client.am.PreparedStatement preparedStatement_;
034 
035 
036     // Relay constructor for NetCallableStatement.
037     NetPreparedStatement(org.apache.derby.client.am.PreparedStatement statement,
038                          NetAgent netAgent,
039                          NetConnection netConnection) {
040         super(statement, netAgent, netConnection);
041         initNetPreparedStatement(statement);
042     }
043 
044     void resetNetPreparedStatement(org.apache.derby.client.am.PreparedStatement statement,
045                                    NetAgent netAgent,
046                                    NetConnection netConnection) {
047         super.resetNetStatement(statement, netAgent, netConnection);
048         initNetPreparedStatement(statement);
049     }
050 
051     private void initNetPreparedStatement(org.apache.derby.client.am.PreparedStatement statement) {
052         preparedStatement_ = statement;
053         preparedStatement_.materialPreparedStatement_ = this;
054     }
055 
056     // Called by abstract Connection.prepareStatment().newPreparedStatement() for jdbc 2 prepared statements
057     // with scroll attributes.
058     NetPreparedStatement(NetAgent netAgent, NetConnection netConnection, String sql, int type, int concurrency, int holdability, int autoGeneratedKeys, String[] columnNamesthrows SqlException {
059         this(new PreparedStatement(netAgent, netConnection, sql, type, concurrency, holdability, autoGeneratedKeys, columnNames),
060                 netAgent,
061                 netConnection);
062     }
063 
064     void resetNetPreparedStatement(NetAgent netAgent, NetConnection netConnection, String sql, int type, int concurrency, int holdability, int autoGeneratedKeys, String[] columnNamesthrows SqlException {
065         preparedStatement_.resetPreparedStatement(netAgent, netConnection, sql, type, concurrency, holdability, autoGeneratedKeys, columnNames);
066         resetNetPreparedStatement(preparedStatement_, netAgent, netConnection);
067     }
068 
069     // For JDBC 3.0 positioned updates.
070     NetPreparedStatement(NetAgent netAgent,
071                          NetConnection netConnection,
072                          String sql,
073                          Section sectionthrows SqlException {
074         this(new PreparedStatement(netAgent, netConnection, sql, section),
075                 netAgent,
076                 netConnection);
077     }
078 
079     void resetNetPreparedStatement(NetAgent netAgent,
080                                    NetConnection netConnection,
081                                    String sql,
082                                    Section sectionthrows SqlException {
083         preparedStatement_.resetPreparedStatement(netAgent, netConnection, sql, section);
084         resetNetPreparedStatement(preparedStatement_, netAgent, netConnection);
085     }
086 
087     void resetNetPreparedStatement(NetAgent netAgent,
088                                    NetConnection netConnection,
089                                    String sql,
090                                    Section section,
091                                    ColumnMetaData parameterMetaData,
092                                    ColumnMetaData resultSetMetaDatathrows SqlException {
093         preparedStatement_.resetPreparedStatement(netAgent, netConnection, sql, section, parameterMetaData, resultSetMetaData);
094         this.resetNetPreparedStatement(preparedStatement_, netAgent, netConnection);
095     }
096 
097     protected void finalize() throws java.lang.Throwable {
098         super.finalize();
099     }
100 
101     public void writeExecute_(Section section,
102                               ColumnMetaData parameterMetaData,
103                               Object[] inputs,
104                               int numInputColumns,
105                               boolean outputExpected,
106                               // This is a hint to the material layer that more write commands will follow.
107                               // It is ignored by the driver in all cases except when blob data is written,
108                               // in which case this boolean is used to optimize the implementation.
109                               // Otherwise we wouldn't be able to chain after blob data is sent.
110                               // If we could always chain a no-op DDM after every execute that writes blobs
111                               // then we could just always set the chaining flag to on for blob send data
112                               boolean chainedWritesFollowingSetLobthrows SqlException {
113         netAgent_.statementRequest_.writeExecute(this,
114                 section,
115                 parameterMetaData,
116                 inputs,
117                 numInputColumns,
118                 outputExpected,
119                 chainedWritesFollowingSetLob);
120     }
121 
122 
123     public void readExecute_() throws SqlException {
124         netAgent_.statementReply_.readExecute(preparedStatement_);
125     }
126 
127     public void writeOpenQuery_(Section section,
128                                 int fetchSize,
129                                 int resultSetType,
130                                 int numInputColumns,
131                                 ColumnMetaData parameterMetaData,
132                                 Object[] inputsthrows SqlException {
133         netAgent_.statementRequest_.writeOpenQuery(this,
134                 section,
135                 fetchSize,
136                 resultSetType,
137                 numInputColumns,
138                 parameterMetaData,
139                 inputs);
140     }
141     // super.readOpenQuery()
142 
143     public void writeDescribeInput_(Section sectionthrows SqlException {
144         netAgent_.statementRequest_.writeDescribeInput(this, section);
145     }
146 
147     public void readDescribeInput_() throws SqlException {
148         netAgent_.statementReply_.readDescribeInput(preparedStatement_);
149     }
150 
151     public void writeDescribeOutput_(Section sectionthrows SqlException {
152         netAgent_.statementRequest_.writeDescribeOutput(this, section);
153     }
154 
155     public void readDescribeOutput_() throws SqlException {
156         netAgent_.statementReply_.readDescribeOutput(preparedStatement_);
157     }
158 }