Examples of QueryManager


Examples of javax.jcr.query.QueryManager

   
    @Test
    public void noLiterals() throws RepositoryException {
        Session session = getAdminSession();
        ValueFactory vf = session.getValueFactory();
        QueryManager qm = session.getWorkspace().getQueryManager();
       
        // insecure
        try {
            Query q = qm.createQuery(
                    "select text from [nt:base] where password = 'x'",
                    Query.JCR_SQL2 + "-noLiterals");
            q.execute();
            fail();
        } catch (InvalidQueryException e) {
            assertTrue(e.toString(), e.toString().indexOf(
                    "literals of this type not allowed") > 0);
        }

        // secure
        Query q = qm.createQuery(
                "select text from [nt:base] where password = $p",
                Query.JCR_SQL2 + "-noLiterals");
        q.bindValue("p", vf.createValue("x"));
        q.execute();
    }
View Full Code Here

Examples of javax.jcr.query.QueryManager

    public void fnNameEncoding() throws Exception {
        Session session = getAdminSession();
        session.getRootNode().addNode("123456_test_name");
        session.save();

        QueryManager qm = session.getWorkspace().getQueryManager();
        Query q;

        q = qm.createQuery("//*[jcr:like(fn:name(), '%123456%')]", Query.XPATH);
        assertEquals("/123456_test_name", getPaths(q));

        q = qm.createQuery("//*[fn:name() = '123456_test_name']", Query.XPATH);
        assertEquals("", getPaths(q));
    }
View Full Code Here

Examples of javax.jcr.query.QueryManager

        Node hello = session.getRootNode().addNode("hello");
        hello.setProperty("id", "1");
        hello.setProperty("properties", new String[] { "p1", "p2" });
        session.save();

        QueryManager qm = session.getWorkspace().getQueryManager();
        Query q = qm.createQuery("select properties from [nt:base] where id = 1",
                Query.JCR_SQL2);

        QueryResult r = q.execute();
        RowIterator it = r.getRows();
        assertTrue(it.hasNext());
View Full Code Here

Examples of javax.jcr.query.QueryManager

            Node rootNode = writer.getRootNode();
            Node node = rootNode.addNode("test", "nt:unstructured");
            node.addNode(".tokens");
            writer.save();

            QueryManager qm = reader.getWorkspace().getQueryManager();
            Query q = qm.createQuery("/jcr:root//*[_x002e_tokens/@jcr:primaryType]", Query.XPATH);
            NodeIterator res = q.execute().getNodes();
            assertEquals(1, res.getSize());
        } finally {
            if (reader != null) {
                reader.logout();
View Full Code Here

Examples of javax.jcr.query.QueryManager

            Node rootNode = writer.getRootNode();
            Node node = rootNode.addNode("test", "nt:unstructured");
            node.setProperty("text", "find me");
            writer.save();

            QueryManager qm = reader.getWorkspace().getQueryManager();
            Query q = qm.createQuery("select * from 'nt:base' where contains(*, 'find me')", Query.JCR_SQL2);
            NodeIterator res = q.execute().getNodes();
            assertEquals("False amount of hits", 1, res.getSize());
        } finally {
            if (reader != null) {
                reader.logout();
View Full Code Here

Examples of javax.jcr.query.QueryManager

   
    @Test
    @Ignore("OAK-1155")
    public void nodeType() throws Exception {
        Session session = getAdminSession();
        QueryManager qm = session.getWorkspace().getQueryManager();
        Node testRootNode = session.getRootNode().addNode("testroot");
        Node n1 = testRootNode.addNode("node1");
        Node n2 = n1.addNode("node2");
        n2.addNode("node3");
        session.save();
      
        String sql2 = "select [jcr:path] as [path] from [nt:base] " +
                "where [node2/node3/jcr:primaryType] is not null";
       
        Query q;
        QueryResult result;
        RowIterator it;
       
        q = qm.createQuery("explain " + sql2, Query.JCR_SQL2);
        result = q.execute();
        it = result.getRows();
        assertTrue(it.hasNext());
        String plan = it.nextRow().getValue("plan").getString();
        // should not use the index on "jcr:primaryType"
        assertEquals("[nt:base] as [nt:base] /* traverse \"*\" " +
                "where [nt:base].[node2/node3/jcr:primaryType] is not null */",
                plan);
       
        // verify the result
        q = qm.createQuery(sql2, Query.JCR_SQL2);
        result = q.execute();
        it = result.getRows();
        assertTrue(it.hasNext());
        String path = it.nextRow().getValue("path").getString();
        assertEquals("/testroot/node1", path);
View Full Code Here

Examples of javax.jcr.query.QueryManager

    }
   
    @Test
    public void excerpt() throws Exception {
        Session session = getAdminSession();
        QueryManager qm = session.getWorkspace().getQueryManager();
        Node testRootNode = session.getRootNode().addNode("testroot");
        Node n1 = testRootNode.addNode("node1");
        n1.setProperty("text", "hello world");
        n1.setProperty("desc", "description");
        Node n2 = testRootNode.addNode("node2");
        n2.setProperty("text", "Hello World");
        n2.setProperty("desc", "Description");
        session.save();

        Query q;
        RowIterator it;
        Row row;
        String s;
       
        String xpath = "//*[jcr:contains(., 'hello')]/rep:excerpt(.) order by jcr:path descending";
       
        q = qm.createQuery(xpath, "xpath");
        it = q.execute().getRows();
        row = it.nextRow();
        s = row.getValue("rep:excerpt(.)").getString();
        assertTrue(s, s.indexOf("<strong>hello</strong> world") >= 0);
        assertTrue(s, s.indexOf("description") >= 0);
        row = it.nextRow();
        s = row.getValue("rep:excerpt(.)").getString();
        // TODO is this expected?
        assertTrue(s, s.indexOf("Hello World") >= 0);
        assertTrue(s, s.indexOf("Description") >= 0);
       
        xpath = "//*[jcr:contains(., 'hello')]/rep:excerpt(.) order by jcr:path descending";

        q = qm.createQuery(xpath, "xpath");
        it = q.execute().getRows();
        row = it.nextRow();
        s = row.getValue("rep:excerpt(text)").getString();
        assertTrue(s, s.indexOf("<strong>hello</strong> world") >= 0);
        assertTrue(s, s.indexOf("description") < 0);
View Full Code Here

Examples of javax.jcr.query.QueryManager

    }
   
    @Test
    public void fulltextOrWithinText() throws Exception {
        Session session = getAdminSession();
        QueryManager qm = session.getWorkspace().getQueryManager();
        Node testRootNode = session.getRootNode().addNode("testroot");
        Node n1 = testRootNode.addNode("node1");
        n1.setProperty("text", "hello");
        Node n2 = testRootNode.addNode("node2");
        n2.setProperty("text", "hallo");
        Node n3 = testRootNode.addNode("node3");
        n3.setProperty("text", "hello hallo");
        session.save();
      
        String sql2 = "select [jcr:path] as [path] from [nt:base] " +
                "where contains([text], 'hello OR hallo') order by [jcr:path]";
       
        Query q;
       
        q = qm.createQuery("explain " + sql2, Query.JCR_SQL2);

        assertEquals("[nt:base] as [nt:base] /* traverse \"*\" " +
                "where contains([nt:base].[text], cast('hello OR hallo' as string)) */",
                getResult(q.execute(), "plan"));
       
        // verify the result
        // uppercase "OR" mean logical "or"
        q = qm.createQuery(sql2, Query.JCR_SQL2);
        assertEquals("/testroot/node1, /testroot/node2, /testroot/node3",
                getResult(q.execute(), "path"));

        // lowercase "or" mean search for the term "or"
        sql2 = "select [jcr:path] as [path] from [nt:base] " +
                "where contains([text], 'hello or hallo') order by [jcr:path]";
        q = qm.createQuery(sql2, Query.JCR_SQL2);
        assertEquals("",
                getResult(q.execute(), "path"));

    }
View Full Code Here

Examples of javax.jcr.query.QueryManager

        tmpl.addEntry(EveryonePrincipal.getInstance(), new Privilege[]{acMgr.privilegeFromName(Privilege.JCR_READ)}, true, restrictions);
        acMgr.setPolicy(tmpl.getPath(), tmpl);
        adminSession.save();

        Session anonymousSession = getRepository().login(new GuestCredentials());
        QueryManager qm = anonymousSession.getWorkspace().getQueryManager();
        Query q = qm.createQuery("/jcr:root/home//social/relationships/following//*[id='aaron.mcdonald@mailinator.com']", Query.XPATH);
        QueryResult r = q.execute();
        RowIterator it = r.getRows();
        Assert.assertTrue(it.hasNext());
    }
View Full Code Here

Examples of javax.jcr.query.QueryManager

     * @see SearchResource#getQueryGrammerSet()
     */
    public QueryGrammerSet getQueryGrammerSet()  {
        QueryGrammerSet qgs = new QueryGrammerSet();
        try {
            QueryManager qMgr = getRepositorySession().getWorkspace().getQueryManager();
            String[] langs = qMgr.getSupportedQueryLanguages();
            for (int i = 0; i < langs.length; i++) {
                // todo: define proper namespace
                qgs.addQueryLanguage(langs[i], Namespace.EMPTY_NAMESPACE);
            }
        } catch (RepositoryException e) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.