01: // $Id: StringClob.java 7 2007-08-17 19:32:18Z jcamaia $
02:
03: package net.sf.persist.tests.framework;
04:
05: import java.io.ByteArrayInputStream;
06: import java.io.InputStream;
07: import java.io.OutputStream;
08: import java.io.Reader;
09: import java.io.StringReader;
10: import java.io.Writer;
11: import java.sql.Clob;
12: import java.sql.SQLException;
13:
14: /**
15: * Clob implementation backed by a String, suitable for sending data to the database only
16: * (does not implement mutable methods)
17: */
18: public class StringClob implements Clob {
19:
20: private String s;
21:
22: public StringClob(String s) {
23: this .s = s;
24: }
25:
26: //not in the interface
27: public String getString() {
28: return s;
29: }
30:
31: public InputStream getAsciiStream() throws SQLException {
32: return new ByteArrayInputStream(s.getBytes());
33: }
34:
35: public Reader getCharacterStream() throws SQLException {
36: return new StringReader(s);
37: }
38:
39: public String getSubString(long pos, int length)
40: throws SQLException {
41: return s.substring((int) pos - 1, (int) (pos + length) - 1);
42: }
43:
44: public long length() throws SQLException {
45: return s.length();
46: }
47:
48: public long position(String searchstr, long start)
49: throws SQLException {
50: return s.indexOf(searchstr, (int) start);
51: }
52:
53: public long position(Clob searchstr, long start)
54: throws SQLException {
55: throw new RuntimeException(
56: "position(Clob,long) not implemented");
57: }
58:
59: public OutputStream setAsciiStream(long pos) throws SQLException {
60: throw new RuntimeException(
61: "setAsciiStream(long) not implemented");
62: }
63:
64: public Writer setCharacterStream(long pos) throws SQLException {
65: throw new RuntimeException(
66: "setCharacterStream(long) not implemented");
67: }
68:
69: public int setString(long pos, String str) throws SQLException {
70: throw new RuntimeException(
71: "setString(lon, String) not implemented");
72: }
73:
74: public int setString(long pos, String str, int offset, int len)
75: throws SQLException {
76: throw new RuntimeException(
77: "setString(long,int,int) not implemented");
78: }
79:
80: public void truncate(long len) throws SQLException {
81: throw new RuntimeException("truncate(long) not implemented");
82: }
83:
84: }
|