Class OffsetOrderVisitor<T extends QueryTreeNode>
java.lang.Object
org.apache.derby.impl.sql.compile.OffsetOrderVisitor<T>
- Type Parameters:
T
- the type of nodes to collect
- All Implemented Interfaces:
Visitor
Get all nodes of a certain type in a query tree, and return them in
the order in which they appear in the original SQL text. This visitor
is useful when rewriting SQL queries by replacing certain tokens in
the original query.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Comparator
<QueryTreeNode> Comparator that orders nodes by ascending begin offset.private final int
private final int
-
Constructor Summary
ConstructorsConstructorDescriptionOffsetOrderVisitor
(Class<T> nodeClass, int low, int high) Create a newOffsetOrderVisitor
that collects nodes of the specified type. -
Method Summary
Modifier and TypeMethodDescriptiongetNodes()
boolean
skipChildren
(Visitable node) Method that is called to indicate whether we should skip all nodes below this node for traversal.boolean
Method that is called to see if query tree traversal should be stopped before visiting all nodes.This is the default visit operation on a QueryTreeNode.boolean
visitChildrenFirst
(Visitable node) Method that is called to see ifvisit()
should be called on the children ofnode
before it is called onnode
itself.
-
Field Details
-
COMPARATOR
Comparator that orders nodes by ascending begin offset. -
nodeClass
-
nodes
-
lowOffset
private final int lowOffset -
highOffset
private final int highOffset
-
-
Constructor Details
-
OffsetOrderVisitor
Create a newOffsetOrderVisitor
that collects nodes of the specified type. The nodes must have begin offset and end offset in the range given by thelow
andhigh
parameters.- Parameters:
nodeClass
- the type of nodes to collectlow
- the lowest begin offset to accept (inclusive)high
- the highest end offset to accept (exclusive)
-
-
Method Details
-
visit
Description copied from interface:Visitor
This is the default visit operation on a QueryTreeNode. It just returns the node. This will typically suffice as the default visit operation for most visitors unless the visitor needs to count the number of nodes visited or something like that.Visitors will overload this method by implementing a version with a signature that matches a specific type of node. For example, if I want to do something special with aggregate nodes, then that Visitor will implement a visit(AggregateNode node) method which does the aggregate specific processing.
- Specified by:
visit
in interfaceVisitor
- Parameters:
node
- the node to process- Returns:
- a query tree node. Often times this is the same node that was passed in, but Visitors that replace nodes with other nodes will use this to return the new replacement node.
- Throws:
StandardException
- may be throw an error as needed by the visitor (i.e. may be a normal error if a particular node is found, e.g. if checking a group by, we don't expect to find any ColumnReferences that aren't under an AggregateNode -- the easiest thing to do is just throw an error when we find the questionable node).
-
visitChildrenFirst
Description copied from interface:Visitor
Method that is called to see ifvisit()
should be called on the children ofnode
before it is called onnode
itself. If this method always returnstrue
, the visitor will walk the tree bottom-up. If it always returnsfalse
, the tree is visited top-down.- Specified by:
visitChildrenFirst
in interfaceVisitor
- Parameters:
node
- the top node of a sub-tree about to be visited- Returns:
true
ifnode
's children should be visited beforenode
,false
otherwise
-
stopTraversal
public boolean stopTraversal()Description copied from interface:Visitor
Method that is called to see if query tree traversal should be stopped before visiting all nodes. Useful for short circuiting traversal if we already know we are done.- Specified by:
stopTraversal
in interfaceVisitor
- Returns:
- true/false
-
skipChildren
Description copied from interface:Visitor
Method that is called to indicate whether we should skip all nodes below this node for traversal. Useful if we want to effectively ignore/prune all branches under a particular node.Differs from stopTraversal() in that it only affects subtrees, rather than the entire traversal.
- Specified by:
skipChildren
in interfaceVisitor
- Parameters:
node
- the node to process- Returns:
- true/false
- Throws:
StandardException
-
getNodes
-