KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Additional SSL Support
9  * Douglas Hammond(djhammond@sympatico.ca)
10  */

11
12 package org.objectweb.rmijdbc;
13
14 import java.sql.*;
15 import java.io.IOException JavaDoc;
16 import java.io.InputStream JavaDoc;
17 import java.rmi.RemoteException JavaDoc;
18 import java.rmi.server.UnicastRemoteObject JavaDoc;
19 import java.rmi.server.Unreferenced JavaDoc;
20
21
22 /**
23  * The representation (mapping) in the JavaTM programming language of an
24  * SQL BLOB. An SQL BLOB is
25  * a built-in type that stores a Binary Large Object as a column value in
26  * a row of a database table. The
27  * driver implements Blob using an SQL locator(BLOB), which means that
28  * a Blob object contains a logical pointer to the SQL BLOB data rather
29  * than the data itself. A Blob object is valid for
30  * the duration of the transaction in which is was created.
31  *
32  * Methods in the interfaces ResultSet, CallableStatement, and
33  * PreparedStatement, such as getBlob and setBlob allow a programmer
34  * to access the SQL BLOB. The Blob interface provides methods for getting
35  * the length of an SQL BLOB (Binary Large Object) value, for
36  * materializing a BLOB value on the client, and for determining the position
37  * of a pattern of bytes within a BLOB value.
38  */

39
40 public class RJBlobServer
41 extends UnicastRemoteObject JavaDoc
42 implements RJBlobInterface, Unreferenced JavaDoc {
43
44   java.sql.Blob JavaDoc jdbcBlob_;
45
46   public RJBlobServer(java.sql.Blob JavaDoc b) throws RemoteException JavaDoc {
47        super(RJJdbcServer.rmiJdbcListenerPort, RJJdbcServer.rmiClientSocketFactory, RJJdbcServer.rmiServerSocketFactory);
48     jdbcBlob_ = b;
49   }
50
51   public void unreferenced() { Runtime.getRuntime().gc(); }
52
53   public long length() throws RemoteException JavaDoc, SQLException {
54     return jdbcBlob_.length();
55   }
56
57   public byte[] getBytes(long pos, int length)
58   throws RemoteException JavaDoc, SQLException {
59     return jdbcBlob_.getBytes(pos, length);
60   }
61
62 // TBD There's a hack there (InputStream not serializable)
63
// public InputStream getBinaryStream() throws RemoteException, SQLException {
64
public byte[] getBinaryStream() throws RemoteException JavaDoc, SQLException {
65     try {
66       InputStream JavaDoc s = jdbcBlob_.getBinaryStream();
67       return RJSerializer.toByteArray(s);
68     } catch(IOException JavaDoc e) {
69       throw new java.rmi.RemoteException JavaDoc(
70        "RJBlobServer::getBinaryStream()", e);
71     }
72   }
73
74   public long position(byte[] pattern, long start)
75   throws RemoteException JavaDoc, SQLException {
76     return jdbcBlob_.position(pattern, start);
77   }
78
79   public long position(Blob pattern, long start)
80   throws RemoteException JavaDoc, SQLException {
81     return jdbcBlob_.position(pattern, start);
82   }
83
84   // -------------------------- JDBC 3.0 -----------------------------------
85

86   public int setBytes(long pos, byte[] bytes) throws RemoteException JavaDoc, SQLException {
87     return jdbcBlob_.setBytes(pos, bytes);
88   }
89
90   public int setBytes(long pos, byte[] bytes, int offset, int len) throws RemoteException JavaDoc, SQLException {
91     return jdbcBlob_.setBytes(pos, bytes, offset, len);
92   }
93
94   public java.io.OutputStream JavaDoc setBinaryStream(long pos) throws RemoteException JavaDoc, SQLException {
95     return jdbcBlob_.setBinaryStream(pos);
96   }
97
98   public void truncate(long len) throws RemoteException JavaDoc, SQLException {
99     jdbcBlob_.truncate(len);
100   }
101
102 };
103
104
Popular Tags