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 / UserDefinedTypeCompiler.java
diff --git a/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/sql/compile/UserDefinedTypeCompiler.java b/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/sql/compile/UserDefinedTypeCompiler.java
new file mode 100644 (file)
index 0000000..ef6ccd0
--- /dev/null
@@ -0,0 +1,132 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.sql.compile.UserDefinedTypeCompiler\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.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
+import org.apache.derby.iapi.services.compiler.LocalField;\r
+import org.apache.derby.iapi.services.compiler.MethodBuilder;\r
+\r
+import org.apache.derby.iapi.reference.ClassName;\r
+\r
+public class UserDefinedTypeCompiler extends BaseTypeCompiler\r
+{\r
+       /* TypeCompiler methods */\r
+\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
+        * @param otherType \r
+        * @param forDataTypeFunction\r
+        * @return true if otherType is convertible to this type, else false.\r
+        * \r
+        *@see TypeCompiler#convertible\r
+        */\r
+       public boolean convertible(TypeId otherType, boolean forDataTypeFunction)\r
+       {\r
+               /*\r
+               ** We are a user defined type, we are\r
+               ** going to have to let the client find out\r
+               ** the hard way.\r
+               */\r
+               return true;\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
+               return cf.getClassInspector().assignableTo(\r
+                          otherType.getCorrespondingJavaTypeName(),\r
+                          getTypeId().getCorrespondingJavaTypeName());\r
+       }\r
+\r
+       /** @see TypeCompiler#interfaceName */\r
+       public String interfaceName()\r
+       {\r
+               return ClassName.UserDataValue;\r
+       }\r
+                       \r
+       /**\r
+        * @see TypeCompiler#getCorrespondingPrimitiveTypeName\r
+        */\r
+\r
+       public String getCorrespondingPrimitiveTypeName()\r
+       {\r
+               return getTypeId().getCorrespondingJavaTypeName();\r
+       }\r
+\r
+       /**\r
+        * @see TypeCompiler#getCastToCharWidth\r
+        */\r
+       public int getCastToCharWidth(DataTypeDescriptor dts)\r
+       {\r
+               // This is the maximum maximum width for user types\r
+               return -1;\r
+       }\r
+\r
+       String nullMethodName()\r
+       {\r
+               return "getNullObject";\r
+       }\r
+\r
+       public void generateDataValue(MethodBuilder mb, int collationType,\r
+                       LocalField field)\r
+       {\r
+               // cast the value to an object for method resolution\r
+               mb.upCast("java.lang.Object");\r
+\r
+               super.generateDataValue(mb, collationType, field);\r
+       }\r
+\r
+               \r
+\r
+}\r