/* special handling is needed to determine criteria placement.
*
* if the join is a left outer join, criteria from the right side will be added to the on clause
*/
Criteria savedCriteria = null;
buildQuery(accessRoot, left, query, metadata, capFinder);
if (joinType == JoinType.JOIN_LEFT_OUTER) {
savedCriteria = query.getCriteria();
query.setCriteria(null);
}
buildQuery(accessRoot, right, query, metadata, capFinder);
if (joinType == JoinType.JOIN_LEFT_OUTER) {
moveWhereClauseIntoOnClause(query, crits);
query.setCriteria(savedCriteria);
}
// Get last two clauses added to the FROM and combine them into a JoinPredicate
From from = query.getFrom();
List clauses = from.getClauses();
int lastClause = clauses.size()-1;
FromClause clause1 = (FromClause) clauses.get(lastClause-1);
FromClause clause2 = (FromClause) clauses.get(lastClause);
//correct the criteria or the join type if necessary
if (joinType != JoinType.JOIN_CROSS && crits.isEmpty()) {
crits.add(QueryRewriter.TRUE_CRITERIA);
} else if (joinType == JoinType.JOIN_CROSS && !crits.isEmpty()) {
joinType = JoinType.JOIN_INNER;
}
JoinPredicate jp = new JoinPredicate(clause1, clause2, joinType, crits);
// Replace last two clauses with new predicate
clauses.remove(lastClause);
clauses.set(lastClause-1, jp);
return;
}
case NodeConstants.Types.SOURCE:
{
if (Boolean.TRUE.equals(node.getProperty(NodeConstants.Info.INLINE_VIEW))) {
PlanNode child = node.getFirstChild();
QueryCommand newQuery = createQuery(metadata, capFinder, accessRoot, child);
//ensure that the group is consistent
GroupSymbol symbol = node.getGroups().iterator().next();
SubqueryFromClause sfc = new SubqueryFromClause(symbol, newQuery);
query.getFrom().addClause(sfc);
return;
}
query.getFrom().addGroup(node.getGroups().iterator().next());
break;
}
}
for (PlanNode childNode : node.getChildren()) {
buildQuery(accessRoot, childNode, query, metadata, capFinder);
}
switch(node.getType()) {
case NodeConstants.Types.SELECT:
{
Criteria crit = (Criteria) node.getProperty(NodeConstants.Info.SELECT_CRITERIA);
prepareSubqueries(node.getSubqueryContainers());
if(!node.hasBooleanProperty(NodeConstants.Info.IS_HAVING)) {
query.setCriteria( CompoundCriteria.combineCriteria(query.getCriteria(), crit) );
} else {
query.setHaving( CompoundCriteria.combineCriteria(query.getHaving(), crit) );