KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > iapi > types > SQLNClob


1 /*
2
3    Derby - Class org.apache.derby.iapi.types.SQLNClob
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.iapi.types;
23
24 import org.apache.derby.iapi.types.DataTypeDescriptor;
25 import org.apache.derby.iapi.types.DataValueDescriptor;
26 import org.apache.derby.iapi.types.TypeId;
27 import org.apache.derby.iapi.types.StringDataValue;
28 import org.apache.derby.iapi.reference.SQLState;
29 import org.apache.derby.iapi.error.StandardException;
30
31 import org.apache.derby.iapi.services.io.FormatIdUtil;
32 import org.apache.derby.iapi.services.io.StoredFormatIds;
33
34 import org.apache.derby.iapi.services.sanity.SanityManager;
35
36 import org.apache.derby.iapi.services.i18n.LocaleFinder;
37
38 import java.util.Locale JavaDoc;
39
40 import java.sql.Date JavaDoc;
41 import java.sql.Time JavaDoc;
42 import java.sql.Timestamp JavaDoc;
43 import java.util.Calendar JavaDoc;
44
45 /**
46  * SQLNClob satisfies the DataValueDescriptor interfaces (i.e., OrderableDataType). It implements a String
47  * holder, e.g. for storing a column value; it can be specified
48  * when constructed to not allow nulls. Nullability cannot be changed
49  * after construction.
50  * <p>
51  *** ----- TODO: fix for NCLOB
52  * Because OrderableDataType is a subclass of DataType,
53  * SQLNationalLongvarchar can play a role in either a DataType/ValueRow
54  * or a OrderableDataType/KeyRow, interchangeably.
55  *** ----- TODO: fix for NCLOB
56  * SQLNationalLongvarchar is mostly the same as SQLLongvarchar, so it is implemented as a
57  * subclass of SQLLongvarchar. Only those methods with different behavior are
58  * implemented here.
59  */

60 public class SQLNClob
61         extends SQLNationalVarchar
62 {
63         /*
64          * DataValueDescriptor interface.
65          *
66          * These are actually all implemented in the super-class, but we need
67          * to duplicate some of them here so they can be called by byte-code
68          * generation, which needs to know the class the method appears in.
69          */

70
71         public String JavaDoc getTypeName()
72         {
73                 return TypeId.NCLOB_NAME;
74         }
75
76         /*
77          * DataValueDescriptor interface
78          */

79
80         /** @see DataValueDescriptor#getClone */
81         public DataValueDescriptor getClone()
82         {
83                 try
84                 {
85                         /* NOTE: We pass instance variables for locale info
86                          * because we only call methods when we know that we
87                          * will need locale info.
88                          */

89                         return new SQLNClob(getString(), getLocaleFinder());
90                 }
91                 catch (StandardException se)
92                 {
93                         if (SanityManager.DEBUG)
94                                 SanityManager.THROWASSERT("Unexpected exception " + se);
95                         return null;
96                 }
97         }
98
99         /**
100          * @see DataValueDescriptor#getNewNull
101          *
102          */

103         public DataValueDescriptor getNewNull()
104         {
105                 /* NOTE: We pass instance variables for locale info
106                  * because we only call methods when we know that we
107                  * will need locale info.
108                  */

109                 SQLNClob result = new SQLNClob();
110                 result.setLocaleFinder(getLocaleFinder());
111                 return result;
112         }
113
114         /*
115          * Storable interface, implies Externalizable, TypedFormat
116          */

117
118         /**
119                 Return my format identifier.
120
121                 @see org.apache.derby.iapi.services.io.TypedFormat#getTypeFormatId
122         */

123         public int getTypeFormatId() {
124                 return StoredFormatIds.SQL_NCLOB_ID;
125         }
126
127         /*
128          * constructors
129          */

130
131         public SQLNClob()
132         {
133         }
134
135         public SQLNClob(String JavaDoc val, LocaleFinder localeFinder)
136         {
137                 super(val, localeFinder);
138         }
139
140         /**
141          * @see DataValueDescriptor#getDate
142          * @exception StandardException thrown on failure to convert
143          */

144         public Date JavaDoc getDate( Calendar JavaDoc cal) throws StandardException
145         {
146                 return nationalGetDate(cal);
147         }
148
149         /**
150          * @see DataValueDescriptor#getTime
151          * @exception StandardException thrown on failure to convert
152          */

153         public Time JavaDoc getTime( Calendar JavaDoc cal) throws StandardException
154         {
155                 return nationalGetTime(cal);
156         }
157
158         /**
159          * @see DataValueDescriptor#getTimestamp
160          * @exception StandardException thrown on failure to convert
161          */

162         public Timestamp JavaDoc getTimestamp( Calendar JavaDoc cal) throws StandardException
163         {
164                 return nationalGetTimestamp(cal);
165         }
166
167         /*
168          * DataValueDescriptor interface
169          */

170
171         /* @see DataValueDescriptor#typePrecedence */
172         public int typePrecedence()
173         {
174                 return TypeId.NCLOB_PRECEDENCE;
175         }
176
177         /**
178      **** ---- TODO: Disable?
179          * Compare two SQLChars. This method will be overriden in the
180          * National char wrappers so that the appropriate comparison
181          * is done.
182          *
183          * @exception StandardException Thrown on error
184          */

185          protected int stringCompare(SQLChar char1, SQLChar char2)
186                  throws StandardException
187          {
188                  return char1.stringCollatorCompare(char2);
189          }
190
191         /**
192          * Get a SQLVarchar for a built-in string function.
193          * (Could be either a SQLVarchar or SQLNationalVarchar.)
194          *
195          * @return a SQLVarchar or SQLNationalVarchar.
196          */

197         protected StringDataValue getNewVarchar()
198         {
199                 return new SQLNationalVarchar();
200         }
201
202         /**
203          * Return whether or not this is a national character datatype.
204          */

205         protected boolean isNationalString()
206         {
207                 return true;
208         }
209
210         /**
211          * @see DataValueDescriptor#setValue
212          *
213          * @exception StandardException Thrown on error
214          */

215         public void setValue(Date JavaDoc theValue, Calendar JavaDoc cal) throws StandardException
216         {
217                 setValue(getDateFormat(cal).format(theValue));
218         }
219
220         /**
221          * @see DataValueDescriptor#setValue
222          *
223          * @exception StandardException Thrown on error
224          */

225         public void setValue(Time JavaDoc theValue, Calendar JavaDoc cal) throws StandardException
226         {
227                 setValue(getTimeFormat(cal).format(theValue));
228         }
229
230         /**
231          * @see DataValueDescriptor#setValue
232          *
233          * @exception StandardException Thrown on error
234          */

235         public void setValue(Timestamp JavaDoc theValue, Calendar JavaDoc cal) throws StandardException
236         {
237                 setValue(getTimestampFormat(cal).format(theValue));
238         }
239         protected void setFrom(DataValueDescriptor theValue) throws StandardException {
240
241                 setValue(((DataType) theValue).getNationalString(getLocaleFinder()));
242         }
243
244         /** @see java.lang.Object#hashCode */
245         public int hashCode()
246         {
247                 return nationalHashCode();
248         }
249 }
250
Popular Tags