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.types.DataTypeDescriptor; 29 import org.apache.derby.iapi.types.DateTimeDataValue; 30 import org.apache.derby.iapi.types.DataValueFactory; 31 import org.apache.derby.iapi.types.TypeId; 32 33 import org.apache.derby.iapi.sql.compile.TypeCompiler; 34 35 import org.apache.derby.iapi.services.sanity.SanityManager; 36 37 import org.apache.derby.iapi.reference.ClassName; 38 39 import java.sql.Types ; 40 41 public class DateTypeCompiler extends BaseTypeCompiler 42 { 43 44 45 55 public boolean comparable(TypeId otherType, 56 boolean forEquals, 57 ClassFactory cf) 58 { 59 int otherJDBCTypeId = otherType.getJDBCTypeId(); 60 TypeCompiler otherTC = getTypeCompiler(otherType); 61 62 if (otherType.isLongConcatableTypeId()) 64 return false; 65 66 if (otherJDBCTypeId == Types.DATE || otherType.isStringTypeId()) 67 return true; 68 69 70 if (otherType.userType()) 71 { 72 return otherTC.comparable(getTypeId(), forEquals, cf); 73 } 74 75 return false; 76 } 77 78 87 public boolean convertible(TypeId otherType, boolean forDataTypeFunction) 88 { 89 90 91 if (otherType.isStringTypeId() && 92 (!otherType.isLongConcatableTypeId())) 93 { 94 return true; 95 } 96 97 return (getStoredFormatIdFromTypeId() == 98 otherType.getTypeFormatId()); 99 100 } 101 102 107 public boolean compatible(TypeId otherType) 108 { 109 return convertible(otherType,false); 110 } 111 112 124 public boolean storable(TypeId otherType, ClassFactory cf) 125 { 126 int otherJDBCTypeId = otherType.getJDBCTypeId(); 127 128 if (otherJDBCTypeId == Types.DATE || 129 (otherJDBCTypeId == Types.CHAR) || 130 (otherJDBCTypeId == Types.VARCHAR)) 131 { 132 return true; 133 } 134 135 return cf.getClassInspector().assignableTo( 136 otherType.getCorrespondingJavaTypeName(), 137 "java.sql.Date"); 138 } 139 140 141 public String interfaceName() 142 { 143 return ClassName.DateTimeDataValue; 144 } 145 146 149 150 public String getCorrespondingPrimitiveTypeName() 151 { 152 return "java.sql.Date"; 153 } 154 155 158 public int getCastToCharWidth(DataTypeDescriptor dts) 159 { 160 return 10; 161 } 162 163 protected String nullMethodName() 164 { 165 return "getNullDate"; 166 } 167 } 168 | Popular Tags |