001: //$Id: ClobImpl.java 5683 2005-02-12 03:09:22Z oneovthafew $
002: package org.hibernate.lob;
003:
004: import java.io.IOException;
005: import java.io.InputStream;
006: import java.io.OutputStream;
007: import java.io.Reader;
008: import java.io.StringReader;
009: import java.io.Writer;
010: import java.sql.Clob;
011: import java.sql.SQLException;
012:
013: /**
014: * A dummy implementation of <tt>java.sql.Clob</tt> that
015: * may be used to insert new data into a CLOB.
016: * @author Gavin King
017: */
018: public class ClobImpl implements Clob {
019:
020: private Reader reader;
021: private int length;
022: private boolean needsReset = false;
023:
024: public ClobImpl(String string) {
025: reader = new StringReader(string);
026: length = string.length();
027: }
028:
029: public ClobImpl(Reader reader, int length) {
030: this .reader = reader;
031: this .length = length;
032: }
033:
034: /**
035: * @see java.sql.Clob#length()
036: */
037: public long length() throws SQLException {
038: return length;
039: }
040:
041: /**
042: * @see java.sql.Clob#truncate(long)
043: */
044: public void truncate(long pos) throws SQLException {
045: excep();
046: }
047:
048: /**
049: * @see java.sql.Clob#getAsciiStream()
050: */
051: public InputStream getAsciiStream() throws SQLException {
052: try {
053: if (needsReset)
054: reader.reset();
055: } catch (IOException ioe) {
056: throw new SQLException("could not reset reader");
057: }
058: needsReset = true;
059: return new ReaderInputStream(reader);
060: }
061:
062: /**
063: * @see java.sql.Clob#setAsciiStream(long)
064: */
065: public OutputStream setAsciiStream(long pos) throws SQLException {
066: excep();
067: return null;
068: }
069:
070: /**
071: * @see java.sql.Clob#getCharacterStream()
072: */
073: public Reader getCharacterStream() throws SQLException {
074: try {
075: if (needsReset)
076: reader.reset();
077: } catch (IOException ioe) {
078: throw new SQLException("could not reset reader");
079: }
080: needsReset = true;
081: return reader;
082: }
083:
084: /**
085: * @see java.sql.Clob#setCharacterStream(long)
086: */
087: public Writer setCharacterStream(long pos) throws SQLException {
088: excep();
089: return null;
090: }
091:
092: /**
093: * @see java.sql.Clob#getSubString(long, int)
094: */
095: public String getSubString(long pos, int len) throws SQLException {
096: excep();
097: return null;
098: }
099:
100: /**
101: * @see java.sql.Clob#setString(long, String)
102: */
103: public int setString(long pos, String string) throws SQLException {
104: excep();
105: return 0;
106: }
107:
108: /**
109: * @see java.sql.Clob#setString(long, String, int, int)
110: */
111: public int setString(long pos, String string, int i, int j)
112: throws SQLException {
113: excep();
114: return 0;
115: }
116:
117: /**
118: * @see java.sql.Clob#position(String, long)
119: */
120: public long position(String string, long pos) throws SQLException {
121: excep();
122: return 0;
123: }
124:
125: /**
126: * @see java.sql.Clob#position(Clob, long)
127: */
128: public long position(Clob colb, long pos) throws SQLException {
129: excep();
130: return 0;
131: }
132:
133: private static void excep() {
134: throw new UnsupportedOperationException(
135: "Blob may not be manipulated from creating session");
136: }
137:
138: }
|