saffron.rel
Class SaffronQueryExpander
java.lang.Object
|
+--openjava.ptree.util.ParseTreeVisitor
|
+--openjava.ptree.util.EvaluationShuttle
|
+--openjava.ptree.util.ScopeHandler
|
+--openjava.ptree.util.QueryExpander
|
+--saffron.rel.SaffronQueryExpander
- public class SaffronQueryExpander
- extends QueryExpander
SaffronQueryExpander
passes over a parse tree, and converts
relational expressions into regular Java constructs.
- Since:
- 22 September, 2001
- Version:
- $Id: //open/saffron/src/main/saffron/rel/SaffronQueryExpander.java#10 $
- Author:
- jhyde
Fields inherited from class openjava.ptree.util.ScopeHandler |
|
Method Summary |
Rel |
convertExpToRel(Expression exp,
boolean eager,
CallingConvention convention,
Variable variable,
StatementList body)
Converts an expression to a relational expression according to a
particular calling convention, and optimizes it. |
(package private) Rel |
convertExpToRel(Expression exp,
boolean eager,
QueryInfo queryInfo,
OJClass desiredRowType)
Convert an expression to a relation, if it is relational, otherwise
return null. |
private Expression |
convertRelToExp(Rel rel)
|
private Expression |
expandExists(Expression exp)
|
private Expression |
expandExpression_(Expression exp,
OJClass desiredRowType,
CallingConvention convention)
Converts an Expression into a java expression which returns an
array. |
protected Expression |
expandExpression(Expression exp)
Converts an Expression into a java expression which returns an
array. |
protected Statement |
expandForIn(Variable variable,
Expression exp,
StatementList body)
Converts an Expression of the form for (variable in
exp) { body } into a regular java Statement . |
private Expression |
expandIn(Expression seekExp,
Expression queryExp)
Translates an expression involving in . |
Type |
getRootRowType()
|
Methods inherited from class openjava.ptree.util.ScopeHandler |
evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, pop, push, pushClosedEnvironment |
Methods inherited from class openjava.ptree.util.EvaluationShuttle |
evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateDown, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, evaluateUp, getEnvironment, setEnvironment, 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, 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 |
rootRowType
private Type rootRowType
SaffronQueryExpander
public SaffronQueryExpander(Environment env)
expandExpression
protected Expression expandExpression(Expression exp)
- Description copied from class:
QueryExpander
- Converts an
Expression
into a java expression which returns an
array.
- Specified by:
expandExpression
in class QueryExpander
expandExpression_
private Expression expandExpression_(Expression exp,
OJClass desiredRowType,
CallingConvention convention)
- Converts an
Expression
into a java expression which returns an
array. Examples:
- Query as expression
Emp[] femaleEmps = (select emp from emps as emp
where emp.gender.equals("F"));
becomes
Emp[] femaleEmps = new Object() {
public Emp[] asArray() {
Vector v = new Vector();
for (i in (select emp from emps as emp
where emp.gender.equals("F"))) {
v.addElement(i);
}
Emp[] a = new Emp[v.size()];
v.copyInto(a);
return a;
}
}.asArray();
- Parameters:
desiredRowType
- row type required; if this is null, leave the
results as they areconvention
- calling convention of the result
getRootRowType
public Type getRootRowType()
- Returns:
- the row Type for the root relational expression encountered
during last expansion, or null if none
expandForIn
protected Statement expandForIn(Variable variable,
Expression exp,
StatementList body)
- Converts an
Expression
of the form for (variable in
exp) { body }
into a regular java Statement
.
- Specified by:
expandForIn
in class QueryExpander
convertExpToRel
public Rel convertExpToRel(Expression exp,
boolean eager,
CallingConvention convention,
Variable variable,
StatementList body)
- Converts an expression to a relational expression according to a
particular calling convention, and optimizes it.
- Parameters:
exp
- expression to converteager
- whether to try to convert expressions which
might not be relational, for example arraysconvention
- calling convention (see CallingConvention
)variable
- iterator variable (for for
-loop)body
- statement list to add code to
- Returns:
- the optimal relational expression
convertExpToRel
Rel convertExpToRel(Expression exp,
boolean eager,
QueryInfo queryInfo,
OJClass desiredRowType)
- Convert an expression to a relation, if it is relational, otherwise
return null. This method only deals with relational expressions which
can occur outside a query; joins, in particular, are only dealt with
inside queries.
- Parameters:
exp
- expression to translateeager
- whether to translate expressions which may or may not be
(such as references to arrays) into relational expressionsqueryInfo
- context to convert expressions into results of other
queries; null if this expression is not inside a querydesiredRowType
- row type required; if this is null, leave the
results as they are
- Returns:
- a relational expression, or null if the expression was not
relational
expandIn
private Expression expandIn(Expression seekExp,
Expression queryExp)
- Translates an expression involving
in
. For example,
if ("Fred" in (select name from emps as emp)) {
yes();
}
becomes in
within a query
if (exists (
select where "Joe" in (select name from emps as emp))) {
yes();
}
expandExists
private Expression expandExists(Expression exp)
convertRelToExp
private Expression convertRelToExp(Rel rel)