Package javax.jcr.query

Examples of javax.jcr.query.QueryManager


    }
   
    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


    names.add("<none>");
    uniq.add("");
   
    try {
      Session session = ((JackConnection)parent.getConnection()).getSession();
      QueryManager qm = session.getWorkspace().getQueryManager();
      Query query = qm.createQuery("/jcr:root/apps//element(*,sling:Folder)", Query.XPATH);
      QueryResult res = query.execute();
      for (RowIterator iter = res.getRows(); iter.hasNext();) {
        Row row = iter.nextRow();
        Value path = row.getValue("jcr:path");
       
View Full Code Here

        }

        public void run() {
            try {
                // run the queries
                QueryManager qm = s.getWorkspace().getQueryManager();
                Query q = qm.createQuery(query, Query.XPATH);
                for (;;) {
                    long time = System.currentTimeMillis();
                    NodeIterator nodes = q.execute().getNodes();
                    long size = nodes.getSize();
                    if (size == -1) {
View Full Code Here

            }
            // save every 100 nodes
            testRootNode.save();
        }

        QueryManager qm = superuser.getWorkspace().getQueryManager();
        String stmt = testPath + "//*[jcr:contains(., '*foo')]";
        QueryResult res = qm.createQuery(stmt, Query.XPATH).execute();
        checkResult(res, 2000);

        stmt = testPath + "//*[jcr:contains(., 'bar*')]";
        res = qm.createQuery(stmt, Query.XPATH).execute();
        checkResult(res, 2000);
    }
View Full Code Here

            }
            // save every 100 nodes
            testRootNode.save();
        }

        QueryManager qm = superuser.getWorkspace().getQueryManager();
        String stmt = testPath + "//*[@foo >= 0]";
        QueryResult res = qm.createQuery(stmt, Query.XPATH).execute();
        checkResult(res, 2000);
    }
View Full Code Here

        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

    {
        // TODO: these may be best as running totals, maintained by observations on the properties in JCR

        try
        {
            QueryManager queryManager = session.getWorkspace().getQueryManager();

            // TODO: JCR-SQL2 query will not complete on a large repo in Jackrabbit 2.2.0 - see JCR-2835
            //    Using the JCR-SQL2 variants gives
            //      "org.apache.lucene.search.BooleanQuery$TooManyClauses: maxClauseCount is set to 1024"
//            String whereClause = "WHERE ISDESCENDANTNODE([/repositories/" + repositoryId + "/content])";
//            Query query = queryManager.createQuery( "SELECT size FROM [archiva:artifact] " + whereClause,
//                                                    Query.JCR_SQL2 );
            String whereClause = "WHERE jcr:path LIKE '/repositories/" + repositoryId + "/content/%'";
            Query query = queryManager.createQuery( "SELECT size FROM archiva:artifact " + whereClause, Query.SQL );

            QueryResult queryResult = query.execute();

            Map<String, Integer> totalByType = new HashMap<String, Integer>();
            long totalSize = 0, totalArtifacts = 0;
            for ( Row row : JcrUtils.getRows( queryResult ) )
            {
                Node n = row.getNode();
                totalSize += row.getValue( "size" ).getLong();

                String type;
                if ( n.hasNode( MavenArtifactFacet.FACET_ID ) )
                {
                    Node facetNode = n.getNode( MavenArtifactFacet.FACET_ID );
                    type = facetNode.getProperty( "type" ).getString();
                }
                else
                {
                    type = "Other";
                }
                Integer prev = totalByType.get( type );
                totalByType.put( type, prev != null ? prev + 1 : 1 );

                totalArtifacts++;
            }

            repositoryStatistics.setTotalArtifactCount( totalArtifacts );
            repositoryStatistics.setTotalArtifactFileSize( totalSize );
            for ( Map.Entry<String, Integer> entry : totalByType.entrySet() )
            {
                repositoryStatistics.setTotalCountForType( entry.getKey(), entry.getValue() );
            }

            // The query ordering is a trick to ensure that the size is correct, otherwise due to lazy init it will be -1
//            query = queryManager.createQuery( "SELECT * FROM [archiva:project] " + whereClause, Query.JCR_SQL2 );
            query = queryManager.createQuery( "SELECT * FROM archiva:project " + whereClause + " ORDER BY jcr:score",
                                              Query.SQL );
            repositoryStatistics.setTotalProjectCount( query.execute().getRows().getSize() );

//            query = queryManager.createQuery(
//                "SELECT * FROM [archiva:namespace] " + whereClause + " AND namespace IS NOT NULL", Query.JCR_SQL2 );
            query = queryManager.createQuery(
                "SELECT * FROM archiva:namespace " + whereClause + " AND namespace IS NOT NULL ORDER BY jcr:score",
                Query.SQL );
            repositoryStatistics.setTotalGroupCount( query.execute().getRows().getSize() );
        }
        catch ( RepositoryException e )
View Full Code Here

        }
        for (int i = 0; i < 100; i++) {
            session.getRootNode().addNode("node" + i, "nt:unstructured");
        }
        session.save();
        final QueryManager qm = session.getWorkspace().getQueryManager();
        final AtomicBoolean stop = new AtomicBoolean(false);
        final List<Exception> exceptions = Collections.synchronizedList(
                new ArrayList<Exception>());
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                while (!stop.get() && exceptions.isEmpty()) {
                    try {
                        // execute query
                        String stmt = "//*[@jcr:primaryType='nt:unstructured']";
                        qm.createQuery(stmt, Query.XPATH).execute();
                    } catch (RepositoryException e) {
                        if (Constants.SUN_OS) {
                            // on Solaris it's OK when the root cause
                            // of the exception is an InterruptedIOException
                            // the underlying file is not closed
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

        // Query for all candidate resources

        final ResourceResolver resourceResolver = resource.getResourceResolver();
        final Session session = resourceResolver.adaptTo(Session.class);
        final QueryManager queryManager = session.getWorkspace().getQueryManager();
        final QueryResult queryResult = queryManager.createQuery(properties.get(KEY_QUERY, ""),
                Query.JCR_SQL2).execute();
        final NodeIterator nodes = queryResult.getNodes();

        long size = nodes.getSize();
        if (size < 0) {
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.