Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* ModeShape (http://www.modeshape.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.modeshape.jcr.query.optimize;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import org.modeshape.jcr.query.QueryContext;
import org.modeshape.jcr.query.model.Column;
import org.modeshape.jcr.query.model.Ordering;
import org.modeshape.jcr.query.model.PropertyValue;
import org.modeshape.jcr.query.model.ReferenceValue;
import org.modeshape.jcr.query.model.SelectorName;
import org.modeshape.jcr.query.model.Visitor;
import org.modeshape.jcr.query.model.Visitors;
import org.modeshape.jcr.query.plan.PlanNode;
import org.modeshape.jcr.query.plan.PlanNode.Property;
import org.modeshape.jcr.query.plan.PlanNode.Type;
/**
* An {@link OptimizerRule} that adds any missing columns required by the ordering specifications to the SORT node's PROJECT, and
* to the appropriate access nodes.
*/
public class AddOrderingColumnsToSources implements OptimizerRule {
public static final AddOrderingColumnsToSources INSTANCE = new AddOrderingColumnsToSources();
@Override
public PlanNode execute( QueryContext context,
PlanNode plan,
LinkedList ruleStack ) {
final boolean includeSourceName = context.getHints().qualifyExpandedColumnNames;
// For each of the SORT nodes ...
for (PlanNode sortNode : plan.findAllAtOrBelow(Type.SORT)) {
// Get the list of property and reference expressions that are used in the Ordering instances, using a visitor. Other
// kinds of
// dynamic operands in Ordering instances will not need to change the columns
final Set sortColumns = new HashSet();
Visitor columnVisitor = new Visitors.AbstractVisitor() {
@Override
public void visit( PropertyValue prop ) {
sortColumns.add(columnFor(prop.selectorName(), prop.getPropertyName(), includeSourceName));
}
@Override
public void visit( ReferenceValue ref ) {
sortColumns.add(columnFor(ref.selectorName(), ref.getPropertyName(), includeSourceName));
}
};
List