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.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 import org.apache.derby.iapi.util.StringUtil; 36 37 import org.apache.derby.iapi.services.i18n.LocaleFinder; 38 39 import java.sql.Date ; 40 import java.sql.Time ; 41 import java.sql.Timestamp ; 42 43 import java.util.Calendar ; 44 45 60 public class SQLNationalVarchar 61 extends SQLVarchar 62 { 63 64 public String getTypeName() 65 { 66 return TypeId.NATIONAL_VARCHAR_NAME; 67 } 68 69 76 protected int stringCompare(SQLChar char1, SQLChar char2) 77 throws StandardException 78 { 79 return char1.stringCollatorCompare(char2); 80 } 81 82 85 86 87 public DataValueDescriptor getClone() 88 { 89 try 90 { 91 95 return new SQLNationalVarchar(getString(), getLocaleFinder()); 96 } 97 catch (StandardException se) 98 { 99 if (SanityManager.DEBUG) 100 SanityManager.THROWASSERT("Unexpected exception " + se); 101 return null; 102 } 103 } 104 105 109 public DataValueDescriptor getNewNull() 110 { 111 115 SQLNationalVarchar result = new SQLNationalVarchar(); 116 result.setLocaleFinder(getLocaleFinder()); 117 return result; 118 } 119 120 121 124 125 130 public int getTypeFormatId() { 131 return StoredFormatIds.SQL_NATIONAL_VARCHAR_ID; 132 } 133 134 137 138 public SQLNationalVarchar() 139 { 140 } 141 142 public SQLNationalVarchar(String val, LocaleFinder localeFinder) 143 { 144 super(val); 145 setLocaleFinder(localeFinder); 146 } 147 148 152 public Date getDate( Calendar cal) throws StandardException 153 { 154 return nationalGetDate(cal); 155 } 156 157 161 public Time getTime( Calendar cal) throws StandardException 162 { 163 return nationalGetTime(cal); 164 } 165 166 170 public Timestamp getTimestamp( Calendar cal) throws StandardException 171 { 172 return nationalGetTimestamp(cal); 173 } 174 175 178 179 180 public int typePrecedence() 181 { 182 return TypeId.NATIONAL_VARCHAR_PRECEDENCE; 183 } 184 185 191 protected StringDataValue getNewVarchar() 192 { 193 return new SQLNationalVarchar(); 194 } 195 196 199 protected boolean isNationalString() 200 { 201 return true; 202 } 203 204 209 public void setValue(Date theValue, Calendar cal) throws StandardException 210 { 211 setValue(getDateFormat( cal).format(theValue)); 212 } 213 214 219 public void setValue(Time theValue, Calendar cal) throws StandardException 220 { 221 setValue(getTimeFormat( cal).format(theValue)); 222 } 223 224 229 public void setValue(Timestamp theValue, Calendar cal) throws StandardException 230 { 231 setValue(getTimestampFormat(cal).format(theValue)); 232 } 233 234 public void normalize( 235 DataTypeDescriptor desiredType, 236 DataValueDescriptor source) 237 throws StandardException 238 { 239 normalize(desiredType, ((DataType) source).getNationalString(getLocaleFinder())); 240 } 241 protected void setFrom(DataValueDescriptor theValue) throws StandardException { 242 243 setValue(((DataType) theValue).getNationalString(getLocaleFinder())); 244 } 245 246 247 public int hashCode() 248 { 249 return nationalHashCode(); 250 } 251 } 252 | Popular Tags |