Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / MyDerby-10.3 / java / engine / org / apache / derby / impl / sql / execute / BaseExpressionActivation.java
diff --git a/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/impl/sql/execute/BaseExpressionActivation.java b/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/impl/sql/execute/BaseExpressionActivation.java
new file mode 100644 (file)
index 0000000..2a76f17
--- /dev/null
@@ -0,0 +1,131 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.sql.execute.BaseExpressionActivation\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.execute;\r
+\r
+import org.apache.derby.catalog.types.UserDefinedTypeIdImpl;\r
+import org.apache.derby.iapi.error.StandardException;\r
+import org.apache.derby.iapi.types.DataValueDescriptor;\r
+import org.apache.derby.iapi.types.TypeId;\r
+\r
+/**\r
+ * BaseExpressionActivation\r
+ *\r
+ * Support needed by Expression evaluators (Filters) and by\r
+ * ResultSet materializers (Activations)\r
+ */\r
+public abstract class BaseExpressionActivation\r
+{\r
+\r
+       \r
+       //\r
+       // constructors\r
+       //\r
+       BaseExpressionActivation()\r
+       {\r
+               super();\r
+       }\r
+\r
+\r
+       /**\r
+        * Get the minimum value of 4 input values.  If less than 4 values, input\r
+        * NULL.  If more than 4 input values, call this multiple times to\r
+        * accumulate results.  Also have judge's type as parameter to have a base\r
+        * upon which the comparison is based.  An example use is for code \r
+        * generation in bug 3858.\r
+        * \r
+        * @param v1            1st value\r
+        * @param v2            2nd value\r
+        * @param v3            3rd value\r
+        * @param v4            4th value\r
+        * @param judgeTypeFormatId             type format id of the judge\r
+        * @param judgeUserJDBCTypeId   JDBC type id if judge is user type;\r
+        *                                                              -1 if not user type\r
+        *\r
+        * @return      The minimum value of the 4.\r
+        */\r
+       public static DataValueDescriptor minValue(DataValueDescriptor v1,\r
+                                                                                         DataValueDescriptor v2,\r
+                                                                                         DataValueDescriptor v3,\r
+                                                                                         DataValueDescriptor v4,\r
+                                                                                         int judgeTypeFormatId,\r
+                                                                                         int judgeUserJDBCTypeId)\r
+                                                                               throws StandardException\r
+       {\r
+               DataValueDescriptor judge;\r
+               if (judgeUserJDBCTypeId == -1)\r
+                       judge = (DataValueDescriptor) new TypeId(judgeTypeFormatId, null).getNull();\r
+               else\r
+                       judge = (DataValueDescriptor) new TypeId(judgeTypeFormatId, new UserDefinedTypeIdImpl()).getNull();\r
+                       \r
+               DataValueDescriptor minVal = v1;\r
+               if (v2 != null && judge.lessThan(v2, minVal).equals(true))\r
+                       minVal = v2;\r
+               if (v3 != null && judge.lessThan(v3, minVal).equals(true))\r
+                       minVal = v3;\r
+               if (v4 != null && judge.lessThan(v4, minVal).equals(true))\r
+                       minVal = v4;\r
+               return minVal;\r
+       }\r
+\r
+\r
+       /**\r
+        * Get the maximum value of 4 input values.  If less than 4 values, input\r
+        * NULL.  If more than 4 input values, call this multiple times to\r
+        * accumulate results.  Also have judge's type as parameter to have a base\r
+        * upon which the comparison is based.  An example use is for code \r
+        * generation in bug 3858.\r
+        * \r
+        * @param v1            1st value\r
+        * @param v2            2nd value\r
+        * @param v3            3rd value\r
+        * @param v4            4th value\r
+        * @param judgeTypeFormatId             type format id of the judge\r
+        * @param judgeUserJDBCTypeId   JDBC type id if judge is user type;\r
+        *                                                              -1 if not user type\r
+        *\r
+        * @return      The maximum value of the 4.\r
+        */\r
+       public static DataValueDescriptor maxValue(DataValueDescriptor v1,\r
+                                                                                         DataValueDescriptor v2,\r
+                                                                                         DataValueDescriptor v3,\r
+                                                                                         DataValueDescriptor v4,\r
+                                                                                         int judgeTypeFormatId,\r
+                                                                                         int judgeUserJDBCTypeId)\r
+                                                                               throws StandardException\r
+       {\r
+               DataValueDescriptor judge;\r
+               if (judgeUserJDBCTypeId == -1)\r
+                       judge =  new TypeId(judgeTypeFormatId, null).getNull();\r
+               else\r
+                       judge =  new TypeId(judgeTypeFormatId, new UserDefinedTypeIdImpl()).getNull();\r
+\r
+               DataValueDescriptor maxVal = v1;\r
+               if (v2 != null && judge.greaterThan(v2, maxVal).equals(true))\r
+                       maxVal = v2;\r
+               if (v3 != null && judge.greaterThan(v3, maxVal).equals(true))\r
+                       maxVal = v3;\r
+               if (v4 != null && judge.greaterThan(v4, maxVal).equals(true))\r
+                       maxVal = v4;\r
+               return maxVal;\r
+       }\r
+\r
+}\r