1 | /* |
2 | |
3 | Derby - Class org.apache.derby.impl.jdbc.EmbedResultSet20 |
4 | |
5 | Copyright 1998, 2005 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.iapi.reference.JDBC20Translation; |
24 | import org.apache.derby.iapi.reference.SQLState; |
25 | |
26 | import org.apache.derby.iapi.sql.ResultSet; |
27 | |
28 | import org.apache.derby.iapi.sql.execute.ExecCursorTableReference; |
29 | |
30 | import org.apache.derby.iapi.error.StandardException; |
31 | import org.apache.derby.impl.jdbc.Util; |
32 | import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; |
33 | import org.apache.derby.iapi.sql.conn.StatementContext; |
34 | |
35 | import org.apache.derby.iapi.types.DataValueDescriptor; |
36 | |
37 | import java.sql.Statement; |
38 | import java.sql.SQLException; |
39 | import java.sql.Types; |
40 | |
41 | /* ---- New jdbc 2.0 types ----- */ |
42 | import java.sql.Array; |
43 | import java.sql.Blob; |
44 | import java.sql.Clob; |
45 | import java.sql.Ref; |
46 | |
47 | import java.math.BigDecimal; |
48 | import java.net.URL; |
49 | |
50 | /** |
51 | * This class extends the EmbedResultSet class in order to support new |
52 | * methods and classes that come with JDBC 2.0. |
53 | <P><B>Supports</B> |
54 | <UL> |
55 | <LI> JDBC 2.0/2.1 |
56 | <LI> JDBC 3.0 |
57 | </UL> |
58 | * @see org.apache.derby.impl.jdbc.EmbedResultSet |
59 | * |
60 | * @author francois |
61 | */ |
62 | |
63 | public class EmbedResultSet20 |
64 | extends org.apache.derby.impl.jdbc.EmbedResultSet { |
65 | |
66 | ////////////////////////////////////////////////////////////// |
67 | // |
68 | // CONSTRUCTORS |
69 | // |
70 | ////////////////////////////////////////////////////////////// |
71 | |
72 | /** |
73 | * This class provides the glue between the Derby |
74 | * resultset and the JDBC resultset, mapping calls-to-calls. |
75 | */ |
76 | public EmbedResultSet20(org.apache.derby.impl.jdbc.EmbedConnection conn, |
77 | ResultSet resultsToWrap, |
78 | boolean forMetaData, |
79 | org.apache.derby.impl.jdbc.EmbedStatement stmt, |
80 | boolean isAtomic) |
81 | throws SQLException { |
82 | super(conn, resultsToWrap, forMetaData, stmt, isAtomic); |
83 | } |
84 | |
85 | |
86 | /* |
87 | ** Methods using java.math.BigDecimal, not supported in JSR169 |
88 | */ |
89 | /** |
90 | * Get the value of a column in the current row as a java.lang.BigDecimal object. |
91 | * |
92 | * @param columnIndex the first column is 1, the second is 2, ... |
93 | * @param scale the number of digits to the right of the decimal |
94 | * @return the column value; if the value is SQL NULL, the result is null |
95 | * @exception SQLException thrown on failure. |
96 | */ |
97 | public final BigDecimal getBigDecimal(int columnIndex, int scale) |
98 | throws SQLException { |
99 | |
100 | BigDecimal ret = getBigDecimal(columnIndex); |
101 | if (ret != null) { |
102 | return ret.setScale(scale, BigDecimal.ROUND_HALF_DOWN); |
103 | } |
104 | return null; |
105 | } |
106 | |
107 | public final BigDecimal getBigDecimal(int columnIndex) |
108 | throws SQLException { |
109 | checkIfClosed("getBigDecimal"); |
110 | try { |
111 | |
112 | DataValueDescriptor dvd = getColumn(columnIndex); |
113 | |
114 | if (wasNull = dvd.isNull()) |
115 | return null; |
116 | |
117 | return org.apache.derby.iapi.types.SQLDecimal.getBigDecimal(dvd); |
118 | |
119 | } catch (StandardException t) { |
120 | throw noStateChangeException(t); |
121 | } |
122 | } |
123 | |
124 | /** |
125 | * Get the value of a column in the current row as a java.lang.BigDecimal object. |
126 | * |
127 | * @param columnName is the SQL name of the column |
128 | * @param scale the number of digits to the right of the decimal |
129 | * @return the column value; if the value is SQL NULL, the result is null |
130 | * @exception SQLException thrown on failure. |
131 | */ |
132 | public final BigDecimal getBigDecimal(String columnName, int scale) |
133 | throws SQLException { |
134 | checkIfClosed("getBigDecimal"); |
135 | return (getBigDecimal(findColumnName(columnName), scale)); |
136 | } |
137 | |
138 | |
139 | /** |
140 | * JDBC 2.0 |
141 | * |
142 | Deprecated in JDBC 2.0, not supported by JCC. |
143 | * @exception SQLException thrown on failure. |
144 | */ |
145 | public final java.io.InputStream getUnicodeStream(int columnIndex) throws SQLException { |
146 | throw Util.notImplemented("getUnicodeStream"); |
147 | } |
148 | /** |
149 | Deprecated in JDBC 2.0, not supported by JCC. |
150 | * @exception SQLException thrown on failure. |
151 | */ |
152 | public final java.io.InputStream getUnicodeStream(String columnName) throws SQLException { |
153 | throw Util.notImplemented("getUnicodeStream"); |
154 | } |
155 | |
156 | /** |
157 | * JDBC 2.0 |
158 | * |
159 | * Get the value of a column in the current row as a java.math.BigDecimal |
160 | * object. |
161 | * |
162 | * @exception SQLException Feature not implemented for now. |
163 | */ |
164 | public final BigDecimal getBigDecimal(String columnName) throws SQLException { |
165 | checkIfClosed("getBigDecimal"); |
166 | return getBigDecimal(findColumnName(columnName)); |
167 | } |
168 | |
169 | public void updateBigDecimal(int columnIndex, BigDecimal x) |
170 | throws SQLException { |
171 | try { |
172 | getDVDforColumnToBeUpdated(columnIndex, "updateBigDecimal").setBigDecimal(x); |
173 | } catch (StandardException t) { |
174 | throw noStateChangeException(t); |
175 | } |
176 | } |
177 | |
178 | /** |
179 | * JDBC 2.0 |
180 | * |
181 | * Update a column with an Object value. |
182 | * |
183 | * The updateXXX() methods are used to update column values in the current |
184 | * row, or the insert row. The updateXXX() methods do not update the |
185 | * underlying database, instead the updateRow() or insertRow() methods are |
186 | * called to update the database. |
187 | * |
188 | * @param columnIndex |
189 | * the first column is 1, the second is 2, ... |
190 | * @param x |
191 | * the new column value |
192 | * @exception SQLException |
193 | * if a database-access error occurs |
194 | */ |
195 | public void updateObject(int columnIndex, Object x) throws SQLException { |
196 | //If the Object x is the right datatype, this method will eventually call getDVDforColumnToBeUpdated which will check for |
197 | //the read only resultset. But for other datatypes of x, we want to catch if this updateObject is being |
198 | //issued against a read only resultset. And that is the reason for call to checksBeforeUpdateOrDelete here. |
199 | checksBeforeUpdateOrDelete("updateObject", columnIndex); |
200 | int colType = getColumnType(columnIndex); |
201 | |
202 | if (x instanceof BigDecimal) { |
203 | updateBigDecimal(columnIndex, (BigDecimal) x); |
204 | return; |
205 | } |
206 | super.updateObject(columnIndex, x); |
207 | } |
208 | |
209 | /** |
210 | * JDBC 2.0 |
211 | * |
212 | * Update a column with a BigDecimal value. |
213 | * |
214 | * The updateXXX() methods are used to update column values in the |
215 | * current row, or the insert row. The updateXXX() methods do not |
216 | * update the underlying database, instead the updateRow() or insertRow() |
217 | * methods are called to update the database. |
218 | * |
219 | * @param columnName the name of the column |
220 | * @param x the new column value |
221 | * @exception SQLException if a database-access error occurs |
222 | */ |
223 | public void updateBigDecimal(String columnName, BigDecimal x) |
224 | throws SQLException { |
225 | checkIfClosed("updateBigDecimal"); |
226 | updateBigDecimal(findColumnName(columnName), x); |
227 | } |
228 | |
229 | /** |
230 | * JDBC 2.0 |
231 | * |
232 | * Returns the value of column @i as a Java object. Use the |
233 | * param map to determine the class from which to construct data of |
234 | * SQL structured and distinct types. |
235 | * |
236 | * @param columnIndex the first column is 1, the second is 2, ... |
237 | * @param map the mapping from SQL type names to Java classes |
238 | * @return an object representing the SQL value |
239 | * @exception SQLException Feature not implemented for now. |
240 | */ |
241 | public Object getObject(int columnIndex, java.util.Map map) throws SQLException { |
242 | checkIfClosed("getObject"); |
243 | if( map == null) |
244 | throw Util.generateCsSQLException(SQLState.INVALID_API_PARAMETER,map,"map", |
245 | "java.sql.ResultSet.getObject"); |
246 | if(!(map.isEmpty())) |
247 | throw Util.notImplemented(); |
248 | // Map is empty call the normal getObject method. |
249 | return getObject(columnIndex); |
250 | } |
251 | |
252 | /** |
253 | * JDBC 2.0 |
254 | * |
255 | * Get a REF(<structured-type>) column. |
256 | * |
257 | * @param i the first column is 1, the second is 2, ... |
258 | * @return an object representing data of an SQL REF type |
259 | * @exception SQLException Feature not implemented for now. |
260 | */ |
261 | public Ref getRef(int i) throws SQLException { |
262 | throw Util.notImplemented(); |
263 | } |
264 | |
265 | /** |
266 | * JDBC 2.0 |
267 | * |
268 | * Get an array column. |
269 | * |
270 | * @param i the first column is 1, the second is 2, ... |
271 | * @return an object representing an SQL array |
272 | * @exception SQLException Feature not implemented for now. |
273 | */ |
274 | public Array getArray(int i) throws SQLException { |
275 | throw Util.notImplemented(); |
276 | } |
277 | |
278 | /** |
279 | * JDBC 2.0 |
280 | * |
281 | * Returns the value of column @i as a Java object. Use the |
282 | * param map to determine the class from which to construct data of |
283 | * SQL structured and distinct types. |
284 | * |
285 | * @param colName the column name |
286 | * @param map the mapping from SQL type names to Java classes |
287 | * @return an object representing the SQL value |
288 | * @exception SQLException Feature not implemented for now. |
289 | */ |
290 | public Object getObject(String colName, java.util.Map map) |
291 | throws SQLException { |
292 | checkIfClosed("getObject"); |
293 | return getObject(findColumn(colName),map); |
294 | } |
295 | |
296 | /** |
297 | * JDBC 2.0 |
298 | * |
299 | * Get a REF(<structured-type>) column. |
300 | * |
301 | * @param colName the column name |
302 | * @return an object representing data of an SQL REF type |
303 | * @exception SQLException Feature not implemented for now. |
304 | */ |
305 | public Ref getRef(String colName) throws SQLException { |
306 | throw Util.notImplemented(); |
307 | } |
308 | |
309 | |
310 | |
311 | |
312 | /** |
313 | * JDBC 2.0 |
314 | * |
315 | * Get an array column. |
316 | * |
317 | * @param colName the column name |
318 | * @return an object representing an SQL array |
319 | * @exception SQLException Feature not implemented for now. |
320 | */ |
321 | public Array getArray(String colName) throws SQLException { |
322 | throw Util.notImplemented(); |
323 | } |
324 | |
325 | |
326 | /** |
327 | Following methods are for the new JDBC 3.0 methods in java.sql.ResultSet |
328 | (see the JDBC 3.0 spec). We have the JDBC 3.0 methods in Local20 |
329 | package, so we don't have to have a new class in Local30. |
330 | The new JDBC 3.0 methods don't make use of any new JDBC3.0 classes and |
331 | so this will work fine in jdbc2.0 configuration. |
332 | */ |
333 | |
334 | ///////////////////////////////////////////////////////////////////////// |
335 | // |
336 | // JDBC 3.0 - New public methods |
337 | // |
338 | ///////////////////////////////////////////////////////////////////////// |
339 | |
340 | |
341 | |
342 | /** |
343 | * JDBC 3.0 |
344 | * |
345 | * Updates the designated column with a java.sql.Ref value. The updater methods are |
346 | * used to update column values in the current row or the insert row. The |
347 | * updater methods do not update the underlying database; instead the updateRow |
348 | * or insertRow methods are called to update the database. |
349 | * |
350 | * @param columnIndex - the first column is 1, the second is 2 |
351 | * @param x - the new column value |
352 | * @exception SQLException Feature not implemented for now. |
353 | */ |
354 | public void updateRef(int columnIndex, Ref x) |
355 | throws SQLException |
356 | { |
357 | throw Util.notImplemented(); |
358 | } |
359 | |
360 | /** |
361 | * JDBC 3.0 |
362 | * |
363 | * Updates the designated column with a java.sql.Ref value. The updater methods are |
364 | * used to update column values in the current row or the insert row. The |
365 | * updater methods do not update the underlying database; instead the updateRow |
366 | * or insertRow methods are called to update the database. |
367 | * |
368 | * @param columnName - the SQL name of the column |
369 | * @param x - the new column value |
370 | * @exception SQLException Feature not implemented for now. |
371 | */ |
372 | public void updateRef(String columnName, Ref x) |
373 | throws SQLException |
374 | { |
375 | throw Util.notImplemented(); |
376 | } |
377 | |
378 | /** |
379 | * JDBC 3.0 |
380 | * |
381 | * Updates the designated column with a java.sql.Array value. The updater methods are |
382 | * used to update column values in the current row or the insert row. The |
383 | * updater methods do not update the underlying database; instead the updateRow |
384 | * or insertRow methods are called to update the database. |
385 | * |
386 | * @param columnIndex - the first column is 1, the second is 2 |
387 | * @param x - the new column value |
388 | * @exception SQLException Feature not implemented for now. |
389 | */ |
390 | public void updateArray(int columnIndex, Array x) |
391 | throws SQLException |
392 | { |
393 | throw Util.notImplemented(); |
394 | } |
395 | |
396 | /** |
397 | * JDBC 3.0 |
398 | * |
399 | * Updates the designated column with a java.sql.Array value. The updater methods are |
400 | * used to update column values in the current row or the insert row. The |
401 | * updater methods do not update the underlying database; instead the updateRow |
402 | * or insertRow methods are called to update the database. |
403 | * |
404 | * @param columnName - the SQL name of the column |
405 | * @param x - the new column value |
406 | * @exception SQLException Feature not implemented for now. |
407 | */ |
408 | public void updateArray(String columnName, Array x) |
409 | throws SQLException |
410 | { |
411 | throw Util.notImplemented(); |
412 | } |
413 | |
414 | |
415 | |
416 | |
417 | } |