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.error.StandardException; 27 28 import org.apache.derby.iapi.reference.SQLState; 29 30 import org.apache.derby.iapi.types.DataTypeDescriptor; 31 import org.apache.derby.iapi.types.BooleanDataValue; 32 import org.apache.derby.iapi.types.TypeId; 33 34 import org.apache.derby.iapi.sql.compile.TypeCompiler; 35 36 import org.apache.derby.catalog.types.BaseTypeIdImpl; 37 import org.apache.derby.iapi.reference.ClassName; 38 39 import java.sql.Types ; 40 41 46 47 public class BooleanTypeCompiler extends BaseTypeCompiler 48 { 49 54 55 public boolean comparable(TypeId otherType, 56 boolean forEquals, 57 ClassFactory cf) 58 { 59 TypeId thisTypeId = getTypeId(); 60 TypeCompiler otherTypeCompiler = getTypeCompiler(otherType); 61 62 63 return otherType.getSQLTypeName().equals(thisTypeId.getSQLTypeName()) || 64 otherType.isStringTypeId() || 65 otherType.isNumericTypeId() || 66 (otherType.userType() && 67 otherTypeCompiler.comparable(thisTypeId, forEquals, cf)); 68 } 69 70 75 public boolean convertible(TypeId otherType, boolean forDataTypeFunction) 76 { 77 int otherJDBCTypeId = otherType.getJDBCTypeId(); 78 79 if ((otherJDBCTypeId == Types.DATE) || 80 (otherJDBCTypeId == Types.TIME) || 81 (otherJDBCTypeId == Types.TIMESTAMP)) 82 { 83 return false; 84 } 85 86 return true; 87 } 88 89 94 public boolean compatible(TypeId otherType) 95 { 96 return convertible(otherType,false); 97 } 98 99 100 public boolean storable(TypeId otherType, ClassFactory cf) 101 { 102 103 if (otherType.isBooleanTypeId() || 104 otherType.isStringTypeId() || 105 otherType.isNumericTypeId()) 106 { 107 return true; 108 } 109 110 114 return userTypeStorable(getTypeId(), otherType, cf); 115 } 116 117 118 public String interfaceName() 119 { 120 return ClassName.BooleanDataValue; 121 } 122 123 126 127 public String getCorrespondingPrimitiveTypeName() 128 { 129 130 return "boolean"; 131 } 132 133 140 public String getPrimitiveMethodName() 141 { 142 return "getBoolean"; 143 } 144 145 148 public int getCastToCharWidth(DataTypeDescriptor dts) 149 { 150 return TypeCompiler.BOOLEAN_MAXWIDTH_AS_CHAR; 151 } 152 153 protected String nullMethodName() 154 { 155 return "getNullBoolean"; 156 } 157 } 158 | Popular Tags |