001: /**
002: * com.mckoi.database.jdbc.MStreamableClob 31 Jan 2003
003: *
004: * Mckoi SQL Database ( http://www.mckoi.com/database )
005: * Copyright (C) 2000, 2001, 2002 Diehl and Associates, Inc.
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * Version 2 as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License Version 2 for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * Version 2 along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: * Change Log:
021: *
022: *
023: */package com.mckoi.database.jdbc;
024:
025: import java.io.*;
026: import java.sql.Clob;
027: import java.sql.SQLException;
028:
029: /**
030: * A Clob that is a large object that may be streamed from the server directly
031: * to this object. A clob that is streamable is only alive for the lifetime of
032: * the result set it is part of. If the underlying result set that contains
033: * this streamable clob is closed then this clob is no longer valid.
034: *
035: * @author Tobias Downer
036: */
037:
038: class MStreamableClob extends AbstractStreamableObject implements Clob {
039:
040: /**
041: * Constructs the Clob.
042: */
043: MStreamableClob(MConnection connection, int result_set_id,
044: byte type, long streamable_object_id, long size) {
045: super (connection, result_set_id, type, streamable_object_id,
046: size);
047: }
048:
049: // ---------- Implemented from Blob ----------
050:
051: public long length() throws SQLException {
052: if (getType() == 4) {
053: return rawSize() / 2;
054: }
055: return rawSize();
056: }
057:
058: public String getSubString(long pos, int length)
059: throws SQLException {
060: int p = (int) (pos - 1);
061: Reader reader = getCharacterStream();
062: try {
063: reader.skip(p);
064: StringBuffer buf = new StringBuffer(length);
065: for (int i = 0; i < length; ++i) {
066: int c = reader.read();
067: buf.append((char) c);
068: }
069: return new String(buf);
070: } catch (IOException e) {
071: e.printStackTrace(System.err);
072: throw new SQLException("IO Error: " + e.getMessage());
073: }
074: }
075:
076: public Reader getCharacterStream() throws SQLException {
077: if (getType() == 3) {
078: return new AsciiReader(new StreamableObjectInputStream(
079: rawSize()));
080: } else if (getType() == 4) {
081: return new BinaryToUnicodeReader(
082: new StreamableObjectInputStream(rawSize()));
083: } else {
084: throw new SQLException("Unknown type.");
085: }
086: }
087:
088: public java.io.InputStream getAsciiStream() throws SQLException {
089: if (getType() == 3) {
090: return new StreamableObjectInputStream(rawSize());
091: } else if (getType() == 4) {
092: return new AsciiInputStream(getCharacterStream());
093: } else {
094: throw new SQLException("Unknown type.");
095: }
096: }
097:
098: public long position(String searchstr, long start)
099: throws SQLException {
100: throw MSQLException.unsupported();
101: }
102:
103: public long position(Clob searchstr, long start)
104: throws SQLException {
105: throw MSQLException.unsupported();
106: }
107:
108: //#IFDEF(JDBC3.0)
109:
110: //---------------------------- JDBC 3.0 -----------------------------------
111:
112: public int setString(long pos, String str) throws SQLException {
113: throw MSQLException.unsupported();
114: }
115:
116: public int setString(long pos, String str, int offset, int len)
117: throws SQLException {
118: throw MSQLException.unsupported();
119: }
120:
121: public java.io.OutputStream setAsciiStream(long pos)
122: throws SQLException {
123: throw MSQLException.unsupported();
124: }
125:
126: public java.io.Writer setCharacterStream(long pos)
127: throws SQLException {
128: throw MSQLException.unsupported();
129: }
130:
131: public void truncate(long len) throws SQLException {
132: throw MSQLException.unsupported();
133: }
134:
135: //#ENDIF
136:
137: }
|