1 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.types.DataValueDescriptor; 29 import org.apache.derby.iapi.types.BooleanDataValue; 30 import org.apache.derby.iapi.reference.SQLState; 31 32 import org.apache.derby.iapi.types.Orderable; 33 34 import org.apache.derby.iapi.services.io.Storable; 35 import org.apache.derby.iapi.services.io.FormatIdUtil; 36 import org.apache.derby.iapi.services.io.StoredFormatIds; 37 38 import org.apache.derby.iapi.error.StandardException; 39 import org.apache.derby.iapi.services.sanity.SanityManager; 40 41 import org.apache.derby.iapi.util.StringUtil; 42 43 import org.apache.derby.iapi.services.i18n.LocaleFinder; 44 45 import java.io.ObjectOutput ; 46 import java.io.ObjectInput ; 47 import java.io.IOException ; 48 import java.io.UTFDataFormatException ; 49 import java.io.EOFException ; 50 import java.sql.Date ; 51 import java.sql.ResultSet ; 52 import java.sql.SQLException ; 53 import java.sql.Time ; 54 import java.sql.Timestamp ; 55 import java.util.Locale ; 56 import java.util.Calendar ; 57 58 69 public class SQLNationalChar 70 extends SQLChar 71 { 72 73 80 81 public String getTypeName() 82 { 83 return TypeId.NATIONAL_CHAR_NAME; 84 } 85 86 89 90 95 public int getTypeFormatId() { 96 return StoredFormatIds.SQL_NATIONAL_CHAR_ID; 97 } 98 99 102 103 104 public DataValueDescriptor getClone() 105 { 106 try 107 { 108 112 return new SQLNationalChar(getString(), getLocaleFinder()); 113 } 114 catch (StandardException se) 115 { 116 if (SanityManager.DEBUG) 117 SanityManager.THROWASSERT("Unexpected exception " + se); 118 return null; 119 } 120 } 121 122 126 public DataValueDescriptor getNewNull() 127 { 128 132 SQLNationalChar result = new SQLNationalChar(); 133 result.setLocaleFinder(getLocaleFinder()); 134 return result; 135 } 136 137 140 141 144 145 148 public SQLNationalChar() 149 { 150 } 151 152 public SQLNationalChar(String val, LocaleFinder localeFinder) 153 { 154 super(val); 155 setLocaleFinder(localeFinder); 156 } 157 158 162 public Date getDate( Calendar cal) throws StandardException 163 { 164 return nationalGetDate(cal); 165 } 166 167 171 public Time getTime( Calendar cal) throws StandardException 172 { 173 return nationalGetTime(cal); 174 } 175 176 180 public Timestamp getTimestamp( Calendar cal) throws StandardException 181 { 182 return nationalGetTimestamp(cal); 183 } 184 185 190 public void setValue(Date theValue, Calendar cal) throws StandardException 191 { 192 setValue(getDateFormat( cal).format(theValue)); 193 } 194 195 200 public void setValue(Time theValue, Calendar cal) throws StandardException 201 { 202 setValue(getTimeFormat( cal).format(theValue)); 203 } 204 205 210 public void setValue(Timestamp theValue, Calendar cal) throws StandardException 211 { 212 setValue(getTimestampFormat(cal).format(theValue)); 213 } 214 215 218 219 220 public int typePrecedence() 221 { 222 return TypeId.NATIONAL_CHAR_PRECEDENCE; 223 } 224 225 226 233 protected int stringCompare(SQLChar char1, SQLChar char2) 234 throws StandardException 235 { 236 return char1.stringCollatorCompare(char2); 237 } 238 239 245 protected StringDataValue getNewVarchar() throws StandardException 246 { 247 SQLNationalVarchar result = new SQLNationalVarchar(); 248 result.setLocaleFinder(getLocaleFinder()); 249 return result; 250 } 251 252 264 265 public void normalize( 266 DataTypeDescriptor desiredType, 267 DataValueDescriptor source) 268 throws StandardException 269 { 270 271 normalize(desiredType, ((DataType) source).getNationalString(getLocaleFinder())); 272 273 } 274 protected void setFrom(DataValueDescriptor theValue) throws StandardException { 275 276 setValue(((DataType) theValue).getNationalString(getLocaleFinder())); 277 } 278 279 282 protected boolean isNationalString() 283 { 284 return true; 285 } 286 287 288 public int hashCode() 289 { 290 return nationalHashCode(); 291 } 292 } 293 | Popular Tags |