use of javax.jcr.query.qom.Join 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.Join in project jackrabbit-oak by apache.
the class QomTest method join.
@Test
public void join() throws RepositoryException {
Source left = f.selector("nodeTypeName", "selectorName");
Source right = f.selector("nodeTypeName2", "selectorName2");
ChildNodeJoinCondition jc = f.childNodeJoinCondition("childSelectorName", "parentSelectorName");
Join j = f.join(left, right, QueryObjectModelConstants.JCR_JOIN_TYPE_INNER, jc);
assertEquals(left, j.getLeft());
assertEquals(right, j.getRight());
assertEquals(QueryObjectModelConstants.JCR_JOIN_TYPE_INNER, j.getJoinType());
assertEquals(jc, j.getJoinCondition());
assertEquals("ISCHILDNODE([childSelectorName], [parentSelectorName])", jc.toString());
}
use of javax.jcr.query.qom.Join in project jackrabbit by apache.
the class QueryEngine method execute.
protected QueryResult execute(Column[] columns, Join join, Constraint constraint, Ordering[] orderings, long offset, long limit, int printIndentation) throws RepositoryException {
// Swap the join sources to normalize all outer joins to left
if (JCR_JOIN_TYPE_RIGHT_OUTER.equalsIgnoreCase(join.getJoinType())) {
log.debug("{} SQL2 RIGHT OUTER JOIN transformed to LEFT OUTER JOIN.", genString(printIndentation));
Join betterJoin = qomFactory.join(join.getRight(), join.getLeft(), JCR_JOIN_TYPE_LEFT_OUTER, join.getJoinCondition());
return execute(columns, betterJoin, constraint, orderings, offset, limit, printIndentation);
}
JoinMerger merger = JoinMerger.getJoinMerger(join, getColumnMap(columns, getSelectorNames(join)), evaluator, qomFactory);
ConstraintSplitter splitter = new ConstraintSplitter(constraint, qomFactory, merger.getLeftSelectors(), merger.getRightSelectors(), join);
ConstraintSplitInfo csInfo = splitter.getConstraintSplitInfo();
logQueryAnalysis(csInfo, printIndentation);
boolean isOuterJoin = JCR_JOIN_TYPE_LEFT_OUTER.equalsIgnoreCase(join.getJoinType());
QueryResult result = execute(merger, csInfo, isOuterJoin, printIndentation);
long sort = System.currentTimeMillis();
QueryResult sortedResult = sort(result, orderings, evaluator, offset, limit);
log.debug(" {} SQL2 SORT took {} ms.", genString(printIndentation), System.currentTimeMillis() - sort);
return sortedResult;
}
use of javax.jcr.query.qom.Join in project jackrabbit by apache.
the class QueryObjectModelFactoryTest method testJoin.
/**
* Test case for {@link QueryObjectModelFactory#join(Source, Source, String, JoinCondition)}
*/
public void testJoin() throws RepositoryException {
Selector s1 = qf.selector(ntBase, SELECTOR_NAME1);
Selector s2 = qf.selector(testNodeType, SELECTOR_NAME1);
JoinCondition cond = qf.equiJoinCondition(ntBase, jcrPrimaryType, testNodeType, jcrPrimaryType);
for (Iterator<String> it = JOIN_TYPES.iterator(); it.hasNext(); ) {
String joinType = it.next();
Join join = qf.join(s1, s2, joinType, cond);
assertTrue("Not a selector source", join.getLeft() instanceof Selector);
assertTrue("Not a selector source", join.getRight() instanceof Selector);
assertEquals("Wrong join type", joinType, join.getJoinType());
assertTrue("Not an EquiJoinCondition", join.getJoinCondition() instanceof EquiJoinCondition);
}
}
Aggregations