Search in sources :

Example 1 with Constraint

use of javax.jcr.query.qom.Constraint in project jackrabbit by apache.

the class AbstractJoinTest method createQuery.

protected QueryObjectModel createQuery(String joinType, JoinCondition condition, Constraint left, Constraint right) throws RepositoryException {
    // only consider nodes under test root
    Constraint constraint;
    if (QueryObjectModelConstants.JCR_JOIN_TYPE_LEFT_OUTER.equals(joinType)) {
        constraint = qf.descendantNode(LEFT, testRoot);
    } else {
        constraint = qf.descendantNode(RIGHT, testRoot);
    }
    if (left != null) {
        constraint = qf.and(constraint, left);
    }
    if (right != null) {
        constraint = qf.and(constraint, right);
    }
    Join join = qf.join(qf.selector(testNodeType, LEFT), qf.selector(testNodeType, RIGHT), joinType, condition);
    return qf.createQuery(join, constraint, null, null);
}
Also used : Constraint(javax.jcr.query.qom.Constraint) Join(javax.jcr.query.qom.Join)

Example 2 with Constraint

use of javax.jcr.query.qom.Constraint in project jackrabbit by apache.

the class QueryEngine method buildRightRowsJoin.

/**
     * @param csi
     *            contains 'WHERE' constraints and the source information
     * @param rightConstraints
     *            contains 'ON' constraints
     * @param ignoreWhereConstraints
     * @param comparator
     *            used to merge similar rows together
     * @param printIndentation
     *            used in logging
     * @return the right-side dataset of the join operation
     * @throws RepositoryException
     */
private Set<Row> buildRightRowsJoin(ConstraintSplitInfo csi, List<Constraint> rightConstraints, boolean ignoreWhereConstraints, Comparator<Row> comparator, int printIndentation) throws RepositoryException {
    if (csi.isMultiple()) {
        if (log.isDebugEnabled()) {
            log.debug(genString(printIndentation) + "SQL2 JOIN RIGHT SIDE there are multiple inner splits.");
        }
        Set<Row> rightRows = new TreeSet<Row>(comparator);
        rightRows.addAll(buildRightRowsJoin(csi.getLeftInnerConstraints(), rightConstraints, ignoreWhereConstraints, comparator, printIndentation + printIndentStep));
        rightRows.addAll(buildRightRowsJoin(csi.getRightInnerConstraints(), rightConstraints, ignoreWhereConstraints, comparator, printIndentation + printIndentStep));
        return rightRows;
    }
    if (rightConstraints.size() < 500) {
        Set<Row> rightRows = new TreeSet<Row>(comparator);
        List<Constraint> localRightContraints = rightConstraints;
        Constraint rightConstraint = Constraints.and(qomFactory, Constraints.or(qomFactory, localRightContraints), csi.getRightConstraint());
        if (ignoreWhereConstraints) {
            rightConstraint = Constraints.or(qomFactory, localRightContraints);
        }
        QueryResult rightResult = execute(null, csi.getSource().getRight(), rightConstraint, null, 0, -1, printIndentation);
        for (Row row : JcrUtils.getRows(rightResult)) {
            rightRows.add(row);
        }
        return rightRows;
    }
    // the 'batch by 500' approach
    Set<Row> rightRows = new TreeSet<Row>(comparator);
    for (int i = 0; i < rightConstraints.size(); i += 500) {
        if (log.isDebugEnabled()) {
            log.debug(genString(printIndentation) + "SQL2 JOIN RIGHT SIDE executing batch # " + i + ".");
        }
        List<Constraint> localRightContraints = rightConstraints.subList(i, Math.min(i + 500, rightConstraints.size()));
        Constraint rightConstraint = Constraints.and(qomFactory, Constraints.or(qomFactory, localRightContraints), csi.getRightConstraint());
        if (ignoreWhereConstraints) {
            rightConstraint = Constraints.or(qomFactory, localRightContraints);
        }
        QueryResult rightResult = execute(null, csi.getSource().getRight(), rightConstraint, null, 0, -1, printIndentation);
        for (Row row : JcrUtils.getRows(rightResult)) {
            rightRows.add(row);
        }
    }
    return rightRows;
}
Also used : QueryResult(javax.jcr.query.QueryResult) Constraint(javax.jcr.query.qom.Constraint) TreeSet(java.util.TreeSet) Row(javax.jcr.query.Row) Constraint(javax.jcr.query.qom.Constraint)

Example 3 with Constraint

use of javax.jcr.query.qom.Constraint in project jackrabbit by apache.

the class DescendantNodeJoinMerger method getRightJoinConstraints.

@Override
public List<Constraint> getRightJoinConstraints(Collection<Row> leftRows) throws RepositoryException {
    Set<String> paths = new HashSet<String>();
    for (Row row : leftRows) {
        paths.addAll(getLeftValues(row));
    }
    List<Constraint> constraints = new ArrayList<Constraint>();
    for (String path : paths) {
        if (rightSelectors.contains(descendantSelector)) {
            constraints.add(factory.descendantNode(descendantSelector, path));
        } else {
            constraints.add(factory.sameNode(ancestorSelector, path));
        }
    }
    return constraints;
}
Also used : Constraint(javax.jcr.query.qom.Constraint) ArrayList(java.util.ArrayList) Row(javax.jcr.query.Row) HashSet(java.util.HashSet)

Example 4 with Constraint

use of javax.jcr.query.qom.Constraint in project jackrabbit by apache.

the class EquiJoinMerger method getRightJoinConstraints.

@Override
public List<Constraint> getRightJoinConstraints(Collection<Row> leftRows) throws RepositoryException {
    Map<String, Literal> literals = new HashMap<String, Literal>();
    for (Row leftRow : leftRows) {
        for (Value value : evaluator.getValues(leftProperty, leftRow)) {
            literals.put(value.getString(), factory.literal(value));
        }
    }
    List<Constraint> constraints = new ArrayList<Constraint>(literals.size());
    for (Literal literal : literals.values()) {
        constraints.add(factory.comparison(rightProperty, JCR_OPERATOR_EQUAL_TO, literal));
    }
    return constraints;
}
Also used : HashMap(java.util.HashMap) Constraint(javax.jcr.query.qom.Constraint) Literal(javax.jcr.query.qom.Literal) Value(javax.jcr.Value) PropertyValue(javax.jcr.query.qom.PropertyValue) ArrayList(java.util.ArrayList) Row(javax.jcr.query.Row)

Example 5 with Constraint

use of javax.jcr.query.qom.Constraint in project jackrabbit by apache.

the class SameNodeJoinMerger method getRightJoinConstraints.

@Override
public List<Constraint> getRightJoinConstraints(Collection<Row> leftRows) throws RepositoryException {
    Set<String> paths = new HashSet<String>();
    for (Row row : leftRows) {
        paths.addAll(getLeftValues(row));
    }
    List<Constraint> constraints = new ArrayList<Constraint>();
    for (String path : paths) {
        if (rightSelectors.contains(selector1)) {
            constraints.add(factory.sameNode(selector1, path));
        } else {
            constraints.add(factory.sameNode(selector2, path));
        }
    }
    return constraints;
}
Also used : Constraint(javax.jcr.query.qom.Constraint) ArrayList(java.util.ArrayList) Row(javax.jcr.query.Row) HashSet(java.util.HashSet)

Aggregations

Constraint (javax.jcr.query.qom.Constraint)25 Row (javax.jcr.query.Row)7 Column (javax.jcr.query.qom.Column)6 ArrayList (java.util.ArrayList)5 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)5 Test (org.junit.Test)5 Or (javax.jcr.query.qom.Or)4 Ordering (javax.jcr.query.qom.Ordering)4 QueryObjectModel (javax.jcr.query.qom.QueryObjectModel)4 Source (javax.jcr.query.qom.Source)4 HashSet (java.util.HashSet)3 And (javax.jcr.query.qom.And)3 Not (javax.jcr.query.qom.Not)3 PropertyValue (javax.jcr.query.qom.PropertyValue)3 TreeSet (java.util.TreeSet)2 RepositoryException (javax.jcr.RepositoryException)2 QueryResult (javax.jcr.query.QueryResult)2 BindVariableValue (javax.jcr.query.qom.BindVariableValue)2 QueryObjectModelFactory (javax.jcr.query.qom.QueryObjectModelFactory)2 Selector (javax.jcr.query.qom.Selector)2