1 21 22 package org.apache.derby.impl.sql.compile; 23 24 import org.apache.derby.iapi.services.loader.ClassFactory; 25 26 import org.apache.derby.iapi.services.sanity.SanityManager; 27 28 import org.apache.derby.iapi.services.io.StoredFormatIds; 29 30 import org.apache.derby.iapi.error.StandardException; 31 32 import org.apache.derby.iapi.types.StringDataValue; 33 import org.apache.derby.iapi.types.DataValueDescriptor; 34 import org.apache.derby.iapi.types.TypeId; 35 import org.apache.derby.iapi.types.DataTypeDescriptor; 36 37 import org.apache.derby.iapi.sql.compile.TypeCompiler; 38 39 import org.apache.derby.iapi.reference.ClassName; 40 import org.apache.derby.iapi.reference.SQLState; 41 42 import org.apache.derby.iapi.util.StringUtil; 43 44 import java.sql.Types ; 45 import org.apache.derby.iapi.reference.JDBC20Translation; 46 47 52 53 public final class CharTypeCompiler extends BaseTypeCompiler 54 { 55 63 64 public boolean comparable(TypeId otherType, 65 boolean forEquals, 66 ClassFactory cf) 67 { 68 69 if (getTypeId().isLongConcatableTypeId() || 71 otherType.isLongConcatableTypeId()) 72 return false; 73 74 if((otherType.isStringTypeId() || 76 otherType.isDateTimeTimeStampTypeID() || 77 otherType.isBooleanTypeId())) 78 return true; 79 80 81 TypeCompiler otherTC = getTypeCompiler(otherType); 82 return (otherType.userType() && otherTC.comparable(getTypeId(), 83 forEquals, cf)); 84 } 85 86 87 92 public boolean convertible(TypeId otherType, boolean forDataTypeFunction) 93 { 94 if (getTypeId().isLongVarcharTypeId()) 97 { 98 return (otherType.isStringTypeId()); 99 } 100 101 if (forDataTypeFunction && otherType.isDoubleTypeId()) 103 return (getTypeId().isStringTypeId()); 104 105 if (otherType.isFloatingPointTypeId() || otherType.isBitTypeId() || 109 otherType.isBlobTypeId() || otherType.isXMLTypeId()) 110 return false; 111 112 return true; 113 } 114 115 116 117 122 public boolean compatible(TypeId otherType) 123 { 124 return (otherType.isStringTypeId() || (otherType.isDateTimeTimeStampTypeId() && !getTypeId().isLongVarcharTypeId())); 125 126 } 127 128 134 135 public boolean storable(TypeId otherType, ClassFactory cf) 136 { 137 if (convertible(otherType,false) && 139 !otherType.isBlobTypeId() && 140 !otherType.isNumericTypeId()) 141 return true; 142 143 147 return userTypeStorable(getTypeId(), otherType, cf); 148 } 149 150 151 public String interfaceName() 152 { 153 return ClassName.StringDataValue; 154 } 155 156 159 160 public String getCorrespondingPrimitiveTypeName() 161 { 162 163 return "java.lang.String"; 164 } 165 166 169 public int getCastToCharWidth(DataTypeDescriptor dts) 170 { 171 return dts.getMaximumWidth(); 172 } 173 174 175 public String getMatchingNationalCharTypeName() 176 { 177 int formatId = getStoredFormatIdFromTypeId(); 178 switch (formatId) 179 { 180 case StoredFormatIds.CHAR_TYPE_ID: 181 case StoredFormatIds.NATIONAL_CHAR_TYPE_ID: 182 return TypeId.NATIONAL_CHAR_NAME; 183 184 case StoredFormatIds.LONGVARCHAR_TYPE_ID: 185 case StoredFormatIds.NATIONAL_LONGVARCHAR_TYPE_ID: 186 return TypeId.NATIONAL_LONGVARCHAR_NAME; 187 188 case StoredFormatIds.VARCHAR_TYPE_ID: 189 case StoredFormatIds.NATIONAL_VARCHAR_TYPE_ID: 190 return TypeId.NATIONAL_VARCHAR_NAME; 191 192 default: 193 if (SanityManager.DEBUG) 194 { 195 SanityManager.THROWASSERT( 196 "unexpected formatId in getMatchingNationalCharTypeName() - " + formatId); 197 } 198 return null; 199 } 200 } 201 202 203 protected String nullMethodName() 204 { 205 int formatId = getStoredFormatIdFromTypeId(); 206 switch (formatId) 207 { 208 case StoredFormatIds.CHAR_TYPE_ID: 209 return "getNullChar"; 210 211 case StoredFormatIds.LONGVARCHAR_TYPE_ID: 212 return "getNullLongvarchar"; 213 214 case StoredFormatIds.NATIONAL_CHAR_TYPE_ID: 215 return "getNullNationalChar"; 216 217 case StoredFormatIds.NATIONAL_LONGVARCHAR_TYPE_ID: 218 return "getNullNationalLongvarchar"; 219 220 case StoredFormatIds.NATIONAL_VARCHAR_TYPE_ID: 221 return "getNullNationalVarchar"; 222 223 case StoredFormatIds.VARCHAR_TYPE_ID: 224 return "getNullVarchar"; 225 226 default: 227 if (SanityManager.DEBUG) 228 { 229 SanityManager.THROWASSERT( 230 "unexpected formatId in nullMethodName() - " + formatId); 231 } 232 return null; 233 } 234 } 235 236 protected String dataValueMethodName() 237 { 238 int formatId = getStoredFormatIdFromTypeId(); 239 switch (formatId) 240 { 241 case StoredFormatIds.CHAR_TYPE_ID: 242 return "getCharDataValue"; 243 244 case StoredFormatIds.LONGVARCHAR_TYPE_ID: 245 return "getLongvarcharDataValue"; 246 247 case StoredFormatIds.NATIONAL_CHAR_TYPE_ID: 248 return "getNationalCharDataValue"; 249 250 case StoredFormatIds.NATIONAL_LONGVARCHAR_TYPE_ID: 251 return "getNationalLongvarcharDataValue"; 252 253 case StoredFormatIds.NATIONAL_VARCHAR_TYPE_ID: 254 return "getNationalVarcharDataValue"; 255 256 case StoredFormatIds.VARCHAR_TYPE_ID: 257 return "getVarcharDataValue"; 258 259 default: 260 if (SanityManager.DEBUG) 261 { 262 SanityManager.THROWASSERT( 263 "unexpected formatId in dataValueMethodName() - " + formatId); 264 } 265 return null; 266 } 267 } 268 } 269 | Popular Tags |