Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / derby-10.3.2.1 / java / engine / org / apache / derby / impl / sql / compile / LOBTypeCompiler.java
diff --git a/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/sql/compile/LOBTypeCompiler.java b/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/sql/compile/LOBTypeCompiler.java
new file mode 100644 (file)
index 0000000..8ac25ba
--- /dev/null
@@ -0,0 +1,139 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.sql.compile.LOBTypeCompiler\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 LOB types.\r
+ *\r
+ */\r
+\r
+public class LOBTypeCompiler extends BaseTypeCompiler\r
+{\r
+        /**\r
+         * Tell whether this type (LOB) 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
+            return  (otherType.isBlobTypeId());\r
+        }\r
+\r
+        /**\r
+         * Tell whether this type (LOB) 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
+        /**\r
+         * Tell whether this type (LOB) 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
+            // no automatic conversions at store time\r
+\r
+                       return  (otherType.isBlobTypeId());\r
+        }\r
+\r
+        /** @see TypeCompiler#interfaceName */\r
+        public String interfaceName()\r
+        {\r
+            return ClassName.BitDataValue;\r
+        }\r
+\r
+        /**\r
+         * @see TypeCompiler#getCorrespondingPrimitiveTypeName\r
+         */\r
+\r
+        public String getCorrespondingPrimitiveTypeName() {\r
+            int formatId = getStoredFormatIdFromTypeId();\r
+            switch (formatId) {\r
+                case StoredFormatIds.BLOB_TYPE_ID:  return "java.sql.Blob";\r
+                default:\r
+                    if (SanityManager.DEBUG)\r
+                        SanityManager.THROWASSERT("unexpected formatId in getCorrespondingPrimitiveTypeName() - " + formatId);\r
+                    return null;\r
+            }\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
+            int formatId = getStoredFormatIdFromTypeId();\r
+            switch (formatId) {\r
+                case StoredFormatIds.BLOB_TYPE_ID:  return "getNullBlob";\r
+                default:\r
+                    if (SanityManager.DEBUG)\r
+                        SanityManager.THROWASSERT("unexpected formatId in nullMethodName() - " + formatId);\r
+                    return null;\r
+            }\r
+        }\r
+\r
+        String dataValueMethodName()\r
+        {\r
+            int formatId = getStoredFormatIdFromTypeId();\r
+            switch (formatId) {\r
+                case StoredFormatIds.BLOB_TYPE_ID:  return "getBlobDataValue";\r
+                default:\r
+                    if (SanityManager.DEBUG)\r
+                        SanityManager.THROWASSERT("unexpected formatId in dataValueMethodName() - " + formatId);\r
+                    return null;\r
+                }\r
+        }\r
+}\r