Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / MyDerby-10.3 / java / engine / org / apache / derby / impl / sql / compile / BitTypeCompiler.java
diff --git a/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/impl/sql/compile/BitTypeCompiler.java b/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/impl/sql/compile/BitTypeCompiler.java
new file mode 100644 (file)
index 0000000..221d54f
--- /dev/null
@@ -0,0 +1,178 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.sql.compile.BitTypeCompiler\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.services.sanity.SanityManager;\r
+\r
+import org.apache.derby.iapi.services.io.StoredFormatIds;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+\r
+import org.apache.derby.iapi.types.BitDataValue;\r
+import org.apache.derby.iapi.types.DataValueFactory;\r
+import org.apache.derby.iapi.types.TypeId;\r
+\r
+import org.apache.derby.iapi.types.DataTypeDescriptor;\r
+\r
+import org.apache.derby.iapi.sql.compile.TypeCompiler;\r
+\r
+import org.apache.derby.iapi.reference.ClassName;\r
+\r
+import java.sql.Types;\r
+import org.apache.derby.iapi.reference.JDBC20Translation;\r
+\r
+/**\r
+ * This class implements TypeCompiler for the SQL BIT datatype.\r
+ *\r
+ */\r
+\r
+public class BitTypeCompiler extends BaseTypeCompiler\r
+{\r
+        /**\r
+         * Tell whether this type (bit) can be converted to the given type.\r
+         *\r
+         * @see TypeCompiler#convertible\r
+         */\r
+        public boolean convertible(TypeId otherType, \r
+                                                                  boolean forDataTypeFunction)\r
+        {\r
+\r
+\r
+                       return (otherType.isBitTypeId() ||\r
+                                       otherType.isBlobTypeId() ||\r
+                                       otherType.isBooleanTypeId() ||\r
+                                       otherType.userType());\r
+               }\r
+\r
+       \r
+        /**\r
+         * Tell whether this type (bit) 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.isBlobTypeId())\r
+          return false;\r
+        return (otherType.isBitTypeId());\r
+        }\r
+\r
+        /**\r
+         * Tell whether this type (bit) can be stored into from the given type.\r
+         *\r
+         * @param otherType     The TypeId of the other type.\r
+         * @param cf            A ClassFactory\r
+         */\r
+\r
+        public boolean storable(TypeId otherType, ClassFactory cf)\r
+        {\r
+        if (otherType.isBlobTypeId())\r
+          return false;\r
+                               if (otherType.isBitTypeId())\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(this.getTypeId(), otherType, cf);\r
+        }\r
+\r
+        /** @see TypeCompiler#interfaceName */\r
+        public String interfaceName()\r
+        {\r
+                // may need to return different for Blob\r
+                // however, since it the nullMethodName()\r
+                // does not operate on a BitTypeCompiler object?\r
+                // it should?\r
+                return ClassName.BitDataValue;\r
+        }\r
+\r
+        /**\r
+         * @see TypeCompiler#getCorrespondingPrimitiveTypeName\r
+         */\r
+\r
+        public String getCorrespondingPrimitiveTypeName()\r
+        {\r
+            return "byte[]";\r
+        }\r
+\r
+        /**\r
+         * @see TypeCompiler#getCastToCharWidth\r
+         */\r
+        public int getCastToCharWidth(DataTypeDescriptor dts)\r
+        {\r
+                return dts.getMaximumWidth();\r
+        }\r
+\r
+        String nullMethodName()\r
+        {\r
+                int formatId = getStoredFormatIdFromTypeId();\r
+                switch (formatId)\r
+                {\r
+                        case StoredFormatIds.BIT_TYPE_ID:\r
+                                return "getNullBit";\r
+\r
+                        case StoredFormatIds.LONGVARBIT_TYPE_ID:\r
+                                return "getNullLongVarbit";\r
+\r
+                        case StoredFormatIds.VARBIT_TYPE_ID:\r
+                                return "getNullVarbit";\r
+\r
+                        default:\r
+                                if (SanityManager.DEBUG)\r
+                                {\r
+                                        SanityManager.THROWASSERT(\r
+                                                "unexpected formatId in nullMethodName() - " + formatId);\r
+                                }\r
+                                return null;\r
+                }\r
+        }\r
+\r
+        String dataValueMethodName()\r
+        {\r
+                int formatId = getStoredFormatIdFromTypeId();\r
+                switch (formatId)\r
+                {\r
+                        case StoredFormatIds.BIT_TYPE_ID:\r
+                                return "getBitDataValue";\r
+\r
+                        case StoredFormatIds.LONGVARBIT_TYPE_ID:\r
+                                return "getLongVarbitDataValue";\r
+\r
+                        case StoredFormatIds.VARBIT_TYPE_ID:\r
+                                return "getVarbitDataValue";\r
+\r
+                        default:\r
+                                if (SanityManager.DEBUG)\r
+                                {\r
+                                        SanityManager.THROWASSERT(\r
+                                                "unexpected formatId in dataValueMethodName() - " + formatId);\r
+                                }\r
+                                return null;\r
+                }\r
+        }\r
+}\r