KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > datasystem > persistentsystem > DClobUpdatable


1 package com.daffodilwoods.daffodildb.server.datasystem.persistentsystem;
2
3 import com.daffodilwoods.database.resource.*;
4 import java.io.*;
5 import java.sql.*;
6 import com.daffodilwoods.daffodildb.server.sql99.utils._Reference;
7 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.Datatype;
8
9 /**
10  * it is used to insert data in clob type column,data is set in DClobUpdatable which has to insert and
11  * data of clob column can be retrieved through DClobUpdatable
12  */

13 public class DClobUpdatable extends DBlobUpdatable implements Clob{
14
15    DClobUpdatable(DBlob blob) {
16       super(blob);
17    }
18
19    public DClobUpdatable(byte[] bytes) {
20       super(bytes);
21    }
22
23    /**
24     * Constructs DClobUpdatable when data has to insert through stream
25     *
26     * @param stream0 from which data has to insert
27     */

28
29    public DClobUpdatable(InputStream stream0) {
30      super(stream0);
31    }
32
33    public DClobUpdatable(boolean isNull) {
34      super(isNull);
35    }
36
37    /**
38     * Constructs DClobUpdatable when data has to insert through stream
39     *
40     * @param inputString which has to insert
41     */

42
43    public DClobUpdatable(String JavaDoc inputString) {
44       this(inputString.getBytes());
45    }
46
47    public DClobUpdatable() {
48    }
49
50    public long length() throws SQLException {
51       return super.length();
52    }
53
54    /**
55     * To retrieve substring of given length and from specified position
56     *
57     * @param pos position from where string is required
58     * @param length length of string which is required
59     *
60     * @return substring of given length and from specified position
61     */

62
63    public String JavaDoc getSubString(long pos, int length) throws SQLException{
64       return new String JavaDoc(getBytes(pos,length));
65    }
66
67    public Reader getCharacterStream() throws SQLException{
68       return new java.io.InputStreamReader JavaDoc(getAsciiStream());
69    }
70
71    public InputStream getAsciiStream() throws SQLException {
72       return getBinaryStream();
73    }
74
75    public long position(String JavaDoc searchstr, long start) throws SQLException {
76       initialize();
77       String JavaDoc targetString = new String JavaDoc(getBytes(start,lengthOfBlob-(int)start));
78       return targetString.indexOf(searchstr);
79    }
80
81    public long position(Clob searchstr, long start) throws SQLException {
82       try {
83         return position(((DClob)searchstr).getSubString(start,(int)(searchstr.length()-start)),0);
84       }catch(DException ex){
85         throw ex.getSqlException(null) ;
86       }
87
88    }
89
90    /**
91     * To update string from given position
92     *
93     * @param pos position form where string has to update
94     * @param str new string which has to write
95     *
96     * @return length of string which is updated
97     */

98
99    public int setString(long pos, String JavaDoc str) throws SQLException{
100       return setBytes(pos,str.getBytes());
101    }
102
103    public int setString(long pos, String JavaDoc str, int offset, int len) throws SQLException {
104       return setString(pos,str.substring(offset,len));
105    }
106
107    public OutputStream setAsciiStream(long pos) throws SQLException {
108       return setBinaryStream(pos);
109    }
110
111    public Writer setCharacterStream(long pos) throws SQLException {
112       return new java.io.OutputStreamWriter JavaDoc(setAsciiStream(pos));
113    }
114
115    public void setStream(InputStream stream) {
116        super.setStream(stream);
117    }
118
119    public String JavaDoc toString(){
120     return "java.sql.Clob";
121 }
122
123
124    public int getDatatype() throws DException{
125        return Datatype.CLOB;
126    }
127
128    public int getLength(){
129     try {
130       return (int) length();
131     }
132     catch (SQLException ex) {
133       return -1;
134     }
135    }
136 }
137
Popular Tags