001: /*
002:
003: Derby - Class org.apache.derby.impl.sql.compile.HasCorrelatedCRsVisitor
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.impl.sql.compile;
023:
024: import org.apache.derby.iapi.services.sanity.SanityManager;
025: import org.apache.derby.iapi.sql.compile.Visitable;
026: import org.apache.derby.iapi.sql.compile.Visitor;
027:
028: import org.apache.derby.iapi.store.access.Qualifier;
029: import org.apache.derby.iapi.error.StandardException;
030:
031: /**
032: * Find out if we have an correlated column reference
033: * anywhere below us. Stop traversal as soon as we find one.
034: *
035: * @author jamie
036: */
037: public class HasCorrelatedCRsVisitor implements Visitor {
038: private boolean hasCorrelatedCRs;
039:
040: /**
041: * Construct a visitor
042: */
043: public HasCorrelatedCRsVisitor() {
044: }
045:
046: ////////////////////////////////////////////////
047: //
048: // VISITOR INTERFACE
049: //
050: ////////////////////////////////////////////////
051:
052: /**
053: * If we have found the target node, we are done.
054: *
055: * @param node the node to process
056: *
057: * @return me
058: */
059: public Visitable visit(Visitable node) {
060: if (node instanceof ColumnReference) {
061: if (((ColumnReference) node).getCorrelated()) {
062: hasCorrelatedCRs = true;
063: }
064: } else if (node instanceof VirtualColumnNode) {
065: if (((VirtualColumnNode) node).getCorrelated()) {
066: hasCorrelatedCRs = true;
067: }
068: } else if (node instanceof MethodCallNode) {
069: /* trigger action references are correlated
070: */
071: if (((MethodCallNode) node).getMethodName().equals(
072: "getTriggerExecutionContext")
073: || ((MethodCallNode) node).getMethodName().equals(
074: "TriggerOldTransitionRows")
075: || ((MethodCallNode) node).getMethodName().equals(
076: "TriggerNewTransitionRows")) {
077: hasCorrelatedCRs = true;
078: }
079: }
080: return node;
081: }
082:
083: /**
084: * Stop traversal if we found the target node
085: *
086: * @return true/false
087: */
088: public boolean stopTraversal() {
089: return hasCorrelatedCRs;
090: }
091:
092: public boolean skipChildren(Visitable v) {
093: return false;
094: }
095:
096: ////////////////////////////////////////////////
097: //
098: // CLASS INTERFACE
099: //
100: ////////////////////////////////////////////////
101: /**
102: * Indicate whether we found the node in
103: * question
104: *
105: * @return true/false
106: */
107: public boolean hasCorrelatedCRs() {
108: return hasCorrelatedCRs;
109: }
110:
111: /**
112: * Shortcut to set if hasCorrelatedCRs
113: *
114: * @param value true/false
115: */
116: public void setHasCorrelatedCRs(boolean value) {
117: hasCorrelatedCRs = value;
118: }
119: }
|