KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > in > co > daffodil > db > jdbc > DaffodilDBClob


1 package in.co.daffodil.db.jdbc;
2
3 import java.io.*;
4 import java.sql.*;
5
6 /**
7  * The mapping in the Java<sup><font size=-2>TM</font></sup> programming language
8  * for the SQL <code>CLOB</code> type.
9  * An SQL <code>CLOB</code> is a built-in type
10  * that stores a Character Large Object as a column value in a row of
11  * a database table.
12  * By default drivers implement a <code>Clob</code> object using an SQL
13  * <code>locator(CLOB)</code>, which means that a <code>Clob</code> object
14  * contains a logical pointer to the SQL <code>CLOB</code> data rather than
15  * the data itself. A <code>Clob</code> object is valid for the duration
16  * of the transaction in which it was created.
17  * <P>The <code>Clob</code> interface provides methods for getting the
18  * length of an SQL <code>CLOB</code> (Character Large Object) value,
19  * for materializing a <code>CLOB</code> value on the client, and for
20  * searching for a substring or <code>CLOB</code> object within a
21  * <code>CLOB</code> value.
22  * Methods in the interfaces {@link ResultSet},
23  * {@link CallableStatement}, and {@link PreparedStatement}, such as
24  * <code>getClob</code> and <code>setClob</code> allow a programmer to
25  * access an SQL <code>CLOB</code> value. In addition, this interface
26  * has methods for updating a <code>CLOB</code> value.
27  *
28  * @since 1.2
29  */

30
31
32 public class DaffodilDBClob implements Clob,Serializable{
33     Clob clob;
34
35     public DaffodilDBClob(Clob clob){
36         this.clob = clob;
37     }
38
39   /**
40    * Retrieves the number of characters
41    * in the <code>CLOB</code> value
42    * designated by this <code>Clob</code> object.
43    *
44    * @return length of the <code>CLOB</code> in characters
45    * @exception SQLException if there is an error accessing the
46    * length of the <code>CLOB</code> value
47    * @since 1.2
48    */

49     public long length() throws SQLException{
50         return clob.length();
51     }
52
53   /**
54    * Retrieves a copy of the specified substring
55    * in the <code>CLOB</code> value
56    * designated by this <code>Clob</code> object.
57    * The substring begins at position
58    * <code>pos</code> and has up to <code>length</code> consecutive
59    * characters.
60    *
61    * @param pos the first character of the substring to be extracted.
62    * The first character is at position 1.
63    * @param length the number of consecutive characters to be copied
64    * @return a <code>String</code> that is the specified substring in
65    * the <code>CLOB</code> value designated by this <code>Clob</code> object
66    * @exception SQLException if there is an error accessing the
67    * <code>CLOB</code> value
68    * @since 1.2
69    */

70     public String JavaDoc getSubString(long pos, int length) throws SQLException{
71         return clob.getSubString(pos,length);
72     }
73
74   /**
75    * Retrieves the <code>CLOB</code> value designated by this <code>Clob</code>
76    * object as a <code>java.io.Reader</code> object (or as a stream of
77    * characters).
78    *
79    * @return a <code>java.io.Reader</code> object containing the
80    * <code>CLOB</code> data
81    * @exception SQLException if there is an error accessing the
82    * <code>CLOB</code> value
83    * @see #setCharacterStream
84    * @since 1.2
85    */

86     public java.io.Reader JavaDoc getCharacterStream() throws SQLException{
87         return clob.getCharacterStream();
88     }
89
90   /**
91    * Retrieves the <code>CLOB</code> value designated by this <code>Clob</code>
92    * object as an ascii stream.
93    *
94    * @return a <code>java.io.InputStream</code> object containing the
95    * <code>CLOB</code> data
96    * @exception SQLException if there is an error accessing the
97    * <code>CLOB</code> value
98    * @see #setAsciiStream
99    * @since 1.2
100    */

101     public java.io.InputStream JavaDoc getAsciiStream() throws SQLException{
102         return clob.getAsciiStream();
103     }
104
105   /**
106    * Retrieves the character position at which the specified substring
107    * <code>searchstr</code> appears in the SQL <code>CLOB</code> value
108    * represented by this <code>Clob</code> object. The search
109    * begins at position <code>start</code>.
110    *
111    * @param searchstr the substring for which to search
112    * @param start the position at which to begin searching; the first position
113    * is 1
114    * @return the position at which the substring appears or -1 if it is not
115    * present; the first position is 1
116    * @exception SQLException if there is an error accessing the
117    * <code>CLOB</code> value
118    * @since 1.2
119    */

120     public long position(String JavaDoc searchstr, long start) throws SQLException{
121         return clob.position(searchstr,start);
122     }
123
124   /**
125    * Retrieves the character position at which the specified
126    * <code>Clob</code> object <code>searchstr</code> appears in this
127    * <code>Clob</code> object. The search begins at position
128    * <code>start</code>.
129    *
130    * @param searchstr the <code>Clob</code> object for which to search
131    * @param start the position at which to begin searching; the first
132    * position is 1
133    * @return the position at which the <code>Clob</code> object appears
134    * or -1 if it is not present; the first position is 1
135    * @exception SQLException if there is an error accessing the
136    * <code>CLOB</code> value
137    * @since 1.2
138    */

139     public long position(Clob searchstr, long start) throws SQLException{
140         return clob.position(searchstr,start);
141     }
142
143
144     /**
145      * Writes the given Java <code>String</code> to the <code>CLOB</code>
146      * value that this <code>Clob</code> object designates at the position
147      * <code>pos</code>.
148      *
149      * @param pos the position at which to start writing to the <code>CLOB</code>
150      * value that this <code>Clob</code> object represents
151      * @param str the string to be written to the <code>CLOB</code>
152      * value that this <code>Clob</code> designates
153      * @return the number of characters written
154      * @exception SQLException if there is an error accessing the
155      * <code>CLOB</code> value
156      *
157      * @since 1.4
158      */

159     public int setString(long pos, String JavaDoc str) throws SQLException{
160         return clob.setString(pos,str);
161     }
162
163     /**
164      * Writes <code>len</code> characters of <code>str</code>, starting
165      * at character <code>offset</code>, to the <code>CLOB</code> value
166      * that this <code>Clob</code> represents.
167      *
168      * @param pos the position at which to start writing to this
169      * <code>CLOB</code> object
170      * @param str the string to be written to the <code>CLOB</code>
171      * value that this <code>Clob</code> object represents
172      * @param offset the offset into <code>str</code> to start reading
173      * the characters to be written
174      * @param len the number of characters to be written
175      * @return the number of characters written
176      * @exception SQLException if there is an error accessing the
177      * <code>CLOB</code> value
178      *
179      * @since 1.4
180      */

181     public int setString(long pos, String JavaDoc str, int offset, int len) throws SQLException{
182         return clob.setString(pos,str,offset,len);
183     }
184
185     /**
186      * Retrieves a stream to be used to write Ascii characters to the
187      * <code>CLOB</code> value that this <code>Clob</code> object represents,
188      * starting at position <code>pos</code>.
189      *
190      * @param pos the position at which to start writing to this
191      * <code>CLOB</code> object
192      * @return the stream to which ASCII encoded characters can be written
193      * @exception SQLException if there is an error accessing the
194      * <code>CLOB</code> value
195      * @see #getAsciiStream
196      *
197      * @since 1.4
198      */

199     public java.io.OutputStream JavaDoc setAsciiStream(long pos) throws SQLException{
200         return clob.setAsciiStream(pos);
201     }
202
203     /**
204      * Retrieves a stream to be used to write a stream of Unicode characters
205      * to the <code>CLOB</code> value that this <code>Clob</code> object
206      * represents, at position <code>pos</code>.
207      *
208      * @param pos the position at which to start writing to the
209      * <code>CLOB</code> value
210      *
211      * @return a stream to which Unicode encoded characters can be written
212      * @exception SQLException if there is an error accessing the
213      * <code>CLOB</code> value
214      * @see #getCharacterStream
215      *
216      * @since 1.4
217      */

218     public java.io.Writer JavaDoc setCharacterStream(long pos) throws SQLException{
219         return clob.setCharacterStream(pos);
220     }
221
222     /**
223      * Truncates the <code>CLOB</code> value that this <code>Clob</code>
224      * designates to have a length of <code>len</code>
225      * characters.
226      * @param len the length, in bytes, to which the <code>CLOB</code> value
227      * should be truncated
228      * @exception SQLException if there is an error accessing the
229      * <code>CLOB</code> value
230      *
231      * @since 1.4
232      */

233     public void truncate(long len) throws SQLException{
234        clob.truncate(len);
235     }
236 }
237
Popular Tags