Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / MyDerby-10.3 / java / engine / org / apache / derby / iapi / sql / compile / TypeCompiler.java
diff --git a/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/iapi/sql/compile/TypeCompiler.java b/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/iapi/sql/compile/TypeCompiler.java
new file mode 100644 (file)
index 0000000..f63cf8b
--- /dev/null
@@ -0,0 +1,214 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.iapi.sql.compile.TypeCompiler\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.iapi.sql.compile;\r
+\r
+import org.apache.derby.iapi.services.loader.ClassFactory;\r
+\r
+import org.apache.derby.iapi.services.compiler.MethodBuilder;\r
+import org.apache.derby.iapi.services.compiler.LocalField;\r
+\r
+import org.apache.derby.iapi.types.DataTypeDescriptor;\r
+import org.apache.derby.iapi.types.TypeId;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+\r
+import org.apache.derby.iapi.reference.Limits;\r
+\r
+/**\r
+ * This interface defines methods associated with a TypeId that are used\r
+ * by the compiler.\r
+ */\r
+\r
+public interface TypeCompiler\r
+{\r
+       /**\r
+        * Various fixed numbers related to datatypes.\r
+        */\r
+       // Need to leave space for '-'\r
+       public static final int LONGINT_MAXWIDTH_AS_CHAR        = 20;\r
+\r
+       // Need to leave space for '-'\r
+       public static final int INT_MAXWIDTH_AS_CHAR    = 11;\r
+\r
+       // Need to leave space for '-'\r
+       public static final int SMALLINT_MAXWIDTH_AS_CHAR       = 6;\r
+\r
+       // Need to leave space for '-'\r
+       public static final int TINYINT_MAXWIDTH_AS_CHAR        = 4;\r
+\r
+       // Need to leave space for '-' and decimal point\r
+       public static final int DOUBLE_MAXWIDTH_AS_CHAR         = 54;\r
+\r
+       // Need to leave space for '-' and decimal point\r
+       public static final int REAL_MAXWIDTH_AS_CHAR   = 25;\r
+\r
+       public static final int DEFAULT_DECIMAL_PRECISION       = Limits.DB2_DEFAULT_DECIMAL_PRECISION;\r
+       public static final int DEFAULT_DECIMAL_SCALE           = Limits.DB2_DEFAULT_DECIMAL_SCALE;\r
+       public static final int MAX_DECIMAL_PRECISION_SCALE = Limits.DB2_MAX_DECIMAL_PRECISION_SCALE;\r
+\r
+       public static final int BOOLEAN_MAXWIDTH_AS_CHAR        = 5;\r
+\r
+       public static final String PLUS_OP              = "+";\r
+       public static final String DIVIDE_OP    = "/";\r
+       public static final String MINUS_OP     = "-";\r
+       public static final String TIMES_OP     = "*";\r
+       public static final String SUM_OP               = "sum";\r
+       public static final String AVG_OP               = "avg";\r
+       public static final String MOD_OP               = "mod";\r
+\r
+       /**\r
+        * Type resolution methods on binary operators\r
+        *\r
+        * @param leftType      The type of the left parameter\r
+        * @param rightType     The type of the right parameter\r
+        * @param operator      The name of the operator (e.g. "+").\r
+        *\r
+        * @return      The type of the result\r
+        *\r
+        * @exception StandardException Thrown on error\r
+        */\r
+\r
+       DataTypeDescriptor      resolveArithmeticOperation(\r
+                                                       DataTypeDescriptor leftType,\r
+                                                       DataTypeDescriptor rightType,\r
+                                                       String operator\r
+                                                               )\r
+                                                       throws StandardException;\r
+\r
+       /**\r
+        * Determine if this type can be CONVERTed to some other type\r
+        *\r
+        * @param otherType     The CompilationType of the other type to compare\r
+        *                                      this type to\r
+        *\r
+        * @param forDataTypeFunction  true if this is a type function that\r
+        *   requires more liberal behavior (e.g DOUBLE can convert a char but \r
+        *   you cannot cast a CHAR to double.\r
+        *   \r
+        * @return      true if the types can be converted, false if conversion\r
+        *                      is not allowed\r
+        */\r
+        boolean             convertible(TypeId otherType, \r
+                                                                        boolean forDataTypeFunction);\r
+\r
+       /**\r
+        * Determine if this type is compatible to some other type\r
+        * (e.g. COALESCE(thistype, othertype)).\r
+        *\r
+        * @param otherType     The CompilationType of the other type to compare\r
+        *                                      this type to\r
+        *\r
+        * @return      true if the types are compatible, false if not compatible\r
+        */\r
+       boolean compatible(TypeId otherType);\r
+\r
+       /**\r
+        * Determine if this type can have a value of another type stored into it.\r
+        * Note that direction is relevant here: the test is that the otherType\r
+        * is storable into this type.\r
+        *\r
+        * @param otherType     The TypeId of the other type to compare this type to\r
+        * @param cf            A ClassFactory\r
+        *\r
+        * @return      true if the other type can be stored in a column of this type.\r
+        */\r
+\r
+       boolean                         storable(TypeId otherType, ClassFactory cf);\r
+\r
+       /**\r
+        * Get the name of the interface for this type.  For example, the interface\r
+        * for a SQLInteger is NumberDataValue.  The full path name of the type\r
+        * is returned.\r
+        *\r
+        * @return      The name of the interface for this type.\r
+        */\r
+       String interfaceName();\r
+\r
+       /**\r
+        * Get the name of the corresponding Java type.  For numerics and booleans\r
+        * we will get the corresponding Java primitive type.\r
+        e\r
+        * Each SQL type has a corresponding Java type.  When a SQL value is\r
+        * passed to a Java method, it is translated to its corresponding Java\r
+        * type.  For example, a SQL Integer will be mapped to a Java int, but\r
+        * a SQL date will be mapped to a java.sql.Date.\r
+        *\r
+        * @return      The name of the corresponding Java primitive type.\r
+        */\r
+       String  getCorrespondingPrimitiveTypeName();\r
+\r
+       /**\r
+        * Get the method name for getting out the corresponding primitive\r
+        * Java type from a DataValueDescriptor.\r
+        *\r
+        * @return String               The method call name for getting the\r
+        *                                              corresponding primitive Java type.\r
+        */\r
+       String getPrimitiveMethodName();\r
+\r
+       /**\r
+        * Generate the code necessary to produce a SQL null of the appropriate\r
+        * type. The stack must contain a DataValueFactory and a null or a value\r
+        * of the correct type (interfaceName()).\r
+        *\r
+        * @param mb    The method to put the expression in\r
+        * @param collationType For character DVDs, this will be used to determine\r
+        *   what Collator should be associated with the DVD which in turn will \r
+        *   decide whether to generate CollatorSQLcharDVDs or SQLcharDVDs.\r
+        */\r
+\r
+       void generateNull(MethodBuilder mb, int collationType);\r
+\r
+\r
+       /**\r
+        * Generate the code necessary to produce a SQL value based on\r
+        * a value.  The value's type is assumed to match\r
+        * the type of this TypeId.  For example, a TypeId\r
+        * for the SQL int type should be given an value that evaluates\r
+        * to a Java int or Integer.\r
+        *\r
+        * If the type of the value is incorrect, the generated code will\r
+        * not work.\r
+        * \r
+        * The stack must contain data value factory value.\r
+        * \r
+        * @param mb    The method to put the expression in\r
+        * @param collationType For character DVDs, this will be used to determine\r
+        *   what Collator should be associated with the DVD which in turn will \r
+        *   decide whether to generate CollatorSQLcharDVDs or SQLcharDVDs. For \r
+        *   other types of DVDs, this parameter will be ignored.\r
+        * @param field LocalField\r
+        */\r
+       void generateDataValue(\r
+                       MethodBuilder mb, int collationType, \r
+                       LocalField field);\r
+\r
+       /**\r
+        * Return the maximum width for this data type when cast to a char type.\r
+        *\r
+        * @param dts           The associated DataTypeDescriptor for this TypeId.\r
+        *\r
+        * @return int                  The maximum width for this data type when cast to a char type.\r
+        */\r
+       int getCastToCharWidth(DataTypeDescriptor dts);\r
+\r
+}\r