KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > jdbc > ResultSetWrapper


1 // $Id: ResultSetWrapper.java,v 1.7 2005/02/12 07:19:24 steveebersole Exp $
2
package org.hibernate.jdbc;
3
4 import java.io.InputStream JavaDoc;
5 import java.io.Reader JavaDoc;
6 import java.math.BigDecimal JavaDoc;
7 import java.net.URL JavaDoc;
8 import java.sql.Array JavaDoc;
9 import java.sql.Blob JavaDoc;
10 import java.sql.Clob JavaDoc;
11 import java.sql.Date JavaDoc;
12 import java.sql.Ref JavaDoc;
13 import java.sql.ResultSet JavaDoc;
14 import java.sql.ResultSetMetaData JavaDoc;
15 import java.sql.SQLException JavaDoc;
16 import java.sql.SQLWarning JavaDoc;
17 import java.sql.Statement JavaDoc;
18 import java.sql.Time JavaDoc;
19 import java.sql.Timestamp JavaDoc;
20 import java.util.Calendar JavaDoc;
21 import java.util.Map JavaDoc;
22
23 /**
24  * A ResultSet delegate, responsible for locally caching the columnName-to-columnIndex
25  * resolution that has been found to be inefficient in a few vendor's drivers (i.e., Oracle
26  * and Postgres).
27  *
28  * @author Steve Ebersole
29  */

30 public class ResultSetWrapper implements ResultSet JavaDoc {
31
32     private ResultSet JavaDoc rs;
33     private ColumnNameCache columnNameCache;
34
35     public ResultSetWrapper(ResultSet JavaDoc resultSet, ColumnNameCache columnNameCache) {
36         this.rs = resultSet;
37         this.columnNameCache = columnNameCache;
38     }
39
40     /*package*/ ResultSet JavaDoc getTarget() {
41         return rs;
42     }
43
44
45     // ResultSet impl ("overridden") ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
46

47     /**
48      * Overridden version to utilize local caching of the column indexes by name
49      * to improve performance for those drivers which are known to not support
50      * such caching by themselves.
51      * <p/>
52      * This implementation performs the caching based on the upper case version
53      * of the given column name.
54      *
55      * @param columnName The column name to resolve into an index.
56      * @return The column index corresponding to the given column name.
57      * @throws SQLException - if the ResultSet object does not contain
58      * columnName or a database access error occurs
59      */

60     public int findColumn(String JavaDoc columnName) throws SQLException JavaDoc {
61         return columnNameCache.getIndexForColumnName( columnName, this );
62     }
63
64     public Array JavaDoc getArray(String JavaDoc colName) throws SQLException JavaDoc {
65         return rs.getArray( findColumn(colName) );
66     }
67
68     public void updateArray(String JavaDoc columnName, Array JavaDoc x) throws SQLException JavaDoc {
69         rs.updateArray( findColumn(columnName), x );
70     }
71
72     public InputStream JavaDoc getAsciiStream(String JavaDoc columnName) throws SQLException JavaDoc {
73         return rs.getAsciiStream( findColumn(columnName) );
74     }
75
76     public void updateAsciiStream(String JavaDoc columnName, InputStream JavaDoc x, int length) throws SQLException JavaDoc {
77         rs.updateAsciiStream( findColumn(columnName), x, length );
78     }
79
80     public BigDecimal JavaDoc getBigDecimal(String JavaDoc columnName) throws SQLException JavaDoc {
81         return rs.getBigDecimal( findColumn(columnName) );
82     }
83
84     public BigDecimal JavaDoc getBigDecimal(String JavaDoc columnName, int scale) throws SQLException JavaDoc {
85         return rs.getBigDecimal( findColumn(columnName), scale );
86     }
87
88     public void updateBigDecimal(String JavaDoc columnName, BigDecimal JavaDoc x) throws SQLException JavaDoc {
89         rs.updateBigDecimal( findColumn(columnName), x );
90     }
91
92     public InputStream JavaDoc getBinaryStream(String JavaDoc columnName) throws SQLException JavaDoc {
93         return rs.getBinaryStream( findColumn(columnName) );
94     }
95
96     public void updateBinaryStream(String JavaDoc columnName, InputStream JavaDoc x, int length) throws SQLException JavaDoc {
97         rs.updateBinaryStream( findColumn(columnName), x, length );
98     }
99
100     public Blob JavaDoc getBlob(String JavaDoc columnName) throws SQLException JavaDoc {
101         return rs.getBlob( findColumn(columnName) );
102     }
103
104     public void updateBlob(String JavaDoc columnName, Blob JavaDoc x) throws SQLException JavaDoc {
105         rs.updateBlob( findColumn(columnName), x );
106     }
107
108     public boolean getBoolean(String JavaDoc columnName) throws SQLException JavaDoc {
109         return rs.getBoolean( findColumn(columnName) );
110     }
111
112     public void updateBoolean(String JavaDoc columnName, boolean x) throws SQLException JavaDoc {
113         rs.updateBoolean( findColumn(columnName), x );
114     }
115
116     public byte getByte(String JavaDoc columnName) throws SQLException JavaDoc {
117         return rs.getByte( findColumn(columnName) );
118     }
119
120     public void updateByte(String JavaDoc columnName, byte x) throws SQLException JavaDoc {
121         rs.updateByte( findColumn(columnName), x );
122     }
123
124     public byte[] getBytes(String JavaDoc columnName) throws SQLException JavaDoc {
125         return rs.getBytes( findColumn(columnName) );
126     }
127
128     public void updateBytes(String JavaDoc columnName, byte[] x) throws SQLException JavaDoc {
129         rs.updateBytes( findColumn(columnName), x );
130     }
131
132     public Reader JavaDoc getCharacterStream(String JavaDoc columnName) throws SQLException JavaDoc {
133         return rs.getCharacterStream( findColumn(columnName) );
134     }
135
136     public void updateCharacterStream(String JavaDoc columnName, Reader JavaDoc x, int length) throws SQLException JavaDoc {
137         rs.updateCharacterStream( findColumn(columnName), x, length );
138     }
139
140     public Clob JavaDoc getClob(String JavaDoc columnName) throws SQLException JavaDoc {
141         return rs.getClob( findColumn(columnName) );
142     }
143
144     public void updateClob(String JavaDoc columnName, Clob JavaDoc x) throws SQLException JavaDoc {
145         rs.updateClob( findColumn(columnName), x );
146     }
147
148     public Date JavaDoc getDate(String JavaDoc columnName) throws SQLException JavaDoc {
149         return rs.getDate( findColumn(columnName) );
150     }
151
152     public Date JavaDoc getDate(String JavaDoc columnName, Calendar JavaDoc cal) throws SQLException JavaDoc {
153         return rs.getDate( findColumn(columnName), cal );
154     }
155
156     public void updateDate(String JavaDoc columnName, Date JavaDoc x) throws SQLException JavaDoc {
157         rs.updateDate( findColumn(columnName), x );
158     }
159
160     public double getDouble(String JavaDoc columnName) throws SQLException JavaDoc {
161         return rs.getDouble( findColumn(columnName) );
162     }
163
164     public void updateDouble(String JavaDoc columnName, double x) throws SQLException JavaDoc {
165         rs.updateDouble( findColumn(columnName), x );
166     }
167
168     public float getFloat(String JavaDoc columnName) throws SQLException JavaDoc {
169         return rs.getFloat( findColumn(columnName) );
170     }
171
172     public void updateFloat(String JavaDoc columnName, float x) throws SQLException JavaDoc {
173         rs.updateFloat( findColumn(columnName), x );
174     }
175
176     public int getInt(String JavaDoc columnName) throws SQLException JavaDoc {
177         return rs.getInt( findColumn(columnName) );
178     }
179
180     public void updateInt(String JavaDoc columnName, int x) throws SQLException JavaDoc {
181         rs.updateInt( findColumn(columnName), x );
182     }
183
184     public long getLong(String JavaDoc columnName) throws SQLException JavaDoc {
185         return rs.getLong( findColumn(columnName) );
186     }
187
188     public void updateLong(String JavaDoc columnName, long x) throws SQLException JavaDoc {
189         rs.updateLong( findColumn(columnName), x );
190     }
191
192     public Object JavaDoc getObject(String JavaDoc columnName) throws SQLException JavaDoc {
193         return rs.getObject( findColumn(columnName) );
194     }
195
196     public Object JavaDoc getObject(String JavaDoc columnName, Map JavaDoc map) throws SQLException JavaDoc {
197         return rs.getObject( findColumn(columnName), map );
198     }
199
200     public void updateObject(String JavaDoc columnName, Object JavaDoc x) throws SQLException JavaDoc {
201         rs.updateObject( findColumn(columnName), x );
202     }
203
204     public void updateObject(String JavaDoc columnName, Object JavaDoc x, int scale) throws SQLException JavaDoc {
205         rs.updateObject( findColumn(columnName), x, scale );
206     }
207
208     public Ref JavaDoc getRef(String JavaDoc columnName) throws SQLException JavaDoc {
209         return rs.getRef( findColumn(columnName) );
210     }
211
212     public void updateRef(String JavaDoc columnName, Ref JavaDoc x) throws SQLException JavaDoc {
213         rs.updateRef( findColumn(columnName), x );
214     }
215
216     public short getShort(String JavaDoc columnName) throws SQLException JavaDoc {
217         return rs.getShort( findColumn(columnName) );
218     }
219
220     public void updateShort(String JavaDoc columnName, short x) throws SQLException JavaDoc {
221         rs.updateShort( findColumn(columnName), x );
222     }
223
224     public String JavaDoc getString(String JavaDoc columnName) throws SQLException JavaDoc {
225         return rs.getString( findColumn(columnName) );
226     }
227
228     public void updateString(String JavaDoc columnName, String JavaDoc x) throws SQLException JavaDoc {
229         rs.updateString( findColumn(columnName), x );
230     }
231
232     public Time JavaDoc getTime(String JavaDoc columnName) throws SQLException JavaDoc {
233         return rs.getTime( findColumn(columnName) );
234     }
235
236     public Time JavaDoc getTime(String JavaDoc columnName, Calendar JavaDoc cal) throws SQLException JavaDoc {
237         return rs.getTime( findColumn(columnName), cal );
238     }
239
240     public void updateTime(String JavaDoc columnName, Time JavaDoc x) throws SQLException JavaDoc {
241         rs.updateTime( findColumn(columnName), x );
242     }
243
244     public Timestamp JavaDoc getTimestamp(String JavaDoc columnName) throws SQLException JavaDoc {
245         return rs.getTimestamp( findColumn(columnName) );
246     }
247
248     public void updateTimestamp(String JavaDoc columnName, Timestamp JavaDoc x) throws SQLException JavaDoc {
249         rs.updateTimestamp( findColumn(columnName), x );
250     }
251
252     public Timestamp JavaDoc getTimestamp(String JavaDoc columnName, Calendar JavaDoc cal) throws SQLException JavaDoc {
253         return rs.getTimestamp( findColumn(columnName), cal );
254     }
255
256     public InputStream JavaDoc getUnicodeStream(String JavaDoc columnName) throws SQLException JavaDoc {
257         return rs.getUnicodeStream( findColumn(columnName) );
258     }
259
260     public URL JavaDoc getURL(String JavaDoc columnName) throws SQLException JavaDoc {
261         return rs.getURL( findColumn(columnName) );
262     }
263
264     public void updateNull(String JavaDoc columnName) throws SQLException JavaDoc {
265         rs.updateNull( findColumn(columnName) );
266     }
267
268
269     // ResultSet impl (delegated) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
270

271     public int getConcurrency() throws SQLException JavaDoc {
272         return rs.getConcurrency();
273     }
274
275     public int getFetchDirection() throws SQLException JavaDoc {
276         return rs.getFetchDirection();
277     }
278
279     public int getFetchSize() throws SQLException JavaDoc {
280         return rs.getFetchSize();
281     }
282
283     public int getRow() throws SQLException JavaDoc {
284         return rs.getRow();
285     }
286
287     public int getType() throws SQLException JavaDoc {
288         return rs.getType();
289     }
290
291     public void afterLast() throws SQLException JavaDoc {
292         rs.afterLast();
293     }
294
295     public void beforeFirst() throws SQLException JavaDoc {
296         rs.beforeFirst();
297     }
298
299     public void cancelRowUpdates() throws SQLException JavaDoc {
300         rs.cancelRowUpdates();
301     }
302
303     public void clearWarnings() throws SQLException JavaDoc {
304         rs.clearWarnings();
305     }
306
307     public void close() throws SQLException JavaDoc {
308         rs.close();
309     }
310
311     public void deleteRow() throws SQLException JavaDoc {
312         rs.deleteRow();
313     }
314
315     public void insertRow() throws SQLException JavaDoc {
316         rs.insertRow();
317     }
318
319     public void moveToCurrentRow() throws SQLException JavaDoc {
320         rs.moveToCurrentRow();
321     }
322
323     public void moveToInsertRow() throws SQLException JavaDoc {
324         rs.moveToInsertRow();
325     }
326
327     public void refreshRow() throws SQLException JavaDoc {
328         rs.refreshRow();
329     }
330
331     public void updateRow() throws SQLException JavaDoc {
332         rs.updateRow();
333     }
334
335     public boolean first() throws SQLException JavaDoc {
336         return rs.first();
337     }
338
339     public boolean isAfterLast() throws SQLException JavaDoc {
340         return rs.isAfterLast();
341     }
342
343     public boolean isBeforeFirst() throws SQLException JavaDoc {
344         return rs.isBeforeFirst();
345     }
346
347     public boolean isFirst() throws SQLException JavaDoc {
348         return rs.isFirst();
349     }
350
351     public boolean isLast() throws SQLException JavaDoc {
352         return rs.isLast();
353     }
354
355     public boolean last() throws SQLException JavaDoc {
356         return rs.last();
357     }
358
359     public boolean next() throws SQLException JavaDoc {
360         return rs.next();
361     }
362
363     public boolean previous() throws SQLException JavaDoc {
364         return rs.previous();
365     }
366
367     public boolean rowDeleted() throws SQLException JavaDoc {
368         return rs.rowDeleted();
369     }
370
371     public boolean rowInserted() throws SQLException JavaDoc {
372         return rs.rowInserted();
373     }
374
375     public boolean rowUpdated() throws SQLException JavaDoc {
376         return rs.rowUpdated();
377     }
378
379     public boolean wasNull() throws SQLException JavaDoc {
380         return rs.wasNull();
381     }
382
383     public byte getByte(int columnIndex) throws SQLException JavaDoc {
384         return rs.getByte(columnIndex);
385     }
386
387     public double getDouble(int columnIndex) throws SQLException JavaDoc {
388         return rs.getDouble(columnIndex);
389     }
390
391     public float getFloat(int columnIndex) throws SQLException JavaDoc {
392         return rs.getFloat(columnIndex);
393     }
394
395     public int getInt(int columnIndex) throws SQLException JavaDoc {
396         return rs.getInt(columnIndex);
397     }
398
399     public long getLong(int columnIndex) throws SQLException JavaDoc {
400         return rs.getLong(columnIndex);
401     }
402
403     public short getShort(int columnIndex) throws SQLException JavaDoc {
404         return rs.getShort(columnIndex);
405     }
406
407     public void setFetchDirection(int direction) throws SQLException JavaDoc {
408         rs.setFetchDirection(direction);
409     }
410
411     public void setFetchSize(int rows) throws SQLException JavaDoc {
412         rs.setFetchSize(rows);
413     }
414
415     public void updateNull(int columnIndex) throws SQLException JavaDoc {
416         rs.updateNull(columnIndex);
417     }
418
419     public boolean absolute(int row) throws SQLException JavaDoc {
420         return rs.absolute(row);
421     }
422
423     public boolean getBoolean(int columnIndex) throws SQLException JavaDoc {
424         return rs.getBoolean(columnIndex);
425     }
426
427     public boolean relative(int rows) throws SQLException JavaDoc {
428         return rs.relative(rows);
429     }
430
431     public byte[] getBytes(int columnIndex) throws SQLException JavaDoc {
432         return rs.getBytes(columnIndex);
433     }
434
435     public void updateByte(int columnIndex, byte x) throws SQLException JavaDoc {
436         rs.updateByte(columnIndex, x);
437     }
438
439     public void updateDouble(int columnIndex, double x) throws SQLException JavaDoc {
440         rs.updateDouble(columnIndex, x);
441     }
442
443     public void updateFloat(int columnIndex, float x) throws SQLException JavaDoc {
444         rs.updateFloat(columnIndex, x);
445     }
446
447     public void updateInt(int columnIndex, int x) throws SQLException JavaDoc {
448         rs.updateInt(columnIndex, x);
449     }
450
451     public void updateLong(int columnIndex, long x) throws SQLException JavaDoc {
452         rs.updateLong(columnIndex, x);
453     }
454
455     public void updateShort(int columnIndex, short x) throws SQLException JavaDoc {
456         rs.updateShort(columnIndex, x);
457     }
458
459     public void updateBoolean(int columnIndex, boolean x) throws SQLException JavaDoc {
460         rs.updateBoolean(columnIndex, x);
461     }
462
463     public void updateBytes(int columnIndex, byte[] x) throws SQLException JavaDoc {
464         rs.updateBytes(columnIndex, x);
465     }
466
467     public InputStream JavaDoc getAsciiStream(int columnIndex) throws SQLException JavaDoc {
468         return rs.getAsciiStream(columnIndex);
469     }
470
471     public InputStream JavaDoc getBinaryStream(int columnIndex) throws SQLException JavaDoc {
472         return rs.getBinaryStream(columnIndex);
473     }
474
475     public InputStream JavaDoc getUnicodeStream(int columnIndex) throws SQLException JavaDoc {
476         return rs.getUnicodeStream(columnIndex);
477     }
478
479     public void updateAsciiStream(int columnIndex, InputStream JavaDoc x, int length) throws SQLException JavaDoc {
480         rs.updateAsciiStream(columnIndex, x, length);
481     }
482
483     public void updateBinaryStream(int columnIndex, InputStream JavaDoc x, int length) throws SQLException JavaDoc {
484         rs.updateBinaryStream(columnIndex, x, length);
485     }
486
487     public Reader JavaDoc getCharacterStream(int columnIndex) throws SQLException JavaDoc {
488         return rs.getCharacterStream(columnIndex);
489     }
490
491     public void updateCharacterStream(int columnIndex, Reader JavaDoc x, int length) throws SQLException JavaDoc {
492         rs.updateCharacterStream(columnIndex, x, length);
493     }
494
495     public Object JavaDoc getObject(int columnIndex) throws SQLException JavaDoc {
496         return rs.getObject(columnIndex);
497     }
498
499     public void updateObject(int columnIndex, Object JavaDoc x) throws SQLException JavaDoc {
500         rs.updateObject(columnIndex, x);
501     }
502
503     public void updateObject(int columnIndex, Object JavaDoc x, int scale) throws SQLException JavaDoc {
504         rs.updateObject(columnIndex, x, scale);
505     }
506
507     public String JavaDoc getCursorName() throws SQLException JavaDoc {
508         return rs.getCursorName();
509     }
510
511     public String JavaDoc getString(int columnIndex) throws SQLException JavaDoc {
512         return rs.getString(columnIndex);
513     }
514
515     public void updateString(int columnIndex, String JavaDoc x) throws SQLException JavaDoc {
516         rs.updateString(columnIndex, x);
517     }
518
519     public BigDecimal JavaDoc getBigDecimal(int columnIndex) throws SQLException JavaDoc {
520         return rs.getBigDecimal(columnIndex);
521     }
522
523     public BigDecimal JavaDoc getBigDecimal(int columnIndex, int scale) throws SQLException JavaDoc {
524         return rs.getBigDecimal(columnIndex, scale);
525     }
526
527     public void updateBigDecimal(int columnIndex, BigDecimal JavaDoc x) throws SQLException JavaDoc {
528         rs.updateBigDecimal(columnIndex, x);
529     }
530
531     public URL JavaDoc getURL(int columnIndex) throws SQLException JavaDoc {
532         return rs.getURL(columnIndex);
533     }
534
535     public Array JavaDoc getArray(int columnIndex) throws SQLException JavaDoc {
536         return rs.getArray(columnIndex);
537     }
538
539     public void updateArray(int columnIndex, Array JavaDoc x) throws SQLException JavaDoc {
540         rs.updateArray(columnIndex, x);
541     }
542
543     public Blob JavaDoc getBlob(int columnIndex) throws SQLException JavaDoc {
544         return rs.getBlob(columnIndex);
545     }
546
547     public void updateBlob(int columnIndex, Blob JavaDoc x) throws SQLException JavaDoc {
548         rs.updateBlob(columnIndex, x);
549     }
550
551     public Clob JavaDoc getClob(int columnIndex) throws SQLException JavaDoc {
552         return rs.getClob(columnIndex);
553     }
554
555     public void updateClob(int columnIndex, Clob JavaDoc x) throws SQLException JavaDoc {
556         rs.updateClob(columnIndex, x);
557     }
558
559     public Date JavaDoc getDate(int columnIndex) throws SQLException JavaDoc {
560         return rs.getDate(columnIndex);
561     }
562
563     public void updateDate(int columnIndex, Date JavaDoc x) throws SQLException JavaDoc {
564         rs.updateDate(columnIndex, x);
565     }
566
567     public Ref JavaDoc getRef(int columnIndex) throws SQLException JavaDoc {
568         return rs.getRef(columnIndex);
569     }
570
571     public void updateRef(int columnIndex, Ref JavaDoc x) throws SQLException JavaDoc {
572         rs.updateRef(columnIndex, x);
573     }
574
575     public ResultSetMetaData JavaDoc getMetaData() throws SQLException JavaDoc {
576         return rs.getMetaData();
577     }
578
579     public SQLWarning JavaDoc getWarnings() throws SQLException JavaDoc {
580         return rs.getWarnings();
581     }
582
583     public Statement JavaDoc getStatement() throws SQLException JavaDoc {
584         return rs.getStatement();
585     }
586
587     public Time JavaDoc getTime(int columnIndex) throws SQLException JavaDoc {
588         return rs.getTime(columnIndex);
589     }
590
591     public void updateTime(int columnIndex, Time JavaDoc x) throws SQLException JavaDoc {
592         rs.updateTime(columnIndex, x);
593     }
594
595     public Timestamp JavaDoc getTimestamp(int columnIndex) throws SQLException JavaDoc {
596         return rs.getTimestamp(columnIndex);
597     }
598
599     public void updateTimestamp(int columnIndex, Timestamp JavaDoc x) throws SQLException JavaDoc {
600         rs.updateTimestamp(columnIndex, x);
601     }
602
603     public Object JavaDoc getObject(int columnIndex, Map JavaDoc map) throws SQLException JavaDoc {
604         return rs.getObject( columnIndex, map );
605     }
606
607     public Date JavaDoc getDate(int columnIndex, Calendar JavaDoc cal) throws SQLException JavaDoc {
608         return rs.getDate(columnIndex, cal);
609     }
610
611     public Time JavaDoc getTime(int columnIndex, Calendar JavaDoc cal) throws SQLException JavaDoc {
612         return rs.getTime(columnIndex, cal);
613     }
614
615     public Timestamp JavaDoc getTimestamp(int columnIndex, Calendar JavaDoc cal) throws SQLException JavaDoc {
616         return rs.getTimestamp(columnIndex, cal);
617     }
618 }
619
620
Popular Tags