* @throws QueryPlannerException
*/
private void planForDependencies(JoinRegion joinRegion) throws QueryPlannerException {
if (joinRegion.getJoinSourceNodes().isEmpty()) {
throw new QueryPlannerException(QueryPlugin.Util.getString("RulePlanJoins.cantSatisfy", joinRegion.getUnsatisfiedAccessPatterns())); //$NON-NLS-1$
}
HashSet<GroupSymbol> currentGroups = new HashSet<GroupSymbol>();
for (PlanNode joinSource : joinRegion.getJoinSourceNodes().keySet()) {
currentGroups.addAll(joinSource.getGroups());
}
HashMap<PlanNode, PlanNode> dependentNodes = new HashMap<PlanNode, PlanNode>(joinRegion.getDependentJoinSourceNodes());
boolean satisfiedAP = true;
while (!dependentNodes.isEmpty() && satisfiedAP) {
satisfiedAP = false;
for (Iterator<Map.Entry<PlanNode, PlanNode>> joinSources = dependentNodes.entrySet().iterator(); joinSources.hasNext();) {
Map.Entry<PlanNode, PlanNode> entry = joinSources.next();
PlanNode joinSource = entry.getKey();
Collection accessPatterns = (Collection)joinSource.getProperty(NodeConstants.Info.ACCESS_PATTERNS);
for (Iterator i = accessPatterns.iterator(); i.hasNext();) {
AccessPattern ap = (AccessPattern)i.next();
boolean foundGroups = true;
HashSet<GroupSymbol> allRequiredGroups = new HashSet<GroupSymbol>();
for (ElementSymbol symbol : ap.getUnsatisfied()) {
Set<Collection<GroupSymbol>> requiredGroupsSet = joinRegion.getDependentCriteriaElements().get(symbol);
boolean elementSatisfied = false;
if (requiredGroupsSet != null) {
for (Collection<GroupSymbol> requiredGroups : requiredGroupsSet) {
if (currentGroups.containsAll(requiredGroups)) {
elementSatisfied = true;
allRequiredGroups.addAll(requiredGroups);
break;
}
}
}
if (!elementSatisfied) {
foundGroups = false;
break;
}
}
if (!foundGroups) {
continue;
}
joinSources.remove();
satisfiedAP = true;
joinSource.setProperty(NodeConstants.Info.ACCESS_PATTERN_USED, ap.clone());
joinSource.setProperty(NodeConstants.Info.REQUIRED_ACCESS_PATTERN_GROUPS, allRequiredGroups);
break;
}
}
}
if (!dependentNodes.isEmpty()) {
throw new QueryPlannerException(QueryPlugin.Util.getString("RulePlanJoins.cantSatisfy", joinRegion.getUnsatisfiedAccessPatterns())); //$NON-NLS-1$
}
}