1 | /* |
2 | |
3 | Derby - Class org.apache.derby.impl.jdbc.EmbedPreparedStatement20 |
4 | |
5 | Copyright 1998, 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.impl.jdbc; |
22 | |
23 | import org.apache.derby.impl.jdbc.EmbedConnection; |
24 | import org.apache.derby.impl.jdbc.Util; |
25 | |
26 | import org.apache.derby.iapi.sql.ResultSet; |
27 | import org.apache.derby.iapi.error.StandardException; |
28 | |
29 | import org.apache.derby.iapi.reference.SQLState; |
30 | |
31 | import java.io.InputStream; |
32 | |
33 | import java.math.BigDecimal; |
34 | |
35 | import java.sql.SQLException; |
36 | import java.sql.SQLWarning; |
37 | import java.sql.Date; |
38 | import java.sql.Time; |
39 | import java.sql.Timestamp; |
40 | |
41 | |
42 | /* ---- New jdbc 2.0 types ----- */ |
43 | import java.sql.Array; |
44 | import java.sql.Blob; |
45 | import java.sql.Clob; |
46 | import java.sql.Ref; |
47 | import java.sql.Types; |
48 | |
49 | /** |
50 | * This class extends the EmbedPreparedStatement class in order to support new |
51 | * methods and classes that come with JDBC 2.0. |
52 | <P><B>Supports</B> |
53 | <UL> |
54 | <LI> JDBC 2.0 |
55 | </UL> |
56 | * @see org.apache.derby.impl.jdbc.EmbedPreparedStatement |
57 | * |
58 | * @author francois |
59 | */ |
60 | public class EmbedPreparedStatement20 |
61 | extends org.apache.derby.impl.jdbc.EmbedPreparedStatement { |
62 | |
63 | ////////////////////////////////////////////////////////////// |
64 | // |
65 | // CONSTRUCTORS |
66 | // |
67 | ////////////////////////////////////////////////////////////// |
68 | /* |
69 | Constructor assumes caller will setup context stack |
70 | and restore it. |
71 | @exception SQLException on error |
72 | */ |
73 | public EmbedPreparedStatement20 (EmbedConnection conn, String sql, boolean forMetaData, |
74 | int resultSetType, |
75 | int resultSetConcurrency, |
76 | int resultSetHoldability, |
77 | int autoGeneratedKeys, |
78 | int[] columnIndexes, |
79 | String[] columnNames) |
80 | throws SQLException { |
81 | |
82 | super(conn, sql, forMetaData, resultSetType, resultSetConcurrency, resultSetHoldability, |
83 | autoGeneratedKeys, columnIndexes, columnNames); |
84 | } |
85 | |
86 | /** |
87 | * JDBC 2.0 |
88 | * |
89 | * Set a REF(<structured-type>) parameter. |
90 | * |
91 | * @param i the first parameter is 1, the second is 2, ... |
92 | * @param x an object representing data of an SQL REF Type |
93 | * @exception SQLException Feature not implemented for now. |
94 | */ |
95 | public void setRef (int i, Ref x) throws SQLException { |
96 | throw Util.notImplemented(); |
97 | } |
98 | |
99 | |
100 | |
101 | |
102 | /** |
103 | * JDBC 2.0 |
104 | * |
105 | * Set an Array parameter. |
106 | * |
107 | * @param i the first parameter is 1, the second is 2, ... |
108 | * @param x an object representing an SQL array |
109 | * @exception SQLException Feature not implemented for now. |
110 | */ |
111 | public void setArray (int i, Array x) throws SQLException { |
112 | throw Util.notImplemented(); |
113 | } |
114 | |
115 | /* |
116 | ** Methods using BigDecimal, moved out of EmbedPreparedStatement |
117 | ** to allow that class to support JSR169. |
118 | */ |
119 | /** |
120 | * Set a parameter to a java.lang.BigDecimal value. |
121 | * The driver converts this to a SQL NUMERIC value when |
122 | * it sends it to the database. |
123 | * |
124 | * @param parameterIndex the first parameter is 1, the second is 2, ... |
125 | * @param x the parameter value |
126 | * @exception SQLException thrown on failure. |
127 | */ |
128 | public final void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException { |
129 | checkStatus(); |
130 | try { |
131 | /* JDBC is one-based, DBMS is zero-based */ |
132 | getParms().getParameterForSet(parameterIndex - 1).setBigDecimal(x); |
133 | |
134 | } catch (Throwable t) { |
135 | throw EmbedResultSet.noStateChangeException(t); |
136 | } |
137 | } |
138 | |
139 | /** |
140 | Allow explict setObject conversions by sub-classes for classes |
141 | not supported by this variant. In this case handle BigDecimal. |
142 | @return true if the object was set successfully, false if no valid |
143 | conversion exists. |
144 | |
145 | @exception SQLException value could not be set. |
146 | */ |
147 | boolean setObjectConvert(int parameterIndex, Object x) throws SQLException |
148 | { |
149 | if (x instanceof BigDecimal) { |
150 | setBigDecimal(parameterIndex, (BigDecimal) x); |
151 | return true; |
152 | } |
153 | return false; |
154 | } |
155 | } |
156 | |