Package javax.jcr.query

Examples of javax.jcr.query.RowIterator


            String language) throws SlingException {
        try {
            QueryResult result = JcrResourceUtil.query(getSession(), query,
                language);
            final String[] colNames = result.getColumnNames();
            final RowIterator rows = result.getRows();
            return new Iterator<Map<String, Object>>() {
                public boolean hasNext() {
                    return rows.hasNext();
                };

                public Map<String, Object> next() {
                    Map<String, Object> row = new HashMap<String, Object>();
                    try {
                        Value[] values = rows.nextRow().getValues();
                        for (int i = 0; i < values.length; i++) {
                            Value v = values[i];
                            if (v != null) {
                                row.put(colNames[i],
                                    JcrResourceUtil.toJavaObject(values[i]));
View Full Code Here


     * @throws RepositoryException if an error occurs while iterating over the
     *                             result nodes.
     */
    protected void checkResult(QueryResult result, int hits)
            throws RepositoryException {
        RowIterator itr = result.getRows();
        long count = itr.getSize();
        if (count == 0) {
            log.println(" NONE");
        } else if (count == -1) {
            // have to count in a loop
            count = 0;
            while (itr.hasNext()) {
                itr.nextRow();
                count++;
            }
        }
        assertEquals("Wrong hit count.", hits, count);
    }
View Full Code Here

            QueryManager qm = session.getWorkspace().getQueryManager();
            Query q = qm.createQuery("select text from [nt:base] where id = $id", Query.JCR_SQL2);
            q.bindValue("id", vf.createValue("1"));
            QueryResult r = q.execute();
            RowIterator it = r.getRows();
            assertTrue(it.hasNext());
            Row row = it.nextRow();
            assertEquals("hello world", row.getValue("text").getString());
            assertFalse(it.hasNext());

            r = q.execute();
            NodeIterator nodeIt = r.getNodes();
            assertTrue(nodeIt.hasNext());
            Node n = nodeIt.nextNode();
            assertEquals("hello world", n.getProperty("text").getString());
            assertFalse(it.hasNext());

        } finally {
            session.logout();
        }
    }
View Full Code Here

     * For configuration description see {@link #setUpFullTextTest()}.
     */
    public void testScoreColumn() throws Exception {
        setUpFullTextTest();
        QueryResult result = execute(getFullTextStatement());
        RowIterator rows = result.getRows();
        // test mere existence
        rows.nextRow().getValue(jcrScore);
    }
View Full Code Here

     * For configuration description see {@link #setUpFullTextTest()}.
     */
    public void testPathColumn() throws Exception {
        setUpFullTextTest();
        QueryResult result = execute(getFullTextStatement());
        RowIterator rows = result.getRows();
        if (getSize(rows) < 1) {
            fail("Query result did not return any nodes");
        }
        // re-aquire rows
        rows = result.getRows();

        // test mere existence
        rows.nextRow().getValue(jcrPath);
    }
View Full Code Here

    public void testPath() throws RepositoryException {
        Node n1 = testRootNode.addNode("node1");
        Node n2 = testRootNode.addNode("node2");
        Node n3 = testRootNode.addNode("node3");
        superuser.save();
        RowIterator rows = GQL.execute(createStatement(""), superuser);
        checkResult(rows, new Node[]{n1, n2, n3});
    }
View Full Code Here

        Node n3 = testRootNode.addNode("node3");
        n3.setProperty("p", 3);
        superuser.save();
        // default: ascending
        String stmt = createStatement("order:p");
        RowIterator rows = GQL.execute(stmt, superuser);
        checkResultSequence(rows, new Node[]{n1, n2, n3});
        // explicit ascending
        stmt = createStatement("order:+p");
        rows = GQL.execute(stmt, superuser);
        checkResultSequence(rows, new Node[]{n1, n2, n3});
View Full Code Here

        Node n3 = testRootNode.addNode("node3");
        n3.setProperty("p", 3);
        superuser.save();
        // only 2 results
        String stmt = createStatement("order:p limit:2");
        RowIterator rows = GQL.execute(stmt, superuser);
        checkResultSequence(rows, new Node[]{n1, n2});
        // range with open start
        stmt = createStatement("order:p limit:..2");
        rows = GQL.execute(stmt, superuser);
        checkResultSequence(rows, new Node[]{n1, n2});
View Full Code Here

        n2.setProperty("text", "bar");
        Node n3 = testRootNode.addNode("node3");
        n3.setProperty("text", "foo bar");
        superuser.save();
        String stmt = createStatement("foo -bar");
        RowIterator rows = GQL.execute(stmt, superuser);
        checkResult(rows, new Node[]{n1});
    }
View Full Code Here

        n2.setProperty("text", "apache jcr");
        Node n3 = testRootNode.addNode("node3");
        n3.setProperty("text", "jackrabbit jcr");
        superuser.save();
        String stmt = createStatement("apache jackrabbit OR jcr");
        RowIterator rows = GQL.execute(stmt, superuser);
        checkResult(rows, new Node[]{n1, n2});
    }
View Full Code Here

TOP

Related Classes of javax.jcr.query.RowIterator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.