01: /*
02:
03: Derby - Class org.apache.derby.iapi.jdbc.BrokeredPreparedStatement30
04:
05: Licensed to the Apache Software Foundation (ASF) under one or more
06: contributor license agreements. See the NOTICE file distributed with
07: this work for additional information regarding copyright ownership.
08: The ASF licenses this file to you under the Apache License, Version 2.0
09: (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:
22: package org.apache.derby.iapi.jdbc;
23:
24: import java.sql.*;
25: import java.net.URL;
26:
27: /**
28: JDBC 3 implementation of PreparedStatement.
29: */
30: public class BrokeredPreparedStatement30 extends
31: BrokeredPreparedStatement {
32:
33: private final Object generatedKeys;
34:
35: public BrokeredPreparedStatement30(
36: BrokeredStatementControl control, int jdbcLevel,
37: String sql, Object generatedKeys) throws SQLException {
38: super (control, jdbcLevel, sql);
39: this .generatedKeys = generatedKeys;
40: }
41:
42: public final void setURL(int i, URL x) throws SQLException {
43: getPreparedStatement().setURL(i, x);
44: }
45:
46: public final ParameterMetaData getParameterMetaData()
47: throws SQLException {
48: return getPreparedStatement().getParameterMetaData();
49: }
50:
51: /**
52: Create a duplicate PreparedStatement to this, including state, from the passed in Connection.
53: */
54: public PreparedStatement createDuplicateStatement(Connection conn,
55: PreparedStatement oldStatement) throws SQLException {
56:
57: PreparedStatement newStatement;
58:
59: if (generatedKeys == null)
60: newStatement = conn.prepareStatement(sql, resultSetType,
61: resultSetConcurrency, resultSetHoldability);
62: else {
63: // The prepareStatement() calls that take a generated key value do not take resultSet* type
64: // parameters, but since they don't return ResultSets that is OK. There are only for INSERT statements.
65: if (generatedKeys instanceof Integer)
66: newStatement = conn.prepareStatement(sql,
67: ((Integer) generatedKeys).intValue());
68: else if (generatedKeys instanceof int[])
69: newStatement = conn.prepareStatement(sql,
70: (int[]) generatedKeys);
71: else
72: newStatement = conn.prepareStatement(sql,
73: (String[]) generatedKeys);
74: }
75:
76: setStatementState(oldStatement, newStatement);
77:
78: return newStatement;
79: }
80: }
|