001: package net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent;
002:
003: /*
004: * Copyright (C) 2001-2004 Colin Bell
005: * colbell@users.sourceforge.net
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021: import java.sql.Clob;
022:
023: import net.sourceforge.squirrel_sql.fw.util.StringManager;
024: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
025:
026: /**
027: * @author gwg
028: *
029: * This is the object that is actually stored in the ContentsTab table
030: * for a CLOB field.
031: * The data in a CLOB is handled differently than other data types.
032: * When the row in the DB is read, what is returned is actually a
033: * java.sql.Clob object that points to the data rather than the data itself.
034: * Since CLOBs can be very large (and thus take a long time to read), we
035: * provide the user the flexibility to read only part of the CLOB data, or
036: * to not read any of it. We use the user selected options in various operations
037: * such as deciding if the field is editable or not.
038: * These options are set in the Session Parameters,
039: * and since those parameters can be changed after the data has been read, we
040: * make a copy of the appropriate information here.
041: */
042: public class ClobDescriptor {
043:
044: /**
045: * The java.sql.Clob object that was read.
046: */
047: Clob _clob;
048:
049: /**
050: * The data read from the Clob.
051: */
052: String _data = null;
053:
054: /**
055: * If <TT>_clobRead</TT> is <TT>true</TT> then at least some
056: * of the data in the CLOB should have been read. If <TT>false</TT>,
057: * then we have not even tried to read the data.
058: */
059: private boolean _clobRead = false;
060:
061: /**
062: * If <TT>_wholeClobRead</TT> is <TT>true</TT> then all of the
063: * data in this CLOB has been read into _data..
064: */
065: private boolean _wholeClobRead = false;
066:
067: /**
068: * If <TT>_wholeClobRead</TT> is false, this is the size limit
069: * set by the user for how much to read.
070: */
071: private int _userSetClobLimit;
072:
073: /** Internationalized strings for this class. */
074: private static final StringManager s_stringMgr = StringManagerFactory
075: .getStringManager(ClobDescriptor.class);
076:
077: public static interface i18n {
078: String CLOB_LABEL = s_stringMgr
079: .getString("ClobDescriptor.clob");
080: }
081:
082: /**
083: * Ctor
084: */
085: public ClobDescriptor(Clob clob, String data, boolean clobRead,
086: boolean wholeClobRead, int userSetClobLimit) {
087: _clob = clob;
088: _data = data;
089: _clobRead = clobRead;
090: _wholeClobRead = wholeClobRead;
091: _userSetClobLimit = userSetClobLimit;
092: }
093:
094: /**
095: * Equals for Clobs means that the internal strings are identical,
096: * including their length.
097: * We need to account for the fact that one or both of them may not
098: * have actually had their data read. If both have not had their data read,
099: * then they are "equal", in a wierd kind of way.
100: */
101: public boolean equals(ClobDescriptor c) {
102: if (c == null) {
103: // the other obj is null, so see if this non-null obj contains
104: // a null value, which is equivilent.
105: // Assume that if we have read some of the data and we still have
106: // _data == null, then the value in the DB is actually null.
107: if (_clobRead == true && _data == null)
108: return true;
109: else
110: return false;
111: }
112:
113: if (c.getClobRead() == false) {
114: // the other obj has not read the data yet.
115: if (_clobRead == true)
116: return false; // we have read data, so that is not the same state
117: else
118: return true; // odd-ball case: assume if neither has read data that they are equal
119: }
120:
121: // the other object has real data
122: if (_clobRead == false)
123: return false; // this one does not, so they are not equal
124:
125: // both have actual data, so compare the strings
126: // Note that if one has read all of the data and the other has read only part
127: // of the data that we will say that they are NOT equal.
128: return c.getData().equals(_data);
129: }
130:
131: /**
132: * toString means print the data string, unless the data has not been
133: * read at all.
134: */
135: public String toString() {
136: if (_clobRead) {
137: if (_data == null) {
138: return s_stringMgr.getString("ClobDescriptor.null");
139: }
140: if (_wholeClobRead || _userSetClobLimit > _data.length()) {
141: return _data; // we have the whole contents of the CLOB
142: }
143: return _data + "..."; // tell user the data is truncated
144: }
145: return i18n.CLOB_LABEL;
146: }
147:
148: /*
149: * Getters and Setters
150: */
151:
152: public Clob getClob() {
153: return _clob;
154: }
155:
156: public void setClob(Clob clob) {
157: _clob = clob;
158: }
159:
160: public String getData() {
161: return _data;
162: }
163:
164: public void setData(String data) {
165: _data = data;
166: }
167:
168: public boolean getClobRead() {
169: return _clobRead;
170: }
171:
172: public void setClobRead(boolean clobRead) {
173: _clobRead = clobRead;
174: }
175:
176: public boolean getWholeClobRead() {
177: return _wholeClobRead;
178: }
179:
180: public void setWholeClobRead(boolean wholeClobRead) {
181: _wholeClobRead = wholeClobRead;
182: }
183:
184: public int getUserSetClobLimit() {
185: return _userSetClobLimit;
186: }
187:
188: public void setUserSetClobLimit(int userSetClobLimit) {
189: _userSetClobLimit = userSetClobLimit;
190: }
191:
192: }
|