public void testChildNodes() throws RepositoryException { Node n1 = testRootNode.addNode(nodeName1, testNodeType); Node n2 = testRootNode.addNode(nodeName2, testNodeType); Node n3 = testRootNode.addNode(nodeName3, testNodeType); superuser.save(); QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"), qf.childNode("s", testRoot), null, null); checkQOM(qom, new Node[]{n1, n2, n3}); }
@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(childSelector)) { constraints.add(factory.childNode(childSelector, path)); } else { constraints.add(factory.sameNode(parentSelector, path)); } } return constraints; }
@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(childSelector)) { constraints.add(factory.childNode(childSelector, path)); } else { constraints.add(factory.sameNode(parentSelector, path)); } } return constraints; }
public void testChildNode() throws RepositoryException { Node n = testRootNode.addNode(nodeName1, testNodeType); superuser.save(); QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"), qf.childNode("s", testRoot), null, null); checkQOM(qom, new Node[]{n}); }
/** * Test case for {@link QueryObjectModelFactory#childNode(String, String)} */ public void testChildNode() throws RepositoryException { ChildNode childNode = qf.childNode(SELECTOR_NAME1, testRootNode.getPath()); assertEquals("Wrong path", testRootNode.getPath(), childNode.getParentPath()); assertEquals("Wrong selector name", SELECTOR_NAME1, childNode.getSelectorName()); }
/** * Test case for {@link QueryObjectModelFactory#childNode(String, String)} */ public void testChildNodeWithSelector() throws RepositoryException { ChildNode childNode = qf.childNode(SELECTOR_NAME1, testRootNode.getPath()); assertEquals("Wrong path", testRootNode.getPath(), childNode.getParentPath()); assertEquals("Wrong selector name", SELECTOR_NAME1, childNode.getSelectorName()); }
public void testPathDoesNotExist() throws RepositoryException { QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"), qf.childNode("s", testRoot + "/" + nodeName1), null, null); checkQOM(qom, new Node[]{}); }
public void testPropertyExistence() throws RepositoryException { Node n1 = testRootNode.addNode(nodeName1, testNodeType); n1.setProperty(propertyName1, "abc"); Node n2 = testRootNode.addNode(nodeName2, testNodeType); n2.setProperty(propertyName2, "abc"); superuser.save(); QueryObjectModel qom = qf.createQuery( qf.selector(testNodeType, "s"), qf.and( qf.childNode("s", testRoot), qf.propertyExistence("s", propertyName1) ), null, null); checkQOM(qom, new Node[]{n1}); qom = qf.createQuery( qf.selector(testNodeType, "s"), qf.and( qf.childNode("s", testRoot), qf.propertyExistence("s", propertyName2) ), null, null); checkQOM(qom, new Node[]{n2}); } }
@Test public void childNode() throws RepositoryException { ChildNode cn = f.childNode("selectorName", "parentPath"); assertEquals("selectorName", cn.getSelectorName()); assertEquals("parentPath", cn.getParentPath()); assertEquals("ISCHILDNODE([selectorName], [parentPath])", cn.toString()); assertEquals("ISCHILDNODE([p])", f.childNode(null, "p").toString()); }
private QueryObjectModel createQuery(String operator, Value literal) throws RepositoryException { return qf.createQuery( qf.selector(testNodeType, "s"), qf.and( qf.childNode("s", testRoot), qf.comparison( qf.nodeLocalName("s"), operator, qf.literal(literal) ) ), null, null); } }
private QueryObjectModel createQuery(String operator, Value literal) throws RepositoryException { return qf.createQuery( qf.selector(testNodeType, "s"), qf.and( qf.childNode("s", testRoot), qf.comparison( qf.nodeName("s"), operator, qf.literal(literal) ) ), null, null); } }
public void testChildNodesDoNotMatchSelector() 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.childNode("s", testRoot), null, null); checkQOM(qom, new Node[]{}); return; } } throw new NotExecutableException("No suitable node type found to " + "perform test against '" + testNodeType + "' nodes"); }
public void testNotASelectorName() throws RepositoryException { try { Query q = qf.createQuery(qf.selector(testNodeType, "s"), qf.childNode("x", testRoot), null, null); q.execute(); fail("ChildNode with an unknown selector name must throw InvalidQueryException"); } catch (InvalidQueryException e) { // expected } try { String stmt = "SELECT * FROM [" + testNodeType + "] AS s WHERE " + "ISCHILDNODE(x, [" + testRoot + "])"; qm.createQuery(stmt, Query.JCR_SQL2).execute(); fail("ISCHILDNODE() 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.childNode("s", testPath), null, null); q.execute(); fail("ChildNode with relative path argument must throw InvalidQueryException"); } catch (InvalidQueryException e) { // expected } try { String stmt = "SELECT * FROM [" + testNodeType + "] AS s WHERE " + "ISCHILDNODE(s, [" + testPath + "])"; qm.createQuery(stmt, Query.JCR_SQL2).execute(); fail("ISCHILDNODE() with relative path argument must throw InvalidQueryException"); } catch (InvalidQueryException e) { // expected } }
private QueryObjectModel createQuery(DynamicOperand operand, boolean toUpper, String operator, Value literal) throws RepositoryException { if (toUpper) { operand = qf.upperCase(operand); } else { operand = qf.lowerCase(operand); } return qf.createQuery( qf.selector(testNodeType, "s"), qf.and( qf.childNode("s", testRoot), qf.comparison( operand, operator, qf.literal(literal) ) ), null, null); } }
public void testSyntacticallyInvalidPath() throws RepositoryException { String invalidPath = testRoot + "/" + nodeName1 + "["; try { Query q = qf.createQuery(qf.selector(testNodeType, "s"), qf.childNode("s", invalidPath), null, null); q.execute(); fail("ChildNode with syntactically invalid path argument must throw InvalidQueryException"); } catch (InvalidQueryException e) { // expected } try { String stmt = "SELECT * FROM [" + testNodeType + "] AS s WHERE " + "ISCHILDNODE(s, [" + invalidPath + "])"; qm.createQuery(stmt, Query.JCR_SQL2).execute(); fail("ISCHILDNODE() with syntactically invalid path argument must throw InvalidQueryException"); } catch (InvalidQueryException e) { // expected } }
protected void setUp() throws Exception { super.setUp(); qomQuery = qf.createQuery( qf.selector(testNodeType, "s"), qf.and( qf.childNode("s", testRoot), qf.comparison( qf.propertyValue("s", propertyName1), QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, qf.bindVariable("v") ) ), null, null); sqlQuery = qm.createQuery(qomQuery.getStatement(), Query.JCR_SQL2); }
/** * will build a query directly via the api using a spaced path * * @throws Exception */ public void testGetChildrenApiDirect() throws Exception { QueryObjectModelFactory qomf = qm.getQOMFactory(); Source source1 = qomf.selector(NodeType.NT_BASE, "selector"); Column[] columns = new Column[] { qomf.column("selector", null, null) }; Constraint constraint2 = qomf.childNode("selector", n1.getPath()); QueryObjectModel qom = qomf.createQuery(source1, constraint2, null, columns); checkResult(qom.execute(), 2); }
/** * the statement behind the api should be consistent, and return a similar * query. in our case it should escape the paths that have spaces in them by * enclosing them in single quotes * * @throws Exception */ public void testGetChildrenApiStatement() throws Exception { QueryObjectModelFactory qomf = qm.getQOMFactory(); Source source1 = qomf.selector(NodeType.NT_BASE, "selector"); Column[] columns = new Column[] { qomf.column("selector", null, null) }; Constraint constraint2 = qomf.childNode("selector", n1.getPath()); QueryObjectModel qom = qomf.createQuery(source1, constraint2, null, columns); checkResult(executeSQL2Query(qom.getStatement()), 2); }
private QueryResult[] executeQueries(String propertyName, String operator, Value length) throws RepositoryException { QueryObjectModel qom = qf.createQuery( qf.selector(testNodeType, "s"), qf.and( qf.childNode("s", testRoot), qf.comparison( qf.length( qf.propertyValue( "s", propertyName)), operator, qf.literal(length)) ), null, null); QueryResult[] results = new QueryResult[2]; results[0] = qom.execute(); results[1] = qm.createQuery(qom.getStatement(), Query.JCR_SQL2).execute(); return results; } }