--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.impl.sql.execute.GenericQualifier\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.iapi.sql.Activation;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+\r
+import org.apache.derby.iapi.store.access.Qualifier;\r
+\r
+import org.apache.derby.iapi.types.DataValueDescriptor;\r
+\r
+import org.apache.derby.iapi.services.loader.GeneratedMethod;\r
+\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+\r
+/**\r
+ * This is the implementation for Qualifier. It is used for generated scans.\r
+ *\r
+ */\r
+\r
+public class GenericQualifier implements Qualifier\r
+{\r
+ private int columnId;\r
+ private int operator;\r
+ private GeneratedMethod orderableGetter;\r
+ private Activation activation;\r
+ private boolean orderedNulls;\r
+ private boolean unknownRV;\r
+ private boolean negateCompareResult;\r
+ protected int variantType;\r
+\r
+ private DataValueDescriptor orderableCache = null;\r
+\r
+ public GenericQualifier(int columnId,\r
+ int operator,\r
+ GeneratedMethod orderableGetter,\r
+ Activation activation,\r
+ boolean orderedNulls,\r
+ boolean unknownRV,\r
+ boolean negateCompareResult,\r
+ int variantType)\r
+ {\r
+ this.columnId = columnId;\r
+ this.operator = operator;\r
+ this.orderableGetter = orderableGetter;\r
+ this.activation = activation;\r
+ this.orderedNulls = orderedNulls;\r
+ this.unknownRV = unknownRV;\r
+ this.negateCompareResult = negateCompareResult;\r
+ this.variantType = variantType;\r
+ }\r
+\r
+ /* \r
+ * Qualifier interface\r
+ */\r
+\r
+ /** \r
+ * @see Qualifier#getColumnId\r
+ */\r
+ public int getColumnId()\r
+ {\r
+ return columnId;\r
+ }\r
+\r
+ /** \r
+ * @see Qualifier#getOrderable\r
+ *\r
+ * @exception StandardException Thrown on error\r
+ */\r
+ public DataValueDescriptor getOrderable() throws StandardException\r
+ {\r
+ if (variantType != VARIANT)\r
+ {\r
+ if (orderableCache == null)\r
+ {\r
+ orderableCache = (DataValueDescriptor) (orderableGetter.invoke(activation));\r
+ }\r
+ return orderableCache;\r
+ }\r
+ return (DataValueDescriptor) (orderableGetter.invoke(activation));\r
+ }\r
+\r
+ /** Get the operator to use in the comparison. \r
+ *\r
+ * @see Qualifier#getOperator\r
+ **/\r
+ public int getOperator()\r
+ {\r
+ return operator;\r
+ }\r
+\r
+ /** Should the result from the compare operation be negated? If true\r
+ * then only rows which fail the compare operation will qualify.\r
+ *\r
+ * @see Qualifier#negateCompareResult\r
+ **/\r
+ public boolean negateCompareResult()\r
+ {\r
+ return negateCompareResult;\r
+ }\r
+\r
+ /** Get the getOrderedNulls argument to use in the comparison. \r
+ * \r
+ * @see Qualifier#getOrderedNulls\r
+ **/\r
+ public boolean getOrderedNulls()\r
+ {\r
+ return orderedNulls;\r
+ }\r
+\r
+ /** Get the getOrderedNulls argument to use in the comparison.\r
+ * \r
+ * @see Qualifier#getUnknownRV\r
+ **/\r
+ public boolean getUnknownRV()\r
+ {\r
+ return unknownRV;\r
+ }\r
+\r
+ /** Clear the DataValueDescriptor cache, if one exists.\r
+ * (The DataValueDescriptor can be 1 of 3 types:\r
+ * o VARIANT - cannot be cached as its value can \r
+ * vary within a scan\r
+ * o SCAN_INVARIANT - can be cached within a scan as its\r
+ * value will not change within a scan\r
+ * o QUERY_INVARIANT- can be cached across the life of the query\r
+ * as its value will never change\r
+ * o CONSTANT - never changes\r
+ * \r
+ * @see Qualifier#getUnknownRV\r
+ */\r
+ public void clearOrderableCache()\r
+ {\r
+ if ((variantType == SCAN_INVARIANT) || (variantType == VARIANT))\r
+ {\r
+ orderableCache = null;\r
+ }\r
+ }\r
+ \r
+ /** \r
+ * This method reinitializes all the state of\r
+ * the Qualifier. It is used to distinguish between\r
+ * resetting something that is query invariant\r
+ * and something that is constant over every\r
+ * execution of a query. Basically, clearOrderableCache()\r
+ * will only clear out its cache if it is a VARIANT\r
+ * or SCAN_INVARIANT value. However, each time a\r
+ * query is executed, the QUERY_INVARIANT qualifiers need\r
+ * to be reset.\r
+ */\r
+ public void reinitialize()\r
+ {\r
+ if (variantType != CONSTANT)\r
+ {\r
+ orderableCache = null;\r
+ }\r
+ }\r
+\r
+ public String toString()\r
+ {\r
+ if (SanityManager.DEBUG)\r
+ {\r
+ return "columnId: "+columnId+\r
+ "\noperator: "+operator+\r
+ "\norderedNulls: "+orderedNulls+\r
+ "\nunknownRV: "+unknownRV+\r
+ "\nnegateCompareResult: "+negateCompareResult;\r
+ }\r
+ else\r
+ {\r
+ return "";\r
+ }\r
+ }\r
+}\r