KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.iapi.types.SQLNationalLongvarchar
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 import java.util.Calendar JavaDoc;
40
41 import java.sql.Date JavaDoc;
42 import java.sql.Time JavaDoc;
43 import java.sql.Timestamp JavaDoc;
44
45 /**
46  * SQLNationalLongvarchar 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  * Because OrderableDataType is a subclass of DataType,
52  * SQLNationalLongvarchar can play a role in either a DataType/ValueRow
53  * or a OrderableDataType/KeyRow, interchangeably.
54  *
55  * SQLNationalLongvarchar is mostly the same as SQLLongvarchar, so it is implemented as a
56  * subclass of SQLLongvarchar. Only those methods with different behavior are
57  * implemented here.
58  */

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

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

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

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

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

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

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

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

129
130     public SQLNationalLongvarchar()
131     {
132     }
133
134     public SQLNationalLongvarchar(String JavaDoc val, LocaleFinder localeFinder)
135     {
136         super(val);
137         setLocaleFinder(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.NATIONAL_LONGVARCHAR_PRECEDENCE;
175     }
176
177     /**
178      * Compare two SQLChars. This method will be overriden in the
179      * National char wrappers so that the appropriate comparison
180      * is done.
181      *
182      * @exception StandardException Thrown on error
183      */

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

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

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

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

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

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