KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > rmijdbc > RJClob


1
2 /**
3  * RmiJdbc client/server JDBC Driver
4  * (C) ExperLog 1999-2000
5  *
6  * @version 1.0
7  * @author Pierre-Yves Gibello (pierreyves.gibello@experlog.com)
8  */

9
10 package org.objectweb.rmijdbc;
11
12 import java.sql.*;
13 import java.io.InputStream JavaDoc;
14 import java.io.Reader JavaDoc;
15 import java.rmi.RemoteException JavaDoc;
16
17 public class RJClob implements java.sql.Clob JavaDoc, java.io.Serializable JavaDoc
18 {
19
20   RJClobInterface rmiClob_;
21
22   public RJClob(RJClobInterface b) {
23     rmiClob_ = b;
24   }
25
26 // TBD There's a hack there (Reader not serializable)
27
public Reader JavaDoc getCharacterStream() throws SQLException {
28     try {
29       char[] val = rmiClob_.getCharacterStream();
30       return RJSerializer.toReader(val);
31     } catch(Exception JavaDoc e) {
32       throw new java.sql.SQLException JavaDoc(e.getMessage());
33     }
34   }
35   public long length() throws SQLException {
36     try {
37       return rmiClob_.length();
38     } catch(RemoteException JavaDoc e) {
39       throw new java.sql.SQLException JavaDoc(e.getMessage());
40     }
41   }
42
43   public String JavaDoc getSubString(long pos, int length) throws SQLException {
44     try {
45       return rmiClob_.getSubString(pos, length);
46     } catch(RemoteException JavaDoc e) {
47       throw new java.sql.SQLException JavaDoc(e.getMessage());
48     }
49   }
50
51 // TBD There's a hack there (InputStream not serializable)
52
public InputStream JavaDoc getAsciiStream() throws SQLException {
53     try {
54       byte[] val = rmiClob_.getAsciiStream();
55       return RJSerializer.toInputStream(val);
56     } catch(Exception JavaDoc e) {
57       throw new java.sql.SQLException JavaDoc(e.getMessage());
58     }
59   }
60
61   public long position(String JavaDoc searchstr, long start) throws SQLException {
62     try {
63       return rmiClob_.position(searchstr, start);
64     } catch(RemoteException JavaDoc e) {
65       throw new java.sql.SQLException JavaDoc(e.getMessage());
66     }
67   }
68
69   public long position(Clob searchstr, long start) throws SQLException {
70     try {
71       // Serialize the blob by calling its getBytes() method, then call the
72
// other position() method - the one that receives a byte array.
73
return rmiClob_.position(searchstr.getSubString(0, (int)searchstr.length()), start);
74     } catch(Exception JavaDoc e) {
75       throw new java.sql.SQLException JavaDoc(e.getMessage());
76     }
77   }
78
79 //---------------------------- jdbc 3.0 -----------------------------------
80
public int setString(long pos, String JavaDoc str)
81   throws SQLException
82   {
83     try {
84       return rmiClob_.setString(pos, str);
85     } catch(Exception JavaDoc e) {
86       throw new java.sql.SQLException JavaDoc(e.getMessage());
87     }
88   }
89
90   public int setString(long pos, String JavaDoc str, int offset, int len)
91   throws SQLException
92   {
93     try {
94       return rmiClob_.setString(pos, str, offset, len);
95     } catch(Exception JavaDoc e) {
96       throw new java.sql.SQLException JavaDoc(e.getMessage());
97     }
98   }
99   
100
101   public java.io.OutputStream JavaDoc setAsciiStream(long pos)
102   throws SQLException
103   {
104     try {
105       return rmiClob_.setAsciiStream(pos);
106     } catch(Exception JavaDoc e) {
107       throw new java.sql.SQLException JavaDoc(e.getMessage());
108     }
109   }
110
111   public java.io.Writer JavaDoc setCharacterStream(long pos)
112   throws SQLException
113   {
114     try {
115       return rmiClob_.setCharacterStream(pos);
116     } catch(Exception JavaDoc e) {
117       throw new java.sql.SQLException JavaDoc(e.getMessage());
118     }
119   }
120
121   public void truncate(long len)
122   throws SQLException
123   {
124     try {
125       rmiClob_.truncate(len);
126     } catch(Exception JavaDoc e) {
127       throw new java.sql.SQLException JavaDoc(e.getMessage());
128     }
129   }
130
131 };
132
133
Popular Tags