Package javax.jcr.query

Examples of javax.jcr.query.QueryManager


        }
        stmt.append("]");
       
        QueryResult result;
        try {
            QueryManager qm = session.getWorkspace().getQueryManager();
            Query q = qm.createQuery(stmt.toString(), Query.XPATH);
            result = q.execute();
        } catch (RepositoryException e) {
            log.error("Unexpected error while searching effective policies.", e.getMessage());           
            throw new UnsupportedOperationException("Retrieve effective policies for set of principals not supported.", e);
        }
View Full Code Here


                    .append(sortCol)
                    .append(' ')
                    .append(sortDir.getDirection());
        }

        QueryManager queryManager = session.getWorkspace().getQueryManager();
        Query query = queryManager.createQuery(xPath.toString(), Query.XPATH);
        long maxCount = builder.getMaxCount();
        if (maxCount == 0) {
            return Iterators.empty();
        }
View Full Code Here

        }
        stmt.append("]");
       
        QueryResult result;
        try {
            QueryManager qm = session.getWorkspace().getQueryManager();
            Query q = qm.createQuery(stmt.toString(), Query.XPATH);
            result = q.execute();
        } catch (RepositoryException e) {
            log.error("Unexpected error while searching effective policies.", e.getMessage());
            throw new UnsupportedOperationException("Retrieve effective policies at absPath '" +jcrPath+ "' not supported.", e);
        }
View Full Code Here

*/
public class QueryFulltextTest extends AbstractQueryTest {
   
    public void testFulltext() throws Exception {
        Session session = superuser;
        QueryManager qm = session.getWorkspace().getQueryManager();
        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);

// TODO the plan should actually be:
//            assertEquals("[nt:base] as [nt:base] /* " +
//                    "+((text:hallo text:hello)~1) +text:{* TO *} " +
//                    "ft:(text:\"hallo\" OR text:\"hello\") " +
//                    "where contains([nt:base].[text], cast('hello OR hallo' as string)) */",
//                    getResult(q.execute(), "plan"));
        assertEquals("[nt:base] as [nt:base] /* " +
                "aggregate +(:fulltext:hallo :fulltext:hello) +text:{* TO *} " +
                "ft:(text:\"hallo\" OR text:\"hello\") " +
                "where contains([nt:base].[text], cast('hello OR hallo' as string)) */",
                getResult(q.execute(), "plan"));
  
        // 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

    }
   
    public void testFulltextRelativeProperty() throws Exception {
        Session session = superuser;
        QueryManager qm = session.getWorkspace().getQueryManager();
        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();

        Query q;

        String sql2 = "select [jcr:path] as [path] from [nt:base] " +
                "where ISCHILDNODE([/testroot])" +
                " AND CONTAINS(text, 'hallo')";

        q = qm.createQuery("explain " + sql2, Query.JCR_SQL2);
        // TODO the plan should actually be:
//          assertEquals("[nt:base] as [nt:base] /* " +
//                  "+text:hallo +:path:/testroot/* +text:{* TO *} " +
//                  "ft:(text:\"hallo\") " +
//                  "where (ischildnode([nt:base], [/testroot])) " +
//                  "and (contains([nt:base].[text], cast('hallo' as string))) */",
//                  getResult(q.execute(), "plan"));
        assertEquals("[nt:base] as [nt:base] /* " +
                "aggregate +:fulltext:hallo* +:path:/testroot/* +text:{* TO *} " +
                "ft:(text:\"hallo\") " +
                "where (ischildnode([nt:base], [/testroot])) " +
                "and (contains([nt:base].[text], cast('hallo' as string))) */",
                getResult(q.execute(), "plan"));
       
        q = qm.createQuery(sql2, Query.JCR_SQL2);
        assertEquals("/testroot/node2, /testroot/node3", getResult(q.execute(), "path"));
      
        sql2 = "select [jcr:path] as [path] from [nt:base] " +
                "where contains([node1/text], 'hello') order by [jcr:path]";
       
//      q = qm.createQuery("explain " + sql2, Query.JCR_SQL2);
//    assertEquals("[nt:base] as [nt:base] /* " +
//            "+text:hallo +:path:/testroot/* +text:{* TO *} " +
//            "ft:(text:\"hallo\") " +
//            "where (ischildnode([nt:base], [/testroot])) " +
//            "and (contains([nt:base].[text], cast('hallo' as string))) */",
//            getResult(q.execute(), "plan"));

        q = qm.createQuery(sql2, Query.JCR_SQL2);
        assertEquals("/testroot", getResult(q.execute(), "path"));
       
        sql2 = "select [jcr:path] as [path] from [nt:base] " +
                "where contains([node2/text], 'hello OR hallo') order by [jcr:path]";
        q = qm.createQuery("explain " + sql2, Query.JCR_SQL2);
        // TODO the plan should actually be:
//            assertEquals("[nt:base] as [nt:base] /* " +
//                    "(text:hallo text:hello)~1 " +
//                    "ft:(node2/text:\"hallo\" OR node2/text:\"hello\") " +
//                    "parent:node2 " +
//                    "where contains([nt:base].[node2/text], cast('hello OR hallo' as string)) */",
//                    getResult(q.execute(), "plan"));
        assertEquals("[nt:base] as [nt:base] /* " +
                "aggregate :fulltext:hallo* :fulltext:hello* " +
                "ft:(node2/text:\"hallo\" OR node2/text:\"hello\") " +
                "parent:node2 " +
                "where contains([nt:base].[node2/text], cast('hello OR hallo' as string)) */",
      getResult(q.execute(), "plan"));
        q = qm.createQuery(sql2, Query.JCR_SQL2);
        assertEquals("/testroot",
                getResult(q.execute(), "path"));           
       
        sql2 = "select [jcr:path] as [path] from [nt:base] " +
                "where contains([node1/text], 'hello') " +
                "and contains([node2/text], 'hallo') " +
                "order by [jcr:path]";
        q = qm.createQuery("explain " + sql2, Query.JCR_SQL2);
        // TODO OAK-890
        assertEquals("[nt:base] as [nt:base] /* " +
                "aggregate Not yet implemented " +
                "where (contains([nt:base].[node1/text], cast('hello' as string))) " +
                "and (contains([nt:base].[node2/text], cast('hallo' as string))) */",
                getResult(q.execute(), "plan"));
        q = qm.createQuery(sql2, Query.JCR_SQL2);
        // assertEquals("/testroot",
        //        getResult(q.execute(), "path"));           
       
    }
View Full Code Here

     * @return the result.
     */
    private RowIterator execute() {
        try {
            String stmt = translateStatement();
            QueryManager qm = session.getWorkspace().getQueryManager();
            RowIterator nodes = qm.createQuery(stmt, Query.XPATH).execute().getRows();
            if (filter != null) {
                nodes = new FilteredRowIterator(nodes);
            }
            if (offset > 0) {
                try {
View Full Code Here

        }
        stmt.append("]");
       
        QueryResult result;
        try {
            QueryManager qm = session.getWorkspace().getQueryManager();
            Query q = qm.createQuery(stmt.toString(), Query.XPATH);
            result = q.execute();
        } catch (RepositoryException e) {
            log.error("Unexpected error while searching effective policies.", e.getMessage());           
            throw new UnsupportedOperationException("Retrieve effective policies for set of principals not supported.", e);
        }
View Full Code Here

     * @see SearchResource#getQueryGrammerSet()
     */
    public QueryGrammerSet getQueryGrammerSet()  {
        QueryGrammerSet qgs = new QueryGrammerSet();
        try {
            QueryManager qMgr = getRepositorySession().getWorkspace().getQueryManager();
            String[] langs = qMgr.getSupportedQueryLanguages();
            for (String lang : langs) {
                // todo: define proper namespace
                qgs.addQueryLanguage(lang, Namespace.EMPTY_NAMESPACE);
            }
        } catch (RepositoryException e) {
View Full Code Here

            throws InvalidQueryException, RepositoryException, DavException {

        Session session = getRepositorySession();
        NamespaceRegistry nsReg = session.getWorkspace().getNamespaceRegistry();
        Node rootNode = session.getRootNode();
        QueryManager qMgr = getRepositorySession().getWorkspace().getQueryManager();

        // test if query is defined by requested repository node
        String itemPath = locator.getRepositoryPath();
        if (itemPath != null && !rootNode.getPath().equals(itemPath)) {
            String qNodeRelPath = itemPath.substring(1);
            if (rootNode.hasNode(qNodeRelPath)) {
                Node qNode = rootNode.getNode(qNodeRelPath);
                if (qNode.isNodeType(JcrConstants.NT_QUERY)) {
                    return qMgr.getQuery(qNode);
                }
            }
        }

        Query q;
        if (sInfo != null) {
            // apply namespace mappings to session
            Map<String, String> namespaces = sInfo.getNamespaces();
            try {
                for (Map.Entry<String, String> entry : namespaces.entrySet()) {
                    String prefix = entry.getKey();
                    String uri = entry.getValue();
                    session.setNamespacePrefix(prefix, uri);
                }
                q = qMgr.createQuery(sInfo.getQuery(), sInfo.getLanguageName());

                if (SearchInfo.NRESULTS_UNDEFINED != sInfo.getNumberResults()) {
                    q.setLimit(sInfo.getNumberResults());
                }
                if (SearchInfo.OFFSET_UNDEFINED != sInfo.getOffset()) {
View Full Code Here

*/
public class QueryFulltextTest extends AbstractQueryTest {
   
    public void testFulltext() throws Exception {
        Session session = superuser;
        QueryManager qm = session.getWorkspace().getQueryManager();
        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);

// TODO the plan should actually be:
//            assertEquals("[nt:base] as [nt:base] /* " +
//                    "+((text:hallo text:hello)~1) +text:{* TO *} " +
//                    "ft:(text:\"hallo\" OR text:\"hello\") " +
//                    "where contains([nt:base].[text], cast('hello OR hallo' as string)) */",
//                    getResult(q.execute(), "plan"));
        assertEquals("[nt:base] as [nt:base] /* " +
                "aggregate :fulltext:hallo :fulltext:hello " +
                "ft:(text:\"hallo\" OR text:\"hello\") " +
                "where contains([nt:base].[text], cast('hello OR hallo' as string)) */",
                getResult(q.execute(), "plan"));
  
        // 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

TOP

Related Classes of javax.jcr.query.QueryManager

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.