KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > lob > ClobImpl


1 //$Id: ClobImpl.java,v 1.3 2005/02/12 03:09:21 oneovthafew Exp $
2
package org.hibernate.lob;
3
4 import java.io.IOException JavaDoc;
5 import java.io.InputStream JavaDoc;
6 import java.io.OutputStream JavaDoc;
7 import java.io.Reader JavaDoc;
8 import java.io.StringReader JavaDoc;
9 import java.io.Writer JavaDoc;
10 import java.sql.Clob JavaDoc;
11 import java.sql.SQLException JavaDoc;
12
13 /**
14  * A dummy implementation of <tt>java.sql.Clob</tt> that
15  * may be used to insert new data into a CLOB.
16  * @author Gavin King
17  */

18 public class ClobImpl implements Clob JavaDoc {
19
20     private Reader JavaDoc reader;
21     private int length;
22     private boolean needsReset = false;
23
24     public ClobImpl(String JavaDoc string) {
25         reader = new StringReader JavaDoc(string);
26         length = string.length();
27     }
28
29     public ClobImpl(Reader JavaDoc reader, int length) {
30         this.reader = reader;
31         this.length = length;
32     }
33
34     /**
35      * @see java.sql.Clob#length()
36      */

37     public long length() throws SQLException JavaDoc {
38         return length;
39     }
40
41     /**
42      * @see java.sql.Clob#truncate(long)
43      */

44     public void truncate(long pos) throws SQLException JavaDoc {
45         excep();
46     }
47
48     /**
49      * @see java.sql.Clob#getAsciiStream()
50      */

51     public InputStream JavaDoc getAsciiStream() throws SQLException JavaDoc {
52         try {
53             if (needsReset) reader.reset();
54         }
55         catch (IOException JavaDoc ioe) {
56             throw new SQLException JavaDoc("could not reset reader");
57         }
58         needsReset = true;
59         return new ReaderInputStream(reader);
60     }
61
62     /**
63      * @see java.sql.Clob#setAsciiStream(long)
64      */

65     public OutputStream JavaDoc setAsciiStream(long pos) throws SQLException JavaDoc {
66         excep(); return null;
67     }
68
69     /**
70      * @see java.sql.Clob#getCharacterStream()
71      */

72     public Reader JavaDoc getCharacterStream() throws SQLException JavaDoc {
73         try {
74             if (needsReset) reader.reset();
75         }
76         catch (IOException JavaDoc ioe) {
77             throw new SQLException JavaDoc("could not reset reader");
78         }
79         needsReset = true;
80         return reader;
81     }
82
83     /**
84      * @see java.sql.Clob#setCharacterStream(long)
85      */

86     public Writer JavaDoc setCharacterStream(long pos) throws SQLException JavaDoc {
87         excep(); return null;
88     }
89
90     /**
91      * @see java.sql.Clob#getSubString(long, int)
92      */

93     public String JavaDoc getSubString(long pos, int len) throws SQLException JavaDoc {
94         excep(); return null;
95     }
96
97     /**
98      * @see java.sql.Clob#setString(long, String)
99      */

100     public int setString(long pos, String JavaDoc string) throws SQLException JavaDoc {
101         excep(); return 0;
102     }
103
104     /**
105      * @see java.sql.Clob#setString(long, String, int, int)
106      */

107     public int setString(long pos, String JavaDoc string, int i, int j)
108     throws SQLException JavaDoc {
109         excep(); return 0;
110     }
111
112     /**
113      * @see java.sql.Clob#position(String, long)
114      */

115     public long position(String JavaDoc string, long pos) throws SQLException JavaDoc {
116         excep(); return 0;
117     }
118
119     /**
120      * @see java.sql.Clob#position(Clob, long)
121      */

122     public long position(Clob JavaDoc colb, long pos) throws SQLException JavaDoc {
123         excep(); return 0;
124     }
125
126
127     private static void excep() {
128         throw new UnsupportedOperationException JavaDoc("Blob may not be manipulated from creating session");
129     }
130
131 }
132
133
134
135
136
137
138
Popular Tags