Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/apache/derby/iapi/types/SQLNClob.java


1   /*
2   
3      Derby - Class org.apache.derby.iapi.types.SQLNClob
4   
5      Copyright 2003, 2004 The Apache Software Foundation or its licensors, as applicable.
6   
7      Licensed under the Apache License, Version 2.0 (the "License");
8      you may not use this file except in compliance with the License.
9      You may obtain a copy of the License at
10  
11        http://www.apache.org/licenses/LICENSE-2.0
12  
13     Unless required by applicable law or agreed to in writing, software
14     distributed under the License is distributed on an "AS IS" BASIS,
15     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16     See the License for the specific language governing permissions and
17     limitations under the License.
18  
19   */
20  
21  package org.apache.derby.iapi.types;
22  
23  import org.apache.derby.iapi.types.DataTypeDescriptor;
24  import org.apache.derby.iapi.types.DataValueDescriptor;
25  import org.apache.derby.iapi.types.TypeId;
26  import org.apache.derby.iapi.types.StringDataValue;
27  import org.apache.derby.iapi.reference.SQLState;
28  import org.apache.derby.iapi.error.StandardException;
29  
30  import org.apache.derby.iapi.services.io.FormatIdUtil;
31  import org.apache.derby.iapi.services.io.StoredFormatIds;
32  
33  import org.apache.derby.iapi.services.sanity.SanityManager;
34  
35  import org.apache.derby.iapi.services.i18n.LocaleFinder;
36  
37  import java.util.Locale;
38  
39  import java.sql.Date;
40  import java.sql.Time;
41  import java.sql.Timestamp;
42  import java.util.Calendar;
43  
44  /**
45   * SQLNClob satisfies the DataValueDescriptor interfaces (i.e., OrderableDataType). It implements a String
46   * holder, e.g. for storing a column value; it can be specified
47   * when constructed to not allow nulls. Nullability cannot be changed
48   * after construction.
49   * <p>
50   *** ----- TODO: fix for NCLOB
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   *** ----- TODO: fix for NCLOB
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 SQLNClob
60          extends SQLNationalVarchar
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 getTypeName()
71          {
72                  return TypeId.NCLOB_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 SQLNClob(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                 SQLNClob result = new SQLNClob();
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_NCLOB_ID;
124         }
125 
126         /*
127          * constructors
128          */
129 
130         public SQLNClob()
131         {
132         }
133 
134         public SQLNClob(String val, LocaleFinder localeFinder)
135         {
136                 super(val, localeFinder);
137         }
138 
139         /**
140          * @see DataValueDescriptor#getDate
141          * @exception StandardException thrown on failure to convert
142          */
143         public Date     getDate( Calendar cal) throws StandardException
144         {
145                 return nationalGetDate(cal);
146         }
147 
148         /**
149          * @see DataValueDescriptor#getTime
150          * @exception StandardException thrown on failure to convert
151          */
152         public Time getTime( Calendar cal) throws StandardException
153         {
154                 return nationalGetTime(cal);
155         }
156 
157         /**
158          * @see DataValueDescriptor#getTimestamp
159          * @exception StandardException thrown on failure to convert
160          */
161         public Timestamp getTimestamp( Calendar cal) throws StandardException
162         {
163                 return nationalGetTimestamp(cal);
164         }
165 
166         /*
167          * DataValueDescriptor interface
168          */
169 
170         /* @see DataValueDescriptor#typePrecedence */
171         public int typePrecedence()
172         {
173                 return TypeId.NCLOB_PRECEDENCE;
174         }
175 
176         /** 
177      ****  ---- TODO: Disable?
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 theValue, Calendar 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 theValue, Calendar 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 theValue, Calendar 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 }