--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.impl.sql.compile.TimestampTypeCompiler\r
+\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to you under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+\r
+ */\r
+\r
+package org.apache.derby.impl.sql.compile;\r
+\r
+import org.apache.derby.iapi.services.loader.ClassFactory;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+\r
+import org.apache.derby.iapi.types.DataTypeDescriptor;\r
+import org.apache.derby.iapi.types.DateTimeDataValue;\r
+import org.apache.derby.iapi.types.DataValueFactory;\r
+import org.apache.derby.iapi.types.TypeId;\r
+\r
+import org.apache.derby.iapi.sql.compile.TypeCompiler;\r
+\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+\r
+import java.sql.Types;\r
+import org.apache.derby.iapi.reference.ClassName;\r
+\r
+public class TimestampTypeCompiler extends BaseTypeCompiler\r
+{\r
+ /* TypeCompiler methods */ \r
+ /**\r
+ * User types are convertible to other user types only if\r
+ * (for now) they are the same type and are being used to\r
+ * implement some JDBC type. This is sufficient for\r
+ * date/time types; it may be generalized later for e.g.\r
+ * comparison of any user type with one of its subtypes.\r
+ *\r
+ * @see TypeCompiler#convertible \r
+ *\r
+ */\r
+ public boolean convertible(TypeId otherType, \r
+ boolean forDataTypeFunction)\r
+ {\r
+ if (otherType.isStringTypeId()&& \r
+ (!otherType.isLongConcatableTypeId()))\r
+ {\r
+ return true;\r
+ }\r
+ \r
+ int otherJDBCTypeId = otherType.getJDBCTypeId();\r
+\r
+ /*\r
+ ** At this point, we have only date/time. If\r
+ ** same type, convert always ok.\r
+ */\r
+ if (otherJDBCTypeId == Types.TIMESTAMP)\r
+ {\r
+ return true;\r
+ }\r
+\r
+ /*\r
+ ** Otherwise, we can convert timestamp to\r
+ ** date or time only.\r
+ */\r
+ return ((otherJDBCTypeId == Types.DATE) ||\r
+ (otherJDBCTypeId == Types.TIME));\r
+ }\r
+\r
+ /**\r
+ * Tell whether this type (timestamp) is compatible with the given type.\r
+ *\r
+ * @param otherType The TypeId of the other type.\r
+ */\r
+ public boolean compatible(TypeId otherType)\r
+ {\r
+ if (otherType.isStringTypeId() &&\r
+ (!otherType.isLongConcatableTypeId()))\r
+ {\r
+ return true;\r
+ }\r
+\r
+ /*\r
+ ** Both are timestamp datatypes and hence compatible.\r
+ */\r
+ return (getStoredFormatIdFromTypeId() ==\r
+ otherType.getTypeFormatId());\r
+ }\r
+\r
+ /**\r
+ * User types are storable into other user types that they\r
+ * are assignable to. The other type must be a subclass of\r
+ * this type, or implement this type as one of its interfaces.\r
+ *\r
+ * Built-in types are also storable into user types when the built-in\r
+ * type's corresponding Java type is assignable to the user type.\r
+ *\r
+ * @param otherType the type of the instance to store into this type.\r
+ * @param cf A ClassFactory\r
+ * @return true if otherType is storable into this type, else false.\r
+ */\r
+ public boolean storable(TypeId otherType, ClassFactory cf)\r
+ {\r
+ int otherJDBCTypeId = otherType.getJDBCTypeId();\r
+\r
+ if (otherJDBCTypeId == Types.TIMESTAMP ||\r
+ (otherJDBCTypeId == Types.CHAR) ||\r
+ (otherJDBCTypeId == Types.VARCHAR))\r
+ {\r
+ return true;\r
+ }\r
+\r
+ return cf.getClassInspector().assignableTo(\r
+ otherType.getCorrespondingJavaTypeName(),\r
+ "java.sql.Timestamp");\r
+ }\r
+\r
+ /** @see TypeCompiler#interfaceName */\r
+ public String interfaceName()\r
+ {\r
+ return ClassName.DateTimeDataValue;\r
+ }\r
+ \r
+ /**\r
+ * @see TypeCompiler#getCorrespondingPrimitiveTypeName\r
+ */\r
+\r
+ public String getCorrespondingPrimitiveTypeName()\r
+ {\r
+ return "java.sql.Timestamp";\r
+ }\r
+\r
+ /**\r
+ * @see TypeCompiler#getCastToCharWidth\r
+ */\r
+ public int getCastToCharWidth(DataTypeDescriptor dts)\r
+ {\r
+ return 26; // DATE TIME.milliseconds (extra few for good measure)\r
+ }\r
+\r
+ public double estimatedMemoryUsage(DataTypeDescriptor dtd)\r
+ {\r
+ return 12.0;\r
+ }\r
+ String nullMethodName()\r
+ {\r
+ return "getNullTimestamp";\r
+ }\r
+}\r