All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.adobe.cq.searchcollections.qom.DescendantNodeJoinMerger Maven / Gradle / Ivy

/*************************************************************************
 *
 * ADOBE CONFIDENTIAL
 * __________________
 *
 *  Copyright 2012 Adobe Systems Incorporated
 *  All Rights Reserved.
 *
 * NOTICE:  All information contained herein is, and remains
 * the property of Adobe Systems Incorporated and its suppliers,
 * if any.  The intellectual and technical concepts contained
 * herein are proprietary to Adobe Systems Incorporated and its
 * suppliers and are protected by trade secret or copyright law.
 * Dissemination of this information or reproduction of this material
 * is strictly forbidden unless prior written permission is obtained
 * from Adobe Systems Incorporated.
 **************************************************************************/
package com.adobe.cq.searchcollections.qom;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.query.Row;
import javax.jcr.query.qom.Constraint;
import javax.jcr.query.qom.DescendantNodeJoinCondition;
import javax.jcr.query.qom.Join;
import javax.jcr.query.qom.PropertyValue;
import javax.jcr.query.qom.QueryObjectModelFactory;

/**
 * @deprecated
 */
class DescendantNodeJoinMerger extends JoinMerger {

    private final String descendantSelector;

    private final String ancestorSelector;

    public DescendantNodeJoinMerger(
            Join join, Map columns,
            OperandEvaluator evaluator, QueryObjectModelFactory factory,
            DescendantNodeJoinCondition condition)
            throws RepositoryException {
        super(join, columns, evaluator, factory);
        this.descendantSelector = condition.getDescendantSelectorName();
        this.ancestorSelector = condition.getAncestorSelectorName();
    }

    @Override
    public Set getLeftValues(Row row) throws RepositoryException {
        return getValues(leftSelectors, row);
    }

    @Override
    public Set getRightValues(Row row) throws RepositoryException {
        return getValues(rightSelectors, row);
    }

    @Override
    public List getRightJoinConstraints(List leftRows)
            throws RepositoryException {
        Set paths = new HashSet();
        for (Row row : leftRows) {
            paths.addAll(getLeftValues(row));
        }

        List constraints = new ArrayList();
        for (String path : paths) {
            if (rightSelectors.contains(descendantSelector)) {
                constraints.add(
                        factory.descendantNode(descendantSelector, path));
            } else {
                constraints.add(factory.sameNode(ancestorSelector, path));
            }
        }
        return constraints;
    }

    private Set getValues(Set selectors, Row row)
            throws RepositoryException {
        if (selectors.contains(descendantSelector)) {
            Node node = row.getNode(descendantSelector);
            if (node != null) {
                Set values = new HashSet();
                while (node.getDepth() > 0) {
                    node = node.getParent();
                    values.add(node.getPath());
                }
                return values;
            }
        } else if (selectors.contains(ancestorSelector)) {
            Node node = row.getNode(ancestorSelector);
            if (node != null) {
                return Collections.singleton(node.getPath());
            }
        } else {
            throw new RepositoryException("Invalid descendant node join");
        }
        return Collections.emptySet();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy