KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > jdbc > EmbedResultSet20


1 /*
2
3    Derby - Class org.apache.derby.impl.jdbc.EmbedResultSet20
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (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.impl.jdbc;
23
24 import org.apache.derby.iapi.reference.JDBC20Translation;
25 import org.apache.derby.iapi.reference.SQLState;
26
27 import org.apache.derby.iapi.sql.ResultSet;
28
29 import org.apache.derby.iapi.sql.execute.ExecCursorTableReference;
30
31 import org.apache.derby.iapi.error.StandardException;
32 import org.apache.derby.impl.jdbc.Util;
33 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
34 import org.apache.derby.iapi.sql.conn.StatementContext;
35                                          
36 import org.apache.derby.iapi.types.DataValueDescriptor;
37
38 import java.sql.Statement JavaDoc;
39 import java.sql.SQLException JavaDoc;
40 import java.sql.Types JavaDoc;
41
42 /* ---- New jdbc 2.0 types ----- */
43 import java.sql.Array JavaDoc;
44 import java.sql.Blob JavaDoc;
45 import java.sql.Clob JavaDoc;
46 import java.sql.Ref JavaDoc;
47
48 import java.math.BigDecimal JavaDoc;
49 import java.net.URL JavaDoc;
50
51 /**
52  * This class extends the EmbedResultSet class in order to support new
53  * methods and classes that come with JDBC 2.0.
54      <P><B>Supports</B>
55    <UL>
56    <LI> JDBC 2.0/2.1
57    <LI> JDBC 3.0
58    </UL>
59  * @see org.apache.derby.impl.jdbc.EmbedResultSet
60  *
61  * @author francois
62  */

63
64 public class EmbedResultSet20
65         extends org.apache.derby.impl.jdbc.EmbedResultSet {
66
67         //////////////////////////////////////////////////////////////
68
//
69
// CONSTRUCTORS
70
//
71
//////////////////////////////////////////////////////////////
72

73         /**
74          * This class provides the glue between the Derby
75          * resultset and the JDBC resultset, mapping calls-to-calls.
76          */

77         public EmbedResultSet20(org.apache.derby.impl.jdbc.EmbedConnection conn,
78                                                          ResultSet resultsToWrap,
79                                                          boolean forMetaData,
80                                                          org.apache.derby.impl.jdbc.EmbedStatement stmt,
81                                                          boolean isAtomic)
82         throws SQLException JavaDoc {
83                 super(conn, resultsToWrap, forMetaData, stmt, isAtomic);
84         }
85
86
87         /*
88         ** Methods using java.math.BigDecimal, not supported in JSR169
89         */

90         /**
91          * Get the value of a column in the current row as a java.lang.BigDecimal object.
92          *
93          * @param columnIndex the first column is 1, the second is 2, ...
94          * @param scale the number of digits to the right of the decimal
95          * @return the column value; if the value is SQL NULL, the result is null
96          * @exception SQLException thrown on failure.
97          */

98         public final BigDecimal JavaDoc getBigDecimal(int columnIndex, int scale)
99             throws SQLException JavaDoc {
100
101             BigDecimal JavaDoc ret = getBigDecimal(columnIndex);
102             if (ret != null) {
103                 return ret.setScale(scale, BigDecimal.ROUND_HALF_DOWN);
104             }
105             return null;
106         }
107
108         public final BigDecimal JavaDoc getBigDecimal(int columnIndex)
109             throws SQLException JavaDoc {
110             checkIfClosed("getBigDecimal");
111             try {
112
113                 DataValueDescriptor dvd = getColumn(columnIndex);
114
115                 if (wasNull = dvd.isNull())
116                     return null;
117                 
118                 return org.apache.derby.iapi.types.SQLDecimal.getBigDecimal(dvd);
119
120             } catch (StandardException t) {
121                 throw noStateChangeException(t);
122             }
123         }
124
125         /**
126          * Get the value of a column in the current row as a java.lang.BigDecimal object.
127          *
128          * @param columnName is the SQL name of the column
129          * @param scale the number of digits to the right of the decimal
130          * @return the column value; if the value is SQL NULL, the result is null
131          * @exception SQLException thrown on failure.
132          */

133         public final BigDecimal JavaDoc getBigDecimal(String JavaDoc columnName, int scale)
134             throws SQLException JavaDoc {
135             checkIfClosed("getBigDecimal");
136             return (getBigDecimal(findColumnName(columnName), scale));
137         }
138
139
140     /**
141      * JDBC 2.0
142      *
143         Deprecated in JDBC 2.0, not supported by JCC.
144      * @exception SQLException thrown on failure.
145      */

146     public final java.io.InputStream JavaDoc getUnicodeStream(int columnIndex) throws SQLException JavaDoc {
147         throw Util.notImplemented("getUnicodeStream");
148     }
149     /**
150         Deprecated in JDBC 2.0, not supported by JCC.
151      * @exception SQLException thrown on failure.
152      */

153     public final java.io.InputStream JavaDoc getUnicodeStream(String JavaDoc columnName) throws SQLException JavaDoc {
154         throw Util.notImplemented("getUnicodeStream");
155     }
156     
157     /**
158      * JDBC 2.0
159      *
160      * Get the value of a column in the current row as a java.math.BigDecimal
161      * object.
162      *
163          * @exception SQLException Feature not implemented for now.
164      */

165     public final BigDecimal JavaDoc getBigDecimal(String JavaDoc columnName) throws SQLException JavaDoc {
166         checkIfClosed("getBigDecimal");
167         return getBigDecimal(findColumnName(columnName));
168     }
169
170     public void updateBigDecimal(int columnIndex, BigDecimal JavaDoc x)
171     throws SQLException JavaDoc {
172         try {
173             getDVDforColumnToBeUpdated(columnIndex, "updateBigDecimal").setBigDecimal(x);
174         } catch (StandardException t) {
175             throw noStateChangeException(t);
176         }
177     }
178
179     /**
180      * JDBC 2.0
181      *
182      * Update a column with an Object value.
183      *
184      * The updateXXX() methods are used to update column values in the current
185      * row, or the insert row. The updateXXX() methods do not update the
186      * underlying database, instead the updateRow() or insertRow() methods are
187      * called to update the database.
188      *
189      * @param columnIndex
190      * the first column is 1, the second is 2, ...
191      * @param x
192      * the new column value
193      * @exception SQLException
194      * if a database-access error occurs
195      */

196     public void updateObject(int columnIndex, Object JavaDoc x) throws SQLException JavaDoc {
197         //If the Object x is the right datatype, this method will eventually call getDVDforColumnToBeUpdated which will check for
198
//the read only resultset. But for other datatypes of x, we want to catch if this updateObject is being
199
//issued against a read only resultset. And that is the reason for call to checksBeforeUpdateOrDelete here.
200
checksBeforeUpdateOrDelete("updateObject", columnIndex);
201         int colType = getColumnType(columnIndex);
202
203         if (x instanceof BigDecimal JavaDoc) {
204             updateBigDecimal(columnIndex, (BigDecimal JavaDoc) x);
205             return;
206         }
207         super.updateObject(columnIndex, x);
208     }
209
210     /**
211      * JDBC 2.0
212      *
213      * Update a column with a BigDecimal value.
214      *
215      * The updateXXX() methods are used to update column values in the
216      * current row, or the insert row. The updateXXX() methods do not
217      * update the underlying database, instead the updateRow() or insertRow()
218      * methods are called to update the database.
219      *
220      * @param columnName the name of the column
221      * @param x the new column value
222      * @exception SQLException if a database-access error occurs
223      */

224     public void updateBigDecimal(String JavaDoc columnName, BigDecimal JavaDoc x)
225     throws SQLException JavaDoc {
226             checkIfClosed("updateBigDecimal");
227             updateBigDecimal(findColumnName(columnName), x);
228         }
229
230     /**
231      * JDBC 2.0
232      *
233      * Returns the value of column @i as a Java object. Use the
234      * param map to determine the class from which to construct data of
235      * SQL structured and distinct types.
236      *
237      * @param columnIndex the first column is 1, the second is 2, ...
238      * @param map the mapping from SQL type names to Java classes
239      * @return an object representing the SQL value
240          * @exception SQLException Feature not implemented for now.
241      */

242     public Object JavaDoc getObject(int columnIndex, java.util.Map JavaDoc map) throws SQLException JavaDoc {
243         checkIfClosed("getObject");
244         if( map == null)
245             throw Util.generateCsSQLException(SQLState.INVALID_API_PARAMETER,map,"map",
246                                               "java.sql.ResultSet.getObject");
247         if(!(map.isEmpty()))
248             throw Util.notImplemented();
249         // Map is empty call the normal getObject method.
250
return getObject(columnIndex);
251         }
252
253     /**
254      * JDBC 2.0
255      *
256      * Get a REF(&lt;structured-type&gt;) column.
257      *
258      * @param i the first column is 1, the second is 2, ...
259      * @return an object representing data of an SQL REF type
260          * @exception SQLException Feature not implemented for now.
261      */

262     public Ref JavaDoc getRef(int i) throws SQLException JavaDoc {
263                 throw Util.notImplemented();
264         }
265
266     /**
267      * JDBC 2.0
268      *
269      * Get an array column.
270      *
271      * @param i the first column is 1, the second is 2, ...
272      * @return an object representing an SQL array
273          * @exception SQLException Feature not implemented for now.
274      */

275     public Array JavaDoc getArray(int i) throws SQLException JavaDoc {
276                 throw Util.notImplemented();
277         }
278
279     /**
280      * JDBC 2.0
281      *
282      * Returns the value of column @i as a Java object. Use the
283      * param map to determine the class from which to construct data of
284      * SQL structured and distinct types.
285      *
286      * @param colName the column name
287      * @param map the mapping from SQL type names to Java classes
288      * @return an object representing the SQL value
289          * @exception SQLException Feature not implemented for now.
290      */

291     public Object JavaDoc getObject(String JavaDoc colName, java.util.Map JavaDoc map)
292     throws SQLException JavaDoc {
293         checkIfClosed("getObject");
294         return getObject(findColumn(colName),map);
295         }
296
297     /**
298      * JDBC 2.0
299      *
300      * Get a REF(&lt;structured-type&gt;) column.
301      *
302      * @param colName the column name
303      * @return an object representing data of an SQL REF type
304          * @exception SQLException Feature not implemented for now.
305      */

306     public Ref JavaDoc getRef(String JavaDoc colName) throws SQLException JavaDoc {
307                 throw Util.notImplemented();
308         }
309
310
311
312
313     /**
314      * JDBC 2.0
315      *
316      * Get an array column.
317      *
318      * @param colName the column name
319      * @return an object representing an SQL array
320          * @exception SQLException Feature not implemented for now.
321      */

322     public Array JavaDoc getArray(String JavaDoc colName) throws SQLException JavaDoc {
323                 throw Util.notImplemented();
324         }
325
326
327         /**
328     Following methods are for the new JDBC 3.0 methods in java.sql.ResultSet
329     (see the JDBC 3.0 spec). We have the JDBC 3.0 methods in Local20
330     package, so we don't have to have a new class in Local30.
331     The new JDBC 3.0 methods don't make use of any new JDBC3.0 classes and
332     so this will work fine in jdbc2.0 configuration.
333         */

334
335         /////////////////////////////////////////////////////////////////////////
336
//
337
// JDBC 3.0 - New public methods
338
//
339
/////////////////////////////////////////////////////////////////////////
340

341
342
343         /**
344     * JDBC 3.0
345     *
346     * Updates the designated column with a java.sql.Ref value. The updater methods are
347     * used to update column values in the current row or the insert row. The
348     * updater methods do not update the underlying database; instead the updateRow
349     * or insertRow methods are called to update the database.
350     *
351     * @param columnIndex - the first column is 1, the second is 2
352     * @param x - the new column value
353     * @exception SQLException Feature not implemented for now.
354         */

355         public void updateRef(int columnIndex, Ref JavaDoc x)
356     throws SQLException JavaDoc
357         {
358                 throw Util.notImplemented();
359         }
360
361         /**
362     * JDBC 3.0
363     *
364     * Updates the designated column with a java.sql.Ref value. The updater methods are
365     * used to update column values in the current row or the insert row. The
366     * updater methods do not update the underlying database; instead the updateRow
367     * or insertRow methods are called to update the database.
368     *
369     * @param columnName - the SQL name of the column
370     * @param x - the new column value
371     * @exception SQLException Feature not implemented for now.
372         */

373         public void updateRef(String JavaDoc columnName, Ref JavaDoc x)
374     throws SQLException JavaDoc
375         {
376                 throw Util.notImplemented();
377         }
378
379         /**
380     * JDBC 3.0
381     *
382     * Updates the designated column with a java.sql.Array value. The updater methods are
383     * used to update column values in the current row or the insert row. The
384     * updater methods do not update the underlying database; instead the updateRow
385     * or insertRow methods are called to update the database.
386     *
387     * @param columnIndex - the first column is 1, the second is 2
388     * @param x - the new column value
389     * @exception SQLException Feature not implemented for now.
390         */

391         public void updateArray(int columnIndex, Array JavaDoc x)
392     throws SQLException JavaDoc
393         {
394                 throw Util.notImplemented();
395         }
396
397         /**
398     * JDBC 3.0
399     *
400     * Updates the designated column with a java.sql.Array value. The updater methods are
401     * used to update column values in the current row or the insert row. The
402     * updater methods do not update the underlying database; instead the updateRow
403     * or insertRow methods are called to update the database.
404     *
405     * @param columnName - the SQL name of the column
406     * @param x - the new column value
407     * @exception SQLException Feature not implemented for now.
408         */

409         public void updateArray(String JavaDoc columnName, Array JavaDoc x)
410     throws SQLException JavaDoc
411         {
412                 throw Util.notImplemented();
413         }
414
415
416  
417
418 }
419
Popular Tags