KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > sql > rowset > serial > SQLInputImpl


1 /*
2  * @(#)SQLInputImpl.java 1.4 04/05/05
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.sql.rowset.serial;
9
10 import java.sql.*;
11 import javax.sql.*;
12 import java.io.*;
13 import java.math.*;
14 import java.util.Map JavaDoc;
15
16 /**
17  * An input stream used for custom mapping user-defined types (UDTs).
18  * An <code>SQLInputImpl</code> object is an input stream that contains a
19  * stream of values that are the attributes of a UDT.
20  * <p>
21  * This class is used by the driver behind the scenes when the method
22  * <code>getObject</code> is called on an SQL structured or distinct type
23  * that has a custom mapping; a programmer never invokes
24  * <code>SQLInputImpl</code> methods directly. They are provided here as a
25  * convenience for those who write <code>RowSet</code> implementations.
26  * <P>
27  * The <code>SQLInputImpl</code> class provides a set of
28  * reader methods analogous to the <code>ResultSet</code> getter
29  * methods. These methods make it possible to read the values in an
30  * <code>SQLInputImpl</code> object.
31  * <P>
32  * The method <code>wasNull</code> is used to determine whether the
33  * the last value read was SQL <code>NULL</code>.
34  * <P>When the method <code>getObject</code> is called with an
35  * object of a class implementing the interface <code>SQLData</code>,
36  * the JDBC driver calls the method <code>SQLData.getSQLType</code>
37  * to determine the SQL type of the UDT being custom mapped. The driver
38  * creates an instance of <code>SQLInputImpl</code>, populating it with the
39  * attributes of the UDT. The driver then passes the input
40  * stream to the method <code>SQLData.readSQL</code>, which in turn
41  * calls the <code>SQLInputImpl</code> reader methods
42  * to read the attributes from the input stream.
43  * @see java.sql.SQLData
44  */

45 public class SQLInputImpl implements SQLInput {
46
47     /**
48      * <code>true</code> if the last value returned was <code>SQL NULL</code>;
49      * <code>false</code> otherwise.
50      */

51     private boolean lastValueWasNull;
52     
53     /**
54      * The current index into the array of SQL structured type attributes
55      * that will be read from this <code>SQLInputImpl</code> object and
56      * mapped to the fields of a class in the Java programming language.
57      */

58     private int idx;
59
60     /**
61      * The array of attributes to be read from this stream. The order
62      * of the attributes is the same as the order in which they were
63      * listed in the SQL definition of the UDT.
64      */

65     private Object JavaDoc attrib[];
66
67     /**
68      * The type map to use when the method <code>readObject</code>
69      * is invoked. This is a <code>java.util.Map</code> object in which
70      * there may be zero or more entries. Each entry consists of the
71      * fully qualified name of a UDT (the value to be mapped) and the
72      * <code>Class</code> object for a class that implements
73      * <code>SQLData</code> (the Java class that defines how the UDT
74      * will be mapped).
75      */

76     private Map JavaDoc map;
77
78
79     /**
80      * Creates an <code>SQLInputImpl</code> object initialized with the
81      * given array of attributes and the given type map. If any of the
82      * attributes is a UDT whose name is in an entry in the type map,
83      * the attribute will be mapped according to the corresponding
84      * <code>SQLData</code> implementation.
85      *
86      * @param attributes an array of <code>Object</code> instances in which
87      * each element is an attribute of a UDT. The order of the
88      * attributes in the array is the same order in which
89      * the attributes were defined in the UDT definition.
90      * @param map a <code>java.util.Map</code> object containing zero or more
91      * entries, with each entry consisting of 1) a <code>String</code>
92      * giving the fully
93      * qualified name of the UDT and 2) the <code>Class</code> object
94      * for the <code>SQLData</code> implementation that defines how
95      * the UDT is to be mapped
96      * @throws SQLException if the <code>attributes</code> or the <code>map</code>
97      * is a <code>null</code> value
98      */

99   
100     public SQLInputImpl(Object JavaDoc[] attributes, Map JavaDoc<String JavaDoc,Class JavaDoc<?>> map)
101     throws SQLException
102     {
103         if ((attributes == null) || (map == null)) {
104             throw new SQLException("Cannot instantiate a SQLInputImpl " +
105             "object with null parameters");
106         }
107         // assign our local reference to the attribute stream
108
attrib = attributes;
109         // init the index point before the head of the stream
110
idx = -1;
111         // set the map
112
this.map = map;
113     }
114         
115
116     /**
117      * Retrieves the next attribute in this <code>SQLInputImpl</code> object
118      * as an <code>Object</code> in the Java programming language.
119      *
120      * @return the next value in the input stream
121      * as an <code>Object</code> in the Java programming language
122      * @throws SQLException if the read position is located at an invalid
123      * position or if there are no further values in the stream
124      */

125     private Object JavaDoc getNextAttribute() throws SQLException {
126         if (++idx >= attrib.length) {
127             throw new SQLException("SQLInputImpl exception: Invalid read " +
128                    "position");
129         } else {
130             return attrib[idx];
131         }
132     }
133
134
135     //================================================================
136
// Methods for reading attributes from the stream of SQL data.
137
// These methods correspond to the column-accessor methods of
138
// java.sql.ResultSet.
139
//================================================================
140

141     /**
142      * Retrieves the next attribute in this <code>SQLInputImpl</code> object as
143      * a <code>String</code> in the Java programming language.
144      * <p>
145      * This method does not perform type-safe checking to determine if the
146      * returned type is the expected type; this responsibility is delegated
147      * to the UDT mapping as defined by a <code>SQLData</code>
148      * implementation.
149      * <p>
150      * @return the next attribute in this <code>SQLInputImpl</code> object;
151      * if the value is <code>SQL NULL</code>, return <code>null</code>
152      * @throws SQLException if the read position is located at an invalid
153      * position or if there are no further values in the stream.
154      */

155     public String JavaDoc readString() throws SQLException {
156
157         String JavaDoc attrib = (String JavaDoc)getNextAttribute();
158         
159         if (attrib == null) {
160             lastValueWasNull = true;
161             return null;
162         } else {
163             lastValueWasNull = false;
164             return attrib;
165         }
166     }
167
168     /**
169      * Retrieves the next attribute in this <code>SQLInputImpl</code> object as
170      * a <code>boolean</code> in the Java programming language.
171      * <p>
172      * This method does not perform type-safe checking to determine if the
173      * returned type is the expected type; this responsibility is delegated
174      * to the UDT mapping as defined by a <code>SQLData</code>
175      * implementation.
176      * <p>
177      * @return the next attribute in this <code>SQLInputImpl</code> object;
178      * if the value is <code>SQL NULL</code>, return <code>null</code>
179      * @throws SQLException if the read position is located at an invalid
180      * position or if there are no further values in the stream.
181      */

182     public boolean readBoolean() throws SQLException {
183
184         Boolean JavaDoc attrib = (Boolean JavaDoc)getNextAttribute();
185
186         if (attrib == null) {
187             lastValueWasNull = true;
188             return false;
189         } else {
190             lastValueWasNull = false;
191             return attrib.booleanValue();
192         }
193     }
194
195     /**
196      * Retrieves the next attribute in this <code>SQLInputImpl</code> object as
197      * a <code>byte</code> in the Java programming language.
198      * <p>
199      * This method does not perform type-safe checking to determine if the
200      * returned type is the expected type; this responsibility is delegated
201      * to the UDT mapping as defined by a <code>SQLData</code>
202      * implementation.
203      * <p>
204      * @return the next attribute in this <code>SQLInputImpl</code> object;
205      * if the value is <code>SQL NULL</code>, return <code>null</code>
206      * @throws SQLException if the read position is located at an invalid
207      * position or if there are no further values in the stream
208      */

209     public byte readByte() throws SQLException {
210         Byte JavaDoc attrib = (Byte JavaDoc)getNextAttribute();
211
212         if (attrib == null) {
213             lastValueWasNull = true;
214             return (byte)0;
215         } else {
216             lastValueWasNull = false;
217             return attrib.byteValue();
218         }
219     }
220
221     /**
222      * Retrieves the next attribute in this <code>SQLInputImpl</code> object
223      * as a <code>short</code> in the Java programming language.
224      * <P>
225      * This method does not perform type-safe checking to determine if the
226      * returned type is the expected type; this responsibility is delegated
227      * to the UDT mapping as defined by a <code>SQLData</code> implementation.
228      * <P>
229      * @return the next attribute in this <code>SQLInputImpl</code> object;
230      * if the value is <code>SQL NULL</code>, return <code>null</code>
231      * @throws SQLException if the read position is located at an invalid
232      * position or if there are no more values in the stream
233      */

234     public short readShort() throws SQLException {
235         Short JavaDoc attrib = (Short JavaDoc)getNextAttribute();
236
237         if (attrib == null) {
238             lastValueWasNull = true;
239             return (short)0;
240         } else {
241             lastValueWasNull = false;
242             return attrib.shortValue();
243         }
244     }
245     
246     /**
247      * Retrieves the next attribute in this <code>SQLInputImpl</code> object
248      * as an <code>int</code> in the Java programming language.
249      * <P>
250      * This method does not perform type-safe checking to determine if the
251      * returned type is the expected type; this responsibility is delegated
252      * to the UDT mapping as defined by a <code>SQLData</code> implementation.
253      * <P>
254      * @return the next attribute in this <code>SQLInputImpl</code> object;
255      * if the value is <code>SQL NULL</code>, return <code>null</code>
256      * @throws SQLException if the read position is located at an invalid
257      * position or if there are no more values in the stream
258      */

259     public int readInt() throws SQLException {
260         Integer JavaDoc attrib = (Integer JavaDoc)getNextAttribute();
261         
262         if (attrib == null) {
263             lastValueWasNull = true;
264             return (int)0;
265         } else {
266             lastValueWasNull = false;
267             return attrib.intValue();
268         }
269     }
270
271     /**
272      * Retrieves the next attribute in this <code>SQLInputImpl</code> object
273      * as a <code>long</code> in the Java programming language.
274      * <P>
275      * This method does not perform type-safe checking to determine if the
276      * returned type is the expected type; this responsibility is delegated
277      * to the UDT mapping as defined by a <code>SQLData</code> implementation.
278      * <P>
279      * @return the next attribute in this <code>SQLInputImpl</code> object;
280      * if the value is <code>SQL NULL</code>, return <code>null</code>
281      * @throws SQLException if the read position is located at an invalid
282      * position or if there are no more values in the stream
283      */

284     public long readLong() throws SQLException {
285         Long JavaDoc attrib = (Long JavaDoc)getNextAttribute();
286
287         if (attrib == null) {
288             lastValueWasNull = true;
289             return (long)0;
290         } else {
291             lastValueWasNull = false;
292             return attrib.longValue();
293         }
294     }
295
296     /**
297      * Retrieves the next attribute in this <code>SQLInputImpl</code> object
298      * as a <code>float</code> in the Java programming language.
299      * <P>
300      * This method does not perform type-safe checking to determine if the
301      * returned type is the expected type; this responsibility is delegated
302      * to the UDT mapping as defined by a <code>SQLData</code> implementation.
303      * <P>
304      * @return the next attribute in this <code>SQLInputImpl</code> object;
305      * if the value is <code>SQL NULL</code>, return <code>null</code>
306      * @throws SQLException if the read position is located at an invalid
307      * position or if there are no more values in the stream
308      */

309     public float readFloat() throws SQLException {
310         Float JavaDoc attrib = (Float JavaDoc)getNextAttribute();
311
312         if (attrib == null) {
313             lastValueWasNull = true;
314             return (float)0;
315         } else {
316             lastValueWasNull = false;
317             return attrib.floatValue();
318         }
319     }
320
321     /**
322      * Retrieves the next attribute in this <code>SQLInputImpl</code> object
323      * as a <code>double</code> in the Java programming language.
324      * <P>
325      * This method does not perform type-safe checking to determine if the
326      * returned type is the expected type; this responsibility is delegated
327      * to the UDT mapping as defined by a <code>SQLData</code> implementation.
328      * <P>
329      * @return the next attribute in this <code>SQLInputImpl</code> object;
330      * if the value is <code>SQL NULL</code>, return <code>null</code>
331      * @throws SQLException if the read position is located at an invalid
332      * position or if there are no more values in the stream
333      */

334     public double readDouble() throws SQLException {
335         Double JavaDoc attrib = (Double JavaDoc)getNextAttribute();
336
337         if (attrib == null) {
338             lastValueWasNull = true;
339             return (double)0;
340         } else {
341             lastValueWasNull = false;
342             return attrib.doubleValue();
343         }
344     }
345
346     /**
347      * Retrieves the next attribute in this <code>SQLInputImpl</code> object
348      * as a <code>java.math.BigDecimal</code>.
349      * <P>
350      * This method does not perform type-safe checking to determine if the
351      * returned type is the expected type; this responsibility is delegated
352      * to the UDT mapping as defined by a <code>SQLData</code> implementation.
353      * <P>
354      * @return the next attribute in this <code>SQLInputImpl</code> object;
355      * if the value is <code>SQL NULL</code>, return <code>null</code>
356      * @throws SQLException if the read position is located at an invalid
357      * position or if there are no more values in the stream
358      */

359     public java.math.BigDecimal JavaDoc readBigDecimal() throws SQLException {
360         java.math.BigDecimal JavaDoc attrib = (java.math.BigDecimal JavaDoc)getNextAttribute();
361
362         if (attrib == null) {
363             lastValueWasNull = true;
364             return null;
365         } else {
366             lastValueWasNull = false;
367             return attrib;
368         }
369     }
370     
371     /**
372      * Retrieves the next attribute in this <code>SQLInputImpl</code> object
373      * as an array of bytes.
374      * <p>
375      * This method does not perform type-safe checking to determine if the
376      * returned type is the expected type; this responsibility is delegated
377      * to the UDT mapping as defined by a <code>SQLData</code> implementation.
378      * <P>
379      * @return the next attribute in this <code>SQLInputImpl</code> object;
380      * if the value is <code>SQL NULL</code>, return <code>null</code>
381      * @throws SQLException if the read position is located at an invalid
382      * position or if there are no more values in the stream
383      */

384     public byte[] readBytes() throws SQLException {
385         byte[] attrib = (byte[])getNextAttribute();
386
387         if (attrib == null) {
388             lastValueWasNull = true;
389             return null;
390         } else {
391             lastValueWasNull = false;
392             return attrib;
393         }
394     }
395
396     /**
397      * Retrieves the next attribute in this <code>SQLInputImpl</code> as
398      * a <code>java.sql.Date</code> object.
399      * <P>
400      * This method does not perform type-safe checking to determine if the
401      * returned type is the expected type; this responsibility is delegated
402      * to the UDT mapping as defined by a <code>SQLData</code> implementation.
403      * <P>
404      * @return the next attribute in this <code>SQLInputImpl</code> object;
405      * if the value is <code>SQL NULL</code>, return <code>null</code>
406      * @throws SQLException if the read position is located at an invalid
407      * position or if there are no more values in the stream
408      */

409     public java.sql.Date JavaDoc readDate() throws SQLException {
410         java.sql.Date JavaDoc attrib = (java.sql.Date JavaDoc)getNextAttribute();
411
412         if (attrib == null) {
413             lastValueWasNull = true;
414             return null;
415         } else {
416             lastValueWasNull = false;
417             return attrib;
418         }
419     }
420
421     /**
422      * Retrieves the next attribute in this <code>SQLInputImpl</code> object as
423      * a <code>java.sql.Time</code> object.
424      * <P>
425      * This method does not perform type-safe checking to determine if the
426      * returned type is the expected type as this responsibility is delegated
427      * to the UDT mapping as implemented by a <code>SQLData</code>
428      * implementation.
429      *
430      * @return the attribute; if the value is <code>SQL NULL</code>, return
431      * <code>null</code>
432      * @throws SQLException if the read position is located at an invalid
433      * position; or if there are no further values in the stream.
434      */

435     public java.sql.Time JavaDoc readTime() throws SQLException {
436         java.sql.Time JavaDoc attrib = (java.sql.Time JavaDoc)getNextAttribute();
437
438         if (attrib == null) {
439             lastValueWasNull = true;
440             return null;
441         } else {
442             lastValueWasNull = false;
443             return attrib;
444         }
445     }
446
447     /**
448      * Retrieves the next attribute in this <code>SQLInputImpl</code> object as
449      * a <code>java.sql.Timestamp</code> object.
450      *
451      * @return the attribute; if the value is <code>SQL NULL</code>, return
452      * <code>null</code>
453      * @throws SQLException if the read position is located at an invalid
454      * position; or if there are no further values in the stream.
455      */

456     public java.sql.Timestamp JavaDoc readTimestamp() throws SQLException {
457         java.sql.Timestamp JavaDoc attrib = (java.sql.Timestamp JavaDoc)getNextAttribute();
458
459         if (attrib == null) {
460             lastValueWasNull = true;
461             return null;
462         } else {
463             lastValueWasNull = false;
464             return attrib;
465         }
466     }
467
468     /**
469      * Retrieves the next attribute in this <code>SQLInputImpl</code> object
470      * as a stream of Unicode characters.
471      * <P>
472      * This method does not perform type-safe checking to determine if the
473      * returned type is the expected type as this responsibility is delegated
474      * to the UDT mapping as implemented by a <code>SQLData</code>
475      * implementation.
476      *
477      * @return the attribute; if the value is <code>SQL NULL</code>, return <code>null</code>
478      * @throws SQLException if the read position is located at an invalid
479      * position; or if there are no further values in the stream.
480      */

481     public java.io.Reader JavaDoc readCharacterStream() throws SQLException {
482         java.io.Reader JavaDoc attrib = (java.io.Reader JavaDoc)getNextAttribute();
483
484         if (attrib == null) {
485             lastValueWasNull = true;
486             return null;
487         } else {
488             lastValueWasNull = false;
489             return attrib;
490         }
491     }
492
493     /**
494      * Returns the next attribute in this <code>SQLInputImpl</code> object
495      * as a stream of ASCII characters.
496      * <P>
497      * This method does not perform type-safe checking to determine if the
498      * returned type is the expected type as this responsibility is delegated
499      * to the UDT mapping as implemented by a <code>SQLData</code>
500      * implementation.
501      *
502      * @return the attribute; if the value is <code>SQL NULL</code>,
503      * return <code>null</code>
504      * @throws SQLException if the read position is located at an invalid
505      * position; or if there are no further values in the stream.
506      */

507     public java.io.InputStream JavaDoc readAsciiStream() throws SQLException {
508         java.io.InputStream JavaDoc attrib = (java.io.InputStream JavaDoc)getNextAttribute();
509
510         if (attrib == null) {
511             lastValueWasNull = true;
512             return null;
513         } else {
514             lastValueWasNull = false;
515             return attrib;
516         }
517     }
518     
519     /**
520      * Returns the next attribute in this <code>SQLInputImpl</code> object
521      * as a stream of uninterpreted bytes.
522      * <P>
523      * This method does not perform type-safe checking to determine if the
524      * returned type is the expected type as this responsibility is delegated
525      * to the UDT mapping as implemented by a <code>SQLData</code>
526      * implementation.
527      *
528      * @return the attribute; if the value is <code>SQL NULL</code>, return
529      * <code>null</code>
530      * @throws SQLException if the read position is located at an invalid
531      * position; or if there are no further values in the stream.
532      */

533     public java.io.InputStream JavaDoc readBinaryStream() throws SQLException {
534         java.io.InputStream JavaDoc attrib = (java.io.InputStream JavaDoc)getNextAttribute();
535
536         if (attrib == null) {
537             lastValueWasNull = true;
538             return null;
539         } else {
540             lastValueWasNull = false;
541             return attrib;
542         }
543     }
544     
545     //================================================================
546
// Methods for reading items of SQL user-defined types from the stream.
547
//================================================================
548

549     /**
550      * Retrieves the value at the head of this <code>SQLInputImpl</code>
551      * object as an <code>Object</code> in the Java programming language. The
552      * actual type of the object returned is determined by the default
553      * mapping of SQL types to types in the Java programming language unless
554      * there is a custom mapping, in which case the type of the object
555      * returned is determined by this stream's type map.
556      * <P>
557      * The JDBC technology-enabled driver registers a type map with the stream
558      * before passing the stream to the application.
559      * <P>
560      * When the datum at the head of the stream is an SQL <code>NULL</code>,
561      * this method returns <code>null</code>. If the datum is an SQL
562      * structured or distinct type with a custom mapping, this method
563      * determines the SQL type of the datum at the head of the stream,
564      * constructs an object of the appropriate class, and calls the method
565      * <code>SQLData.readSQL</code> on that object. The <code>readSQL</code>
566      * method then calls the appropriate <code>SQLInputImpl.readXXX</code>
567      * methods to retrieve the attribute values from the stream.
568      *
569      * @return the value at the head of the stream as an <code>Object</code>
570      * in the Java programming language; <code>null</code> if
571      * the value is SQL <code>NULL</code>
572      * @throws SQLException if the read position is located at an invalid
573      * position; or if there are no further values in the stream.
574      */

575     public Object JavaDoc readObject() throws SQLException {
576         Object JavaDoc attrib = (Object JavaDoc)getNextAttribute();
577
578         if (attrib == null) {
579             lastValueWasNull = true;
580             return null;
581         } else {
582             lastValueWasNull = false;
583             if (attrib instanceof Struct) {
584                 Struct s = (Struct)attrib;
585                 // look up the class in the map
586
Class JavaDoc c = (Class JavaDoc)map.get(s.getSQLTypeName());
587                 if (c != null) {
588                     // create new instance of the class
589
SQLData obj = null;
590                     try {
591                         obj = (SQLData)c.newInstance();
592                     } catch (java.lang.InstantiationException JavaDoc ex) {
593                         throw new SQLException("Unable to instantiate: " +
594                                                ex.getMessage());
595                     } catch (java.lang.IllegalAccessException JavaDoc ex) {
596                         throw new SQLException("Unable to instantiate: " +
597                                                ex.getMessage());
598                     }
599                     // get the attributes from the struct
600
Object JavaDoc attribs[] = s.getAttributes(map);
601                     // create the SQLInput "stream"
602
SQLInputImpl JavaDoc sqlInput = new SQLInputImpl JavaDoc(attribs, map);
603                     // read the values...
604
obj.readSQL(sqlInput, s.getSQLTypeName());
605                     return (Object JavaDoc)obj;
606                 }
607             }
608             return (Object JavaDoc)attrib;
609         }
610     }
611     
612     /**
613      * Retrieves the value at the head of this <code>SQLInputImpl</code> object
614      * as a <code>Ref</code> object in the Java programming language.
615      *
616      * @return a <code>Ref</code> object representing the SQL
617      * <code>REF</code> value at the head of the stream; if the value
618      * is <code>SQL NULL</code> return <code>null</code>
619      * @throws SQLException if the read position is located at an invalid
620      * position; or if there are no further values in the stream.
621      */

622     public Ref readRef() throws SQLException {
623         Ref attrib = (Ref)getNextAttribute();
624
625         if (attrib == null) {
626             lastValueWasNull = true;
627             return null;
628         } else {
629             lastValueWasNull = false;
630             return attrib;
631         }
632     }
633
634     /**
635      * Retrieves the <code>BLOB</code> value at the head of this
636      * <code>SQLInputImpl</code> object as a <code>Blob</code> object
637      * in the Java programming language.
638      * <P>
639      * This method does not perform type-safe checking to determine if the
640      * returned type is the expected type as this responsibility is delegated
641      * to the UDT mapping as implemented by a <code>SQLData</code>
642      * implementation.
643      *
644      * @return a <code>Blob</code> object representing the SQL
645      * <code>BLOB</code> value at the head of this stream;
646      * if the value is <code>SQL NULL</code>, return
647      * <code>null</code>
648      * @throws SQLException if the read position is located at an invalid
649      * position; or if there are no further values in the stream.
650      */

651     public Blob readBlob() throws SQLException {
652         Blob attrib = (Blob)getNextAttribute();
653         
654         if (attrib == null) {
655             lastValueWasNull = true;
656             return null;
657         } else {
658             lastValueWasNull = false;
659             return attrib;
660         }
661     }
662
663     /**
664      * Retrieves the <code>CLOB</code> value at the head of this
665      * <code>SQLInputImpl</code> object as a <code>Clob</code> object
666      * in the Java programming language.
667      * <P>
668      * This method does not perform type-safe checking to determine if the
669      * returned type is the expected type as this responsibility is delegated
670      * to the UDT mapping as implemented by a <code>SQLData</code>
671      * implementation.
672      *
673      * @return a <code>Clob</code> object representing the SQL
674      * <code>CLOB</code> value at the head of the stream;
675      * if the value is <code>SQL NULL</code>, return
676      * <code>null</code>
677      * @throws SQLException if the read position is located at an invalid
678      * position; or if there are no further values in the stream.
679      */

680     public Clob readClob() throws SQLException {
681
682         Clob attrib = (Clob)getNextAttribute();
683         if (attrib == null) {
684             lastValueWasNull = true;
685             return null;
686         } else {
687             lastValueWasNull = false;
688             return attrib;
689         }
690     }
691
692     /**
693      * Reads an SQL <code>ARRAY</code> value from the stream and
694      * returns it as an <code>Array</code> object in the Java programming
695      * language.
696      * <P>
697      * This method does not perform type-safe checking to determine if the
698      * returned type is the expected type as this responsibility is delegated
699      * to the UDT mapping as implemented by a <code>SQLData</code>
700      * implementation.
701      *
702      * @return an <code>Array</code> object representing the SQL
703      * <code>ARRAY</code> value at the head of the stream; *
704      * if the value is <code>SQL NULL</code>, return
705      * <code>null</code>
706      * @throws SQLException if the read position is located at an invalid
707      * position; or if there are no further values in the stream.
708
709      */

710     public Array readArray() throws SQLException {
711         Array attrib = (Array)getNextAttribute();
712
713         if (attrib == null) {
714             lastValueWasNull = true;
715             return null;
716         } else {
717             lastValueWasNull = false;
718             return attrib;
719         }
720     }
721
722     /**
723      * Ascertains whether the last value read from this
724      * <code>SQLInputImpl</code> object was <code>null</code>.
725      *
726      * @return <code>true</code> if the SQL value read most recently was
727      * <code>null</code>; otherwise, <code>false</code>; by default it
728      * will return false
729      * @throws SQLException if an error occurs determining the last value
730      * read was a <code>null</code> value or not;
731      */

732     public boolean wasNull() throws SQLException {
733         return lastValueWasNull;
734     }
735     
736     /**
737      * Reads an SQL <code>DATALINK</code> value from the stream and
738      * returns it as an <code>URL</code> object in the Java programming
739      * language.
740      * <P>
741      * This method does not perform type-safe checking to determine if the
742      * returned type is the expected type as this responsibility is delegated
743      * to the UDT mapping as implemented by a <code>SQLData</code>
744      * implementation.
745      *
746      * @return an <code>URL</code> object representing the SQL
747      * <code>DATALINK</code> value at the head of the stream; *
748      * if the value is <code>SQL NULL</code>, return
749      * <code>null</code>
750      * @throws SQLException if the read position is located at an invalid
751      * position; or if there are no further values in the stream.
752      */

753     public java.net.URL JavaDoc readURL() throws SQLException {
754         throw new SQLException("Operation not supported");
755     }
756
757 }
758
Popular Tags