1 | /* |
2 | |
3 | Derby - Class org.apache.derby.iapi.jdbc.BrokeredPreparedStatement30 |
4 | |
5 | Copyright 2003, 2004 The Apache Software Foundation or its licensors, as 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 | |
21 | package org.apache.derby.iapi.jdbc; |
22 | |
23 | import java.sql.*; |
24 | import java.net.URL; |
25 | |
26 | /** |
27 | JDBC 3 implementation of PreparedStatement. |
28 | */ |
29 | public class BrokeredPreparedStatement30 extends BrokeredPreparedStatement { |
30 | |
31 | private final Object generatedKeys; |
32 | public BrokeredPreparedStatement30(BrokeredStatementControl control, int jdbcLevel, String sql, Object generatedKeys) throws SQLException { |
33 | super(control, jdbcLevel, sql); |
34 | this.generatedKeys = generatedKeys; |
35 | } |
36 | |
37 | public final void setURL(int i, URL x) |
38 | throws SQLException |
39 | { |
40 | getPreparedStatement().setURL( i, x); |
41 | } |
42 | public final ParameterMetaData getParameterMetaData() |
43 | throws SQLException |
44 | { |
45 | return getPreparedStatement().getParameterMetaData(); |
46 | } |
47 | /** |
48 | Create a duplicate PreparedStatement to this, including state, from the passed in Connection. |
49 | */ |
50 | public PreparedStatement createDuplicateStatement(Connection conn, PreparedStatement oldStatement) throws SQLException { |
51 | |
52 | PreparedStatement newStatement; |
53 | |
54 | if (generatedKeys == null) |
55 | newStatement = conn.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability); |
56 | else { |
57 | // The prepareStatement() calls that take a generated key value do not take resultSet* type |
58 | // parameters, but since they don't return ResultSets that is OK. There are only for INSERT statements. |
59 | if (generatedKeys instanceof Integer) |
60 | newStatement = conn.prepareStatement(sql, ((Integer) generatedKeys).intValue()); |
61 | else if (generatedKeys instanceof int[]) |
62 | newStatement = conn.prepareStatement(sql, (int[]) generatedKeys); |
63 | else |
64 | newStatement = conn.prepareStatement(sql, (String[]) generatedKeys); |
65 | } |
66 | |
67 | |
68 | setStatementState(oldStatement, newStatement); |
69 | |
70 | return newStatement; |
71 | } |
72 | } |