01: /**
02: * Objective Database Abstraction Layer (ODAL)
03: * Copyright (c) 2004, The ODAL Development Group
04: * All rights reserved.
05: * For definition of the ODAL Development Group please refer to LICENCE.txt file
06: *
07: * Distributable under LGPL license.
08: * See terms of license at gnu.org.
09: */package com.completex.objective.components.persistency.type;
10:
11: import java.io.InputStream;
12: import java.io.Reader;
13: import java.sql.Clob;
14: import java.sql.SQLException;
15:
16: /**
17: * Implementation of java.sql.Clob interface that retrieves whole object allowing for
18: * consistent serialization.
19: *
20: * @author Gennady Krizhevsky
21: */
22: public class DetachedClobImpl extends ClobImpl {
23:
24: public static final DetachedClobImpl NULL_CLOB = new DetachedClobImpl();
25:
26: static {
27: NULL_CLOB.setData("");
28: }
29:
30: public DetachedClobImpl() {
31: }
32:
33: public DetachedClobImpl(Clob clob) throws SQLException {
34: if (clob == null) {
35: throw new SQLException(
36: "Cannot instantiate a DetachedClobImpl "
37: + "object with a null Clob object");
38: }
39: Reader characterReader = clob.getCharacterStream();
40: InputStream asciiStream = clob.getAsciiStream();
41: if (characterReader == null || asciiStream == null) {
42: throw new SQLException(
43: "Invalid Clob object. Calls to getCharacterStream "
44: + "or getAsciiStream return null which cannot be serialized.");
45: }
46:
47: setReader(clob.getCharacterStream());
48: getString();
49: }
50:
51: public DetachedClobImpl(String data, String charsetName)
52: throws SQLException {
53: super (data, charsetName);
54: getString();
55: }
56:
57: public DetachedClobImpl(String data) throws SQLException {
58: super (data);
59: getString();
60: }
61:
62: public DetachedClobImpl(Reader reader, String charsetName)
63: throws SQLException {
64: super (reader, charsetName);
65: getString();
66: }
67:
68: public DetachedClobImpl(Reader reader) throws SQLException {
69: super (reader);
70: getString();
71: }
72:
73: public DetachedClobImpl(InputStream inputStream, String charsetName)
74: throws SQLException {
75: super (inputStream, charsetName);
76: getString();
77: }
78:
79: public DetachedClobImpl(InputStream inputStream)
80: throws SQLException {
81: super(inputStream);
82: getString();
83: }
84: }
|