--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.impl.sql.compile.BooleanTypeCompiler\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.reference.SQLState;\r
+\r
+import org.apache.derby.iapi.types.DataTypeDescriptor;\r
+import org.apache.derby.iapi.types.BooleanDataValue;\r
+import org.apache.derby.iapi.types.TypeId;\r
+\r
+import org.apache.derby.iapi.sql.compile.TypeCompiler;\r
+\r
+import org.apache.derby.catalog.types.BaseTypeIdImpl;\r
+import org.apache.derby.iapi.reference.ClassName;\r
+\r
+import java.sql.Types;\r
+\r
+/**\r
+ * This class implements TypeCompiler for the SQL BOOLEAN datatype.\r
+ *\r
+ */\r
+\r
+public class BooleanTypeCompiler extends BaseTypeCompiler\r
+{\r
+ /**\r
+ * Tell whether this type (boolean) can be converted to the given type.\r
+ *\r
+ * @see TypeCompiler#convertible\r
+ */\r
+ public boolean convertible(TypeId otherType, boolean forDataTypeFunction)\r
+ {\r
+ int otherJDBCTypeId = otherType.getJDBCTypeId();\r
+\r
+ if ((otherJDBCTypeId == Types.DATE) ||\r
+ (otherJDBCTypeId == Types.TIME) ||\r
+ (otherJDBCTypeId == Types.TIMESTAMP))\r
+ {\r
+ return false;\r
+ }\r
+\r
+ return true;\r
+ }\r
+\r
+ /**\r
+ * Tell whether this type (boolean) 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
+ return convertible(otherType,false);\r
+ }\r
+\r
+ /** @see TypeCompiler#storable */\r
+ public boolean storable(TypeId otherType, ClassFactory cf)\r
+ {\r
+ /* Are the types the same or is other type a string or number type? */\r
+ if (otherType.isBooleanTypeId() ||\r
+ otherType.isStringTypeId() ||\r
+ otherType.isNumericTypeId())\r
+ {\r
+ return true;\r
+ }\r
+\r
+ /*\r
+ ** If the other type is user-defined, use the java types to determine\r
+ ** assignability.\r
+ */\r
+ return userTypeStorable(getTypeId(), otherType, cf);\r
+ }\r
+\r
+ /** @see TypeCompiler#interfaceName */\r
+ public String interfaceName()\r
+ {\r
+ return ClassName.BooleanDataValue;\r
+ }\r
+\r
+ /**\r
+ * @see TypeCompiler#getCorrespondingPrimitiveTypeName\r
+ */\r
+\r
+ public String getCorrespondingPrimitiveTypeName()\r
+ {\r
+ /* Only numerics and booleans get mapped to Java primitives */\r
+ return "boolean";\r
+ }\r
+\r
+ /**\r
+ * Get the method name for getting out the corresponding primitive\r
+ * Java type.\r
+ *\r
+ * @return String The method call name for getting the\r
+ * corresponding primitive Java type.\r
+ */\r
+ public String getPrimitiveMethodName()\r
+ {\r
+ return "getBoolean";\r
+ }\r
+\r
+ /**\r
+ * @see TypeCompiler#getCastToCharWidth\r
+ */\r
+ public int getCastToCharWidth(DataTypeDescriptor dts)\r
+ {\r
+ return TypeCompiler.BOOLEAN_MAXWIDTH_AS_CHAR;\r
+ }\r
+\r
+ String nullMethodName()\r
+ {\r
+ return "getNullBoolean";\r
+ }\r
+}\r