1 21 22 package org.apache.derby.impl.sql.compile; 23 24 import org.apache.derby.iapi.reference.SQLState; 25 import org.apache.derby.iapi.services.loader.ClassFactory; 26 27 import org.apache.derby.iapi.services.sanity.SanityManager; 28 29 import org.apache.derby.iapi.error.StandardException; 30 import org.apache.derby.iapi.sql.conn.ConnectionUtil; 31 32 import org.apache.derby.iapi.sql.compile.TypeCompiler; 33 34 import org.apache.derby.iapi.types.BitDataValue; 35 import org.apache.derby.iapi.types.DataValueFactory; 36 import org.apache.derby.iapi.types.DataValueDescriptor; 37 import org.apache.derby.iapi.types.TypeId; 38 39 import org.apache.derby.iapi.types.DataTypeDescriptor; 40 41 import org.apache.derby.iapi.reference.SQLState; 42 import org.apache.derby.iapi.reference.ClassName; 43 44 import org.apache.derby.iapi.services.compiler.LocalField; 45 import org.apache.derby.iapi.services.compiler.MethodBuilder; 46 47 import org.apache.derby.iapi.services.classfile.VMOpcode; 48 49 import java.sql.Types ; 50 51 56 57 abstract class BaseTypeCompiler implements TypeCompiler 58 { 59 private TypeId correspondingTypeId; 60 61 68 public String getPrimitiveMethodName() 69 { 70 if (SanityManager.DEBUG) 71 { 72 SanityManager.THROWASSERT("getPrimitiveMethodName not applicable for " + 73 getClass().toString()); 74 } 75 return null; 76 } 77 78 79 public String getMatchingNationalCharTypeName() 80 { 81 return TypeId.NATIONAL_CHAR_NAME; 82 } 83 84 85 90 public DataTypeDescriptor 91 resolveArithmeticOperation(DataTypeDescriptor leftType, 92 DataTypeDescriptor rightType, 93 String operator) 94 throws StandardException 95 { 96 throw StandardException.newException(SQLState.LANG_BINARY_OPERATOR_NOT_SUPPORTED, 97 operator, 98 leftType.getTypeId().getSQLTypeName(), 99 rightType.getTypeId().getSQLTypeName() 100 ); 101 } 102 103 104 105 public void generateNull(MethodBuilder mb) 106 { 107 mb.callMethod(VMOpcode.INVOKEINTERFACE, (String ) null, 108 nullMethodName(), 109 interfaceName(), 110 1); 111 } 112 113 114 public void generateDataValue(MethodBuilder mb, 115 LocalField field) 116 { 117 String interfaceName = interfaceName(); 118 119 121 125 if (field == null) 126 { 127 mb.pushNull(interfaceName); 128 } 129 else 130 { 131 mb.getField(field); 132 } 133 134 135 mb.callMethod(VMOpcode.INVOKEINTERFACE, (String ) null, 136 dataValueMethodName(), 137 interfaceName, 138 2); 139 140 if (field != null) 141 { 142 145 mb.putField(field); 146 } 147 } 148 149 protected abstract String nullMethodName(); 150 151 155 protected String dataValueMethodName() 156 { 157 return "getDataValue"; 158 } 159 160 161 170 protected boolean userTypeStorable(TypeId thisType, 171 TypeId otherType, 172 ClassFactory cf) 173 { 174 178 if (otherType.userType()) 179 { 180 return cf.getClassInspector().assignableTo( 181 thisType.getCorrespondingJavaTypeName(), 182 otherType.getCorrespondingJavaTypeName()); 183 } 184 185 return false; 186 } 187 188 193 194 public boolean numberComparable(TypeId otherType, 195 boolean forEquals, 196 ClassFactory cf) 197 { 198 TypeCompiler otherTC = getTypeCompiler(otherType); 199 200 203 return otherType.isNumericTypeId() || 204 otherType.isBooleanTypeId() || 205 (otherType.userType() && otherTC.comparable(otherType, 206 forEquals, 207 cf)); 208 } 209 210 211 218 public boolean numberConvertible(TypeId otherType, 219 boolean forDataTypeFunction) 220 { 221 222 if (otherType.isLongConcatableTypeId()) 224 return false; 225 226 boolean retval =((otherType.isNumericTypeId()) || 230 (otherType.isBooleanTypeId()) || 231 (otherType.userType())); 232 233 if (forDataTypeFunction) 236 retval = retval || 237 (otherType.isFixedStringTypeId() && 238 (getTypeId().isFloatingPointTypeId())); 239 240 retval = retval || 241 (otherType.isFixedStringTypeId() && 242 (!getTypeId().isFloatingPointTypeId())); 243 244 return retval; 245 246 } 247 248 255 256 public boolean numberStorable(TypeId thisType, 257 TypeId otherType, 258 ClassFactory cf) 259 { 260 264 if ((otherType.isNumericTypeId()) || 265 (otherType.isBooleanTypeId())) 266 return true; 267 268 272 return userTypeStorable(thisType, otherType, cf); 273 } 274 275 276 279 protected TypeId getTypeId() 280 { 281 return correspondingTypeId; 282 } 283 284 287 protected TypeCompiler getTypeCompiler(TypeId typeId) 288 { 289 return TypeCompilerFactoryImpl.staticGetTypeCompiler(typeId); 290 } 291 292 295 void setTypeId(TypeId typeId) 296 { 297 correspondingTypeId = typeId; 298 } 299 300 307 protected int getStoredFormatIdFromTypeId() 308 { 309 return getTypeId().getTypeFormatId(); 310 } 311 312 313 } 314 315 316 317 318 319 | Popular Tags |