KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > compile > HasCorrelatedCRsVisitor


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.compile.HasCorrelatedCRsVisitor
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.sql.compile;
23
24 import org.apache.derby.iapi.services.sanity.SanityManager;
25 import org.apache.derby.iapi.sql.compile.Visitable;
26 import org.apache.derby.iapi.sql.compile.Visitor;
27
28
29 import org.apache.derby.iapi.store.access.Qualifier;
30 import org.apache.derby.iapi.error.StandardException;
31
32 /**
33  * Find out if we have an correlated column reference
34  * anywhere below us. Stop traversal as soon as we find one.
35  *
36  * @author jamie
37  */

38 public class HasCorrelatedCRsVisitor implements Visitor
39 {
40     private boolean hasCorrelatedCRs;
41
42     /**
43      * Construct a visitor
44      */

45     public HasCorrelatedCRsVisitor()
46     {
47     }
48
49
50
51     ////////////////////////////////////////////////
52
//
53
// VISITOR INTERFACE
54
//
55
////////////////////////////////////////////////
56

57     /**
58      * If we have found the target node, we are done.
59      *
60      * @param node the node to process
61      *
62      * @return me
63      */

64     public Visitable visit(Visitable node)
65     {
66         if (node instanceof ColumnReference)
67         {
68             if (((ColumnReference)node).getCorrelated())
69             {
70                 hasCorrelatedCRs = true;
71             }
72         }
73         else if (node instanceof VirtualColumnNode)
74         {
75             if (((VirtualColumnNode)node).getCorrelated())
76             {
77                 hasCorrelatedCRs = true;
78             }
79         }
80         else if (node instanceof MethodCallNode)
81         {
82             /* trigger action references are correlated
83              */

84             if (((MethodCallNode)node).getMethodName().equals("getTriggerExecutionContext") ||
85                 ((MethodCallNode)node).getMethodName().equals("TriggerOldTransitionRows") ||
86                 ((MethodCallNode)node).getMethodName().equals("TriggerNewTransitionRows")
87                )
88             {
89                 hasCorrelatedCRs = true;
90             }
91         }
92         return node;
93     }
94
95     /**
96      * Stop traversal if we found the target node
97      *
98      * @return true/false
99      */

100     public boolean stopTraversal()
101     {
102         return hasCorrelatedCRs;
103     }
104
105     public boolean skipChildren(Visitable v)
106     {
107         return false;
108     }
109
110     ////////////////////////////////////////////////
111
//
112
// CLASS INTERFACE
113
//
114
////////////////////////////////////////////////
115
/**
116      * Indicate whether we found the node in
117      * question
118      *
119      * @return true/false
120      */

121     public boolean hasCorrelatedCRs()
122     {
123         return hasCorrelatedCRs;
124     }
125
126     /**
127      * Shortcut to set if hasCorrelatedCRs
128      *
129      * @param value true/false
130      */

131     public void setHasCorrelatedCRs(boolean value)
132     {
133         hasCorrelatedCRs = value;
134     }
135 }
136
Popular Tags