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.BitDataValue; 33 import org.apache.derby.iapi.types.DataValueFactory; 34 import org.apache.derby.iapi.types.TypeId; 35 36 import org.apache.derby.iapi.types.DataTypeDescriptor; 37 38 import org.apache.derby.iapi.sql.compile.TypeCompiler; 39 40 import org.apache.derby.iapi.reference.ClassName; 41 42 import java.sql.Types ; 43 import org.apache.derby.iapi.reference.JDBC20Translation; 44 45 50 51 public class BitTypeCompiler extends BaseTypeCompiler 52 { 53 60 61 public boolean comparable(TypeId otherType, 62 boolean forEquals, 63 ClassFactory cf) 64 { 65 66 if (getTypeId().isLongConcatableTypeId() || 67 otherType.isLongConcatableTypeId()) 68 return false; 69 70 TypeCompiler otherTC = getTypeCompiler(otherType); 71 return (otherType.isBitTypeId() || 72 (otherType.userType() && 73 otherTC.comparable(getTypeId(), forEquals, cf))); 74 } 75 76 81 public boolean convertible(TypeId otherType, 82 boolean forDataTypeFunction) 83 { 84 85 86 return (otherType.isBitTypeId() || 87 otherType.isBlobTypeId() || 88 otherType.isBooleanTypeId() || 89 otherType.userType()); 90 } 91 92 93 98 public boolean compatible(TypeId otherType) 99 { 100 if (otherType.isBlobTypeId()) 101 return false; 102 return (otherType.isBitTypeId()); 103 } 104 105 111 112 public boolean storable(TypeId otherType, ClassFactory cf) 113 { 114 if (otherType.isBlobTypeId()) 115 return false; 116 if (otherType.isBitTypeId()) 117 { 118 return true; 119 } 120 121 125 return userTypeStorable(this.getTypeId(), otherType, cf); 126 } 127 128 129 public String interfaceName() 130 { 131 return ClassName.BitDataValue; 136 } 137 138 141 142 public String getCorrespondingPrimitiveTypeName() 143 { 144 return "byte[]"; 145 } 146 147 150 public int getCastToCharWidth(DataTypeDescriptor dts) 151 { 152 return dts.getMaximumWidth(); 153 } 154 155 protected String nullMethodName() 156 { 157 int formatId = getStoredFormatIdFromTypeId(); 158 switch (formatId) 159 { 160 case StoredFormatIds.BIT_TYPE_ID: 161 return "getNullBit"; 162 163 case StoredFormatIds.LONGVARBIT_TYPE_ID: 164 return "getNullLongVarbit"; 165 166 case StoredFormatIds.VARBIT_TYPE_ID: 167 return "getNullVarbit"; 168 169 default: 170 if (SanityManager.DEBUG) 171 { 172 SanityManager.THROWASSERT( 173 "unexpected formatId in nullMethodName() - " + formatId); 174 } 175 return null; 176 } 177 } 178 179 protected String dataValueMethodName() 180 { 181 int formatId = getStoredFormatIdFromTypeId(); 182 switch (formatId) 183 { 184 case StoredFormatIds.BIT_TYPE_ID: 185 return "getBitDataValue"; 186 187 case StoredFormatIds.LONGVARBIT_TYPE_ID: 188 return "getLongVarbitDataValue"; 189 190 case StoredFormatIds.VARBIT_TYPE_ID: 191 return "getVarbitDataValue"; 192 193 default: 194 if (SanityManager.DEBUG) 195 { 196 SanityManager.THROWASSERT( 197 "unexpected formatId in dataValueMethodName() - " + formatId); 198 } 199 return null; 200 } 201 } 202 } 203 | Popular Tags |