--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.impl.sql.compile.TimeTypeCompiler\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.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 TimeTypeCompiler 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
+ public boolean convertible(TypeId otherType,\r
+ boolean forDataTypeFunction)\r
+ {\r
+\r
+ if (otherType.isStringTypeId() && \r
+ (!otherType.isLOBTypeId()) &&\r
+ !otherType.isLongVarcharTypeId())\r
+ {\r
+ return true;\r
+ }\r
+\r
+\r
+ /*\r
+ ** If same type, convert always ok.\r
+ */\r
+ return (getStoredFormatIdFromTypeId() == \r
+ otherType.getTypeFormatId());\r
+ \r
+ }\r
+\r
+ /** @see TypeCompiler#compatible */\r
+ public boolean compatible(TypeId otherType)\r
+ {\r
+ return convertible(otherType,false);\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.TIME ||\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.Time");\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.Time";\r
+ }\r
+\r
+ /**\r
+ * @see TypeCompiler#getCastToCharWidth\r
+ */\r
+ public int getCastToCharWidth(DataTypeDescriptor dts)\r
+ {\r
+ return 8;\r
+ }\r
+\r
+ public double estimatedMemoryUsage(DataTypeDescriptor dtd)\r
+ {\r
+ return 12.0;\r
+ }\r
+\r
+ String nullMethodName()\r
+ {\r
+ return "getNullTime";\r
+ }\r
+}\r