--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.impl.sql.compile.HasCorrelatedCRsVisitor\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.sanity.SanityManager;\r
+import org.apache.derby.iapi.sql.compile.Visitable; \r
+import org.apache.derby.iapi.sql.compile.Visitor;\r
+\r
+\r
+import org.apache.derby.iapi.store.access.Qualifier;\r
+import org.apache.derby.iapi.error.StandardException;\r
+\r
+/**\r
+ * Find out if we have an correlated column reference\r
+ * anywhere below us. Stop traversal as soon as we find one.\r
+ *\r
+ */\r
+public class HasCorrelatedCRsVisitor implements Visitor\r
+{\r
+ private boolean hasCorrelatedCRs;\r
+\r
+ /**\r
+ * Construct a visitor\r
+ */\r
+ public HasCorrelatedCRsVisitor()\r
+ {\r
+ }\r
+\r
+\r
+\r
+ ////////////////////////////////////////////////\r
+ //\r
+ // VISITOR INTERFACE\r
+ //\r
+ ////////////////////////////////////////////////\r
+\r
+ /**\r
+ * If we have found the target node, we are done.\r
+ *\r
+ * @param node the node to process\r
+ *\r
+ * @return me\r
+ */\r
+ public Visitable visit(Visitable node)\r
+ {\r
+ if (node instanceof ColumnReference)\r
+ {\r
+ if (((ColumnReference)node).getCorrelated())\r
+ {\r
+ hasCorrelatedCRs = true;\r
+ }\r
+ }\r
+ else if (node instanceof VirtualColumnNode)\r
+ {\r
+ if (((VirtualColumnNode)node).getCorrelated())\r
+ {\r
+ hasCorrelatedCRs = true;\r
+ }\r
+ }\r
+ else if (node instanceof MethodCallNode)\r
+ {\r
+ /* trigger action references are correlated\r
+ */\r
+ if (((MethodCallNode)node).getMethodName().equals("getTriggerExecutionContext") ||\r
+ ((MethodCallNode)node).getMethodName().equals("TriggerOldTransitionRows") ||\r
+ ((MethodCallNode)node).getMethodName().equals("TriggerNewTransitionRows")\r
+ )\r
+ {\r
+ hasCorrelatedCRs = true;\r
+ }\r
+ }\r
+ return node;\r
+ }\r
+\r
+ /**\r
+ * Stop traversal if we found the target node\r
+ *\r
+ * @return true/false\r
+ */\r
+ public boolean stopTraversal()\r
+ {\r
+ return hasCorrelatedCRs;\r
+ }\r
+\r
+ public boolean skipChildren(Visitable v)\r
+ {\r
+ return false;\r
+ }\r
+\r
+ ////////////////////////////////////////////////\r
+ //\r
+ // CLASS INTERFACE\r
+ //\r
+ ////////////////////////////////////////////////\r
+ /**\r
+ * Indicate whether we found the node in\r
+ * question\r
+ *\r
+ * @return true/false\r
+ */\r
+ public boolean hasCorrelatedCRs()\r
+ {\r
+ return hasCorrelatedCRs;\r
+ }\r
+\r
+ /**\r
+ * Shortcut to set if hasCorrelatedCRs\r
+ *\r
+ * @param value true/false\r
+ */\r
+ public void setHasCorrelatedCRs(boolean value)\r
+ {\r
+ hasCorrelatedCRs = value;\r
+ }\r
+}\r