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 java.sql.Types ; 38 import org.apache.derby.iapi.reference.ClassName; 39 40 public class TimestampTypeCompiler extends BaseTypeCompiler 41 { 42 43 44 54 public boolean comparable(TypeId otherType, 55 boolean forEquals, 56 ClassFactory cf) 57 { 58 return comparable(getTypeId(), otherType, forEquals, cf); 59 } 60 61 boolean comparable(TypeId leftType, 62 TypeId otherType, 63 boolean forEquals, 64 ClassFactory cf) 65 { 66 67 int otherJDBCTypeId = otherType.getJDBCTypeId(); 68 69 if (otherType.isLongConcatableTypeId()) 71 return false; 72 73 TypeCompiler otherTC = getTypeCompiler(otherType); 74 if (otherJDBCTypeId == Types.TIMESTAMP || otherType.isStringTypeId()) 75 return true; 76 77 78 if (otherType.userType()) 79 { 80 return otherTC.comparable(getTypeId(), forEquals, cf); 81 } 82 83 return false; 84 } 85 86 96 public boolean convertible(TypeId otherType, 97 boolean forDataTypeFunction) 98 { 99 if (otherType.isStringTypeId()&& 100 (!otherType.isLongConcatableTypeId())) 101 { 102 return true; 103 } 104 105 int otherJDBCTypeId = otherType.getJDBCTypeId(); 106 107 111 if (otherJDBCTypeId == Types.TIMESTAMP) 112 { 113 return true; 114 } 115 116 120 return ((otherJDBCTypeId == Types.DATE) || 121 (otherJDBCTypeId == Types.TIME)); 122 } 123 124 129 public boolean compatible(TypeId otherType) 130 { 131 if (otherType.isStringTypeId() && 132 (!otherType.isLongConcatableTypeId())) 133 { 134 return true; 135 } 136 137 140 return (getStoredFormatIdFromTypeId() == 141 otherType.getTypeFormatId()); 142 } 143 144 156 public boolean storable(TypeId otherType, ClassFactory cf) 157 { 158 int otherJDBCTypeId = otherType.getJDBCTypeId(); 159 160 if (otherJDBCTypeId == Types.TIMESTAMP || 161 (otherJDBCTypeId == Types.CHAR) || 162 (otherJDBCTypeId == Types.VARCHAR)) 163 { 164 return true; 165 } 166 167 return cf.getClassInspector().assignableTo( 168 otherType.getCorrespondingJavaTypeName(), 169 "java.sql.Timestamp"); 170 } 171 172 173 public String interfaceName() 174 { 175 return ClassName.DateTimeDataValue; 176 } 177 178 181 182 public String getCorrespondingPrimitiveTypeName() 183 { 184 return "java.sql.Timestamp"; 185 } 186 187 190 public int getCastToCharWidth(DataTypeDescriptor dts) 191 { 192 return 26; } 194 195 public double estimatedMemoryUsage(DataTypeDescriptor dtd) 196 { 197 return 12.0; 198 } 199 protected String nullMethodName() 200 { 201 return "getNullTimestamp"; 202 } 203 } 204 | Popular Tags |