com.metamatrix.query.rewriter
Class VariableSubstitutionVisitor

java.lang.Object
  extended by com.metamatrix.query.sql.LanguageVisitor
      extended by com.metamatrix.query.sql.visitor.ExpressionMappingVisitor
          extended by com.metamatrix.query.rewriter.VariableSubstitutionVisitor

public class VariableSubstitutionVisitor
extends ExpressionMappingVisitor

This visitor class will traverse a language object tree, it finds variables in the language object and replaces the variable with a Reference obj.,/p>

This will also evaluate special variables INPUT and CHANGING by looking at the user's query, it finds these special variables it replaces the variable with a value(in case of INPUT) of the corresponding variable in set the user command or replace it with a constant of boolean value (in case CHANGING) indicating if the variable value is set on the user's command.

The easiest way to use this visitor is to call the static method which creates the the visitor by passing it the Language Object and the variable context to be looked up. The public visit() methods should NOT be called directly.


Constructor Summary
VariableSubstitutionVisitor(java.util.Map variableValues, int commandType)
          Construct a new visitor with the list of references.
 
Method Summary
 Expression replaceExpression(Expression expr)
          Common pattern used by visit methods in this Visitor
static void substituteVariables(LanguageObject obj, java.util.Map variableValues, int commandType)
          Helper to visit the language object specified and replace any variables a Reference obj, and collect the references returned.
 void visit(Update obj)
           
 void visit(XQuery obj)
           
 
Methods inherited from class com.metamatrix.query.sql.visitor.ExpressionMappingVisitor
createAliases, getVariableValues, mapExpressions, setVariableValues, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit
 
Methods inherited from class com.metamatrix.query.sql.LanguageVisitor
setAbort, shouldAbort, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VariableSubstitutionVisitor

public VariableSubstitutionVisitor(java.util.Map variableValues,
                                   int commandType)
Construct a new visitor with the list of references.

Parameters:
references - A list of references on to be collected
Method Detail

visit

public void visit(XQuery obj)
Overrides:
visit in class LanguageVisitor

visit

public void visit(Update obj)
Overrides:
visit in class LanguageVisitor

replaceExpression

public Expression replaceExpression(Expression expr)
Common pattern used by visit methods in this Visitor

Overrides:
replaceExpression in class ExpressionMappingVisitor
Parameters:
expr -
Returns:

substituteVariables

public static final void substituteVariables(LanguageObject obj,
                                             java.util.Map variableValues,
                                             int commandType)
                                      throws QueryValidatorException

Helper to visit the language object specified and replace any variables a Reference obj, and collect the references returned.

Parameters:
obj - The Language object that is to be visited
commandType - The command type of the user command invoking this procedure
forwardReferences - If references in the variable values should be substituted into expressions in this command
Throws:
QueryValidatorException
QueryValidatorException


Copyright © 2009. All Rights Reserved.