@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; }
public void testDescendantNodes() throws RepositoryException { Node n1 = testRootNode.addNode(nodeName1, testNodeType); Node n2 = testRootNode.addNode(nodeName2, testNodeType); Node n21 = n2.addNode(nodeName1, testNodeType); superuser.save(); QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"), qf.descendantNode("s", testRoot), null, null); checkQOM(qom, new Node[]{n1, n2, n21}); }
@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; }
public void testDescendantNode() throws RepositoryException { Node n = testRootNode.addNode(nodeName1, testNodeType); superuser.save(); QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"), qf.descendantNode("s", testRoot), null, null); checkQOM(qom, new Node[]{n}); }
/** * Test case for {@link QueryObjectModelFactory#descendantNode(String, String)} */ public void testDescendantNodeWithSelector() throws RepositoryException { DescendantNode descNode = qf.descendantNode(SELECTOR_NAME1, testRootNode.getPath()); assertEquals("Wrong selector name", SELECTOR_NAME1, descNode.getSelectorName()); assertEquals("Wrong path", testRootNode.getPath(), descNode.getAncestorPath()); }
/** * Test case for {@link QueryObjectModelFactory#descendantNode(String, String)} */ public void testDescendantNode() throws RepositoryException { DescendantNode descNode = qf.descendantNode(SELECTOR_NAME1, testRootNode.getPath()); assertEquals("Wrong selector", SELECTOR_NAME1, descNode.getSelectorName()); assertEquals("Wrong path", testRootNode.getPath(), descNode.getAncestorPath()); }
public void testPathDoesNotExist() throws RepositoryException { QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"), qf.descendantNode("s", testRoot + "/" + nodeName1), null, null); checkQOM(qom, new Node[]{}); }
public void testNot() throws RepositoryException { Node n1 = testRootNode.addNode(nodeName1, testNodeType); n1.setProperty(propertyName1, "foo"); Node n2 = testRootNode.addNode(nodeName2, testNodeType); n2.setProperty(propertyName2, "bar"); superuser.save(); QueryObjectModel qom = qf.createQuery( qf.selector(testNodeType, "s"), qf.and( qf.descendantNode("s", testRootNode.getPath()), qf.not( qf.propertyExistence("s", propertyName1) ) ), null, null ); checkQOM(qom, new Node[]{n2}); } }
public void testSetOffset() throws RepositoryException { testRootNode.addNode(nodeName1, testNodeType); testRootNode.addNode(nodeName2, testNodeType); testRootNode.addNode(nodeName3, testNodeType); superuser.save(); for (int i = 0; i < 5; i++) { Query query = qf.createQuery( qf.selector(testNodeType, "s"), qf.descendantNode("s", testRoot), null, null ); query.setOffset(i); long expected = Math.max(3 - i, 0); assertEquals("Wrong numer of results", expected, getSize(query.execute().getNodes())); } } }
public void testSetLimit() throws RepositoryException { testRootNode.addNode(nodeName1, testNodeType); testRootNode.addNode(nodeName2, testNodeType); testRootNode.addNode(nodeName3, testNodeType); superuser.save(); for (int i = 0; i < 5; i++) { Query query = qf.createQuery( qf.selector(testNodeType, "s"), qf.descendantNode("s", testRoot), null, null ); query.setLimit(i); long expected = Math.min(i, 3); assertEquals("Wrong numer of results", expected, getSize(query.execute().getNodes())); } } }
public void testLeftOuterJoin() throws RepositoryException { QueryObjectModel qom = qf.createQuery( qf.join( qf.selector(testNodeType, LEFT), qf.selector(mixReferenceable, RIGHT), QueryObjectModelConstants.JCR_JOIN_TYPE_LEFT_OUTER, qf.sameNodeJoinCondition(LEFT, RIGHT, ".")), qf.descendantNode(LEFT, testRoot), null, null); checkQOM(qom, new Node[][]{{n1, null}, {n2, n2}}); }
public void testRightOuterJoin() throws RepositoryException { QueryObjectModel qom = qf.createQuery( qf.join( qf.selector(mixReferenceable, LEFT), qf.selector(testNodeType, RIGHT), QueryObjectModelConstants.JCR_JOIN_TYPE_RIGHT_OUTER, qf.sameNodeJoinCondition(LEFT, RIGHT, ".")), qf.descendantNode(RIGHT, testRoot), null, null); checkQOM(qom, new Node[][]{{null, n1}, {n2, n2}}); }
public void testRightOuterJoinWithPath() throws RepositoryException { QueryObjectModel qom = qf.createQuery( qf.join( qf.selector(mixReferenceable, LEFT), qf.selector(testNodeType, RIGHT), QueryObjectModelConstants.JCR_JOIN_TYPE_RIGHT_OUTER, qf.sameNodeJoinCondition(LEFT, RIGHT, nodeName2)), qf.descendantNode(RIGHT, testRoot), null, null); checkQOM(qom, new Node[][]{{n2, n1}, {null, n2}}); }
@Test public void descendantNode() throws RepositoryException { DescendantNode d = f.descendantNode("selectorName", "path"); assertEquals("selectorName", d.getSelectorName()); assertEquals("path", d.getAncestorPath()); assertEquals("ISDESCENDANTNODE([selectorName], [path])", d.toString()); assertEquals("ISDESCENDANTNODE([p])", f.descendantNode(null, "p").toString()); }
public void testDescendantNodesDoNotMatchSelector() throws RepositoryException, NotExecutableException { testRootNode.addNode(nodeName1, testNodeType); superuser.save(); NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager(); NodeTypeIterator it = ntMgr.getPrimaryNodeTypes(); NodeType testNt = ntMgr.getNodeType(testNodeType); while (it.hasNext()) { NodeType nt = it.nextNodeType(); if (!testNt.isNodeType(nt.getName())) { // perform test QueryObjectModel qom = qf.createQuery(qf.selector(nt.getName(), "s"), qf.descendantNode("s", testRoot), null, null); checkQOM(qom, new Node[]{}); return; } } throw new NotExecutableException("No suitable node type found to " + "perform test against '" + testNodeType + "' nodes"); }
/** * @return a basic QOM to test order by queries. * @throws RepositoryException if an error occurs. */ protected QueryObjectModel createQOM(boolean ascending) throws RepositoryException { DynamicOperand op = createOrderingOperand(); Ordering ordering; if (ascending) { ordering = qf.ascending(op); } else { ordering = qf.descending(op); } return qf.createQuery( qf.selector(testNodeType, "s"), qf.descendantNode("s", testRoot), new Ordering[]{ordering}, null ); }
public void testSyntacticallyInvalidPath() throws RepositoryException { String invalidPath = testRoot + "/" + nodeName1 + "["; try { Query q = qf.createQuery(qf.selector(testNodeType, "s"), qf.descendantNode("s", invalidPath), null, null); q.execute(); fail("DescendantNode with syntactically invalid path argument must throw InvalidQueryException"); } catch (InvalidQueryException e) { // expected } try { String stmt = "SELECT * FROM [" + testNodeType + "] AS s WHERE " + "ISDESCENDANTNODE(s, [" + invalidPath + "])"; qm.createQuery(stmt, Query.JCR_SQL2).execute(); fail("ISDESCENDANTNODE() with syntactically invalid path argument must throw InvalidQueryException"); } catch (InvalidQueryException e) { // expected } }
public void testNotASelectorName() throws RepositoryException { try { Query q = qf.createQuery(qf.selector(testNodeType, "s"), qf.descendantNode("x", testRoot), null, null); q.execute(); fail("DescendantNode with an unknown selector name must throw InvalidQueryException"); } catch (InvalidQueryException e) { // expected } try { String stmt = "SELECT * FROM [" + testNodeType + "] AS s WHERE " + "ISDESCENDANTNODE(x, [" + testRoot + "])"; qm.createQuery(stmt, Query.JCR_SQL2).execute(); fail("ISDESCENDANTNODE() with an unknown selector name must throw InvalidQueryException"); } catch (InvalidQueryException e) { // expected } }
public void testRelativePath() throws RepositoryException { try { Query q = qf.createQuery(qf.selector(testNodeType, "s"), qf.descendantNode("s", testPath), null, null); q.execute(); fail("DescendantNode with relative path argument must throw InvalidQueryException"); } catch (InvalidQueryException e) { // expected } try { String stmt = "SELECT * FROM [" + testNodeType + "] AS s WHERE " + "ISDESCENDANTNODE(s, [" + testPath + "])"; qm.createQuery(stmt, Query.JCR_SQL2).execute(); fail("ISDESCENDANTNODE() with relative path argument must throw InvalidQueryException"); } catch (InvalidQueryException e) { // expected } }
private Row getRow() throws RepositoryException { QueryObjectModel qom = qf.createQuery( qf.selector(testNodeType, SELECTOR_NAME), qf.descendantNode(SELECTOR_NAME, testRoot), null, new Column[]{qf.column(SELECTOR_NAME, propertyName1, propertyName1)}); RowIterator rows = qom.execute().getRows(); assertTrue("empty result", rows.hasNext()); Row r = rows.nextRow(); assertFalse("result must not contain more than one row", rows.hasNext()); return r; } }