001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029: package com.caucho.db.sql;
030:
031: import com.caucho.db.store.BlobInputStream;
032: import com.caucho.db.store.Store;
033: import com.caucho.util.L10N;
034:
035: import java.io.InputStream;
036: import java.io.OutputStream;
037: import java.sql.Blob;
038: import java.sql.SQLException;
039:
040: /**
041: * The JDBC blob implementation.
042: */
043: public class BlobImpl implements java.sql.Blob {
044: private static final L10N L = new L10N(BlobImpl.class);
045:
046: private Store _store;
047: private byte[] _inode = new byte[128];
048:
049: BlobImpl() {
050: }
051:
052: void setStore(Store store) {
053: _store = store;
054: }
055:
056: byte[] getInode() {
057: return _inode;
058: }
059:
060: /**
061: * Returns the blob as a stream.
062: */
063: public InputStream getBinaryStream() throws SQLException {
064: return new BlobInputStream(_store, _inode, 0);
065: }
066:
067: /**
068: * Returns a subset of the bytes.
069: */
070: public byte[] getBytes(long pos, int length) throws SQLException {
071: throw new UnsupportedOperationException();
072: }
073:
074: /**
075: * Returns the length of the blob
076: */
077: public long length() throws SQLException {
078: return BlobInputStream.readLong(_inode, 0);
079: }
080:
081: /**
082: * Returns the position in the blob where the pattern starts.
083: */
084: public long position(Blob pattern, long start) throws SQLException {
085: throw new UnsupportedOperationException();
086: }
087:
088: /**
089: * Returns the position in the blob where the pattern starts.
090: */
091: public long position(byte[] pattern, long start)
092: throws SQLException {
093: throw new UnsupportedOperationException();
094: }
095:
096: /**
097: * Returns a stream to write to the blob.
098: */
099: public OutputStream setBinaryStream(long pos) throws SQLException {
100: throw new UnsupportedOperationException();
101: }
102:
103: /**
104: * Sets a subset of bytes.
105: */
106: public int setBytes(long pos, byte[] bytes) throws SQLException {
107: return setBytes(pos, bytes, 0, bytes.length);
108: }
109:
110: /**
111: * Sets a subset of bytes.
112: */
113: public int setBytes(long pos, byte[] bytes, int offset, int length)
114: throws SQLException {
115: throw new UnsupportedOperationException();
116: }
117:
118: /**
119: * Truncates the blob
120: */
121: public void truncate(long length) throws SQLException {
122: throw new UnsupportedOperationException();
123: }
124:
125: public String toString() {
126: return "BlobImpl[]";
127: }
128:
129: public void free() throws SQLException {
130: throw new UnsupportedOperationException("Not supported yet.");
131: }
132:
133: public InputStream getBinaryStream(long pos, long length)
134: throws SQLException {
135: throw new UnsupportedOperationException("Not supported yet.");
136: }
137: }
|