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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations