001: /*
002:
003: Derby - Class org.apache.derby.iapi.types.SQLNClob
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.iapi.types;
023:
024: import org.apache.derby.iapi.types.DataTypeDescriptor;
025: import org.apache.derby.iapi.types.DataValueDescriptor;
026: import org.apache.derby.iapi.types.TypeId;
027: import org.apache.derby.iapi.types.StringDataValue;
028: import org.apache.derby.iapi.reference.SQLState;
029: import org.apache.derby.iapi.error.StandardException;
030:
031: import org.apache.derby.iapi.services.io.FormatIdUtil;
032: import org.apache.derby.iapi.services.io.StoredFormatIds;
033:
034: import org.apache.derby.iapi.services.sanity.SanityManager;
035:
036: import org.apache.derby.iapi.services.i18n.LocaleFinder;
037:
038: import java.util.Locale;
039:
040: import java.sql.Date;
041: import java.sql.Time;
042: import java.sql.Timestamp;
043: import java.util.Calendar;
044:
045: /**
046: * SQLNClob satisfies the DataValueDescriptor interfaces (i.e., OrderableDataType). It implements a String
047: * holder, e.g. for storing a column value; it can be specified
048: * when constructed to not allow nulls. Nullability cannot be changed
049: * after construction.
050: * <p>
051: *** ----- TODO: fix for NCLOB
052: * Because OrderableDataType is a subclass of DataType,
053: * SQLNationalLongvarchar can play a role in either a DataType/ValueRow
054: * or a OrderableDataType/KeyRow, interchangeably.
055: *** ----- TODO: fix for NCLOB
056: * SQLNationalLongvarchar is mostly the same as SQLLongvarchar, so it is implemented as a
057: * subclass of SQLLongvarchar. Only those methods with different behavior are
058: * implemented here.
059: */
060: public class SQLNClob extends SQLNationalVarchar {
061: /*
062: * DataValueDescriptor interface.
063: *
064: * These are actually all implemented in the super-class, but we need
065: * to duplicate some of them here so they can be called by byte-code
066: * generation, which needs to know the class the method appears in.
067: */
068:
069: public String getTypeName() {
070: return TypeId.NCLOB_NAME;
071: }
072:
073: /*
074: * DataValueDescriptor interface
075: */
076:
077: /** @see DataValueDescriptor#getClone */
078: public DataValueDescriptor getClone() {
079: try {
080: /* NOTE: We pass instance variables for locale info
081: * because we only call methods when we know that we
082: * will need locale info.
083: */
084: return new SQLNClob(getString(), getLocaleFinder());
085: } catch (StandardException se) {
086: if (SanityManager.DEBUG)
087: SanityManager.THROWASSERT("Unexpected exception " + se);
088: return null;
089: }
090: }
091:
092: /**
093: * @see DataValueDescriptor#getNewNull
094: *
095: */
096: public DataValueDescriptor getNewNull() {
097: /* NOTE: We pass instance variables for locale info
098: * because we only call methods when we know that we
099: * will need locale info.
100: */
101: SQLNClob result = new SQLNClob();
102: result.setLocaleFinder(getLocaleFinder());
103: return result;
104: }
105:
106: /*
107: * Storable interface, implies Externalizable, TypedFormat
108: */
109:
110: /**
111: Return my format identifier.
112:
113: @see org.apache.derby.iapi.services.io.TypedFormat#getTypeFormatId
114: */
115: public int getTypeFormatId() {
116: return StoredFormatIds.SQL_NCLOB_ID;
117: }
118:
119: /*
120: * constructors
121: */
122:
123: public SQLNClob() {
124: }
125:
126: public SQLNClob(String val, LocaleFinder localeFinder) {
127: super (val, localeFinder);
128: }
129:
130: /**
131: * @see DataValueDescriptor#getDate
132: * @exception StandardException thrown on failure to convert
133: */
134: public Date getDate(Calendar cal) throws StandardException {
135: return nationalGetDate(cal);
136: }
137:
138: /**
139: * @see DataValueDescriptor#getTime
140: * @exception StandardException thrown on failure to convert
141: */
142: public Time getTime(Calendar cal) throws StandardException {
143: return nationalGetTime(cal);
144: }
145:
146: /**
147: * @see DataValueDescriptor#getTimestamp
148: * @exception StandardException thrown on failure to convert
149: */
150: public Timestamp getTimestamp(Calendar cal)
151: throws StandardException {
152: return nationalGetTimestamp(cal);
153: }
154:
155: /*
156: * DataValueDescriptor interface
157: */
158:
159: /* @see DataValueDescriptor#typePrecedence */
160: public int typePrecedence() {
161: return TypeId.NCLOB_PRECEDENCE;
162: }
163:
164: /**
165: **** ---- TODO: Disable?
166: * Compare two SQLChars. This method will be overriden in the
167: * National char wrappers so that the appropriate comparison
168: * is done.
169: *
170: * @exception StandardException Thrown on error
171: */
172: protected int stringCompare(SQLChar char1, SQLChar char2)
173: throws StandardException {
174: return char1.stringCollatorCompare(char2);
175: }
176:
177: /**
178: * Get a SQLVarchar for a built-in string function.
179: * (Could be either a SQLVarchar or SQLNationalVarchar.)
180: *
181: * @return a SQLVarchar or SQLNationalVarchar.
182: */
183: protected StringDataValue getNewVarchar() {
184: return new SQLNationalVarchar();
185: }
186:
187: /**
188: * Return whether or not this is a national character datatype.
189: */
190: protected boolean isNationalString() {
191: return true;
192: }
193:
194: /**
195: * @see DataValueDescriptor#setValue
196: *
197: * @exception StandardException Thrown on error
198: */
199: public void setValue(Date theValue, Calendar cal)
200: throws StandardException {
201: setValue(getDateFormat(cal).format(theValue));
202: }
203:
204: /**
205: * @see DataValueDescriptor#setValue
206: *
207: * @exception StandardException Thrown on error
208: */
209: public void setValue(Time theValue, Calendar cal)
210: throws StandardException {
211: setValue(getTimeFormat(cal).format(theValue));
212: }
213:
214: /**
215: * @see DataValueDescriptor#setValue
216: *
217: * @exception StandardException Thrown on error
218: */
219: public void setValue(Timestamp theValue, Calendar cal)
220: throws StandardException {
221: setValue(getTimestampFormat(cal).format(theValue));
222: }
223:
224: protected void setFrom(DataValueDescriptor theValue)
225: throws StandardException {
226:
227: setValue(((DataType) theValue)
228: .getNationalString(getLocaleFinder()));
229: }
230:
231: /** @see java.lang.Object#hashCode */
232: public int hashCode() {
233: return nationalHashCode();
234: }
235: }
|