Package javax.jcr.query

Examples of javax.jcr.query.Query


    public String[] checkQueryStatement(SessionInfo sessionInfo,
                                    String statement,
                                    String language,
                                    Map<String, String> namespaces)
            throws InvalidQueryException, RepositoryException {
        Query q = createQuery(getSessionInfoImpl(sessionInfo).getSession(),
                statement, language, namespaces);
        return q.getBindVariableNames();
    }
View Full Code Here


    /**
     * {@inheritDoc}
     */
    public QueryInfo executeQuery(SessionInfo sessionInfo, String statement, String language, Map<String, String> namespaces, long limit, long offset, Map<String, QValue> values) throws RepositoryException {
        SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
        Query query = createQuery(sInfo.getSession(), statement,
                language, namespaces);
        if (limit != -1) {
            query.setLimit(limit);
        }
        if (offset != -1) {
            query.setOffset(offset);
        }
        if (values != null && !values.isEmpty()) {
            for (Map.Entry<String, QValue> entry : values.entrySet()) {
                Value value = ValueFormat.getJCRValue(entry.getValue(), sInfo.getNamePathResolver(), sInfo.getSession().getValueFactory());
                query.bindValue(entry.getKey(), value);
            }
        }
        return new QueryInfoImpl(query.execute(), idFactory,
                sInfo.getNamePathResolver(), getQValueFactory());
    }
View Full Code Here

       
        for(String root : allowedRoots) {
            final String statement = "/jcr:root" + root + "/element(*, " + SLING_TEST_NODETYPE + ")";
            log.debug("Querying for test nodes: {}", statement);
            session.refresh(true);
            final Query q = session.getWorkspace().getQueryManager().createQuery(statement, Query.XPATH);
            final NodeIterator it = q.execute().getNodes();
            while(it.hasNext()) {
                final String path = it.nextNode().getPath();
                newList.add(path);
                log.debug("Test resource found: {}", path);
            }
View Full Code Here

            }
            s.save();

            final String stmt = "SELECT * FROM nt:base WHERE " + propName + " IS NOT NULL";

            @SuppressWarnings("deprecation")
            final Query q = s.getWorkspace().getQueryManager().createQuery(stmt, Query.SQL);

            final NodeIterator it = q.execute().getNodes();
            int count = 0;
            while(it.hasNext()) {
                it.next();
                count++;
            }
View Full Code Here

            final Node n = deleteAfterTests(s.getRootNode().addNode(path));
            n.addMixin("mix:title");
            s.save();

            final String statement = "/jcr:root//element(*, mix:title)";
            @SuppressWarnings("deprecation")
            final Query q = s.getWorkspace().getQueryManager().createQuery(statement, Query.XPATH);
            final NodeIterator it = q.execute().getNodes();
            assertTrue("Expecting a non-empty result", it.hasNext());
            boolean found = false;
            while(it.hasNext()) {
                if(it.nextNode().getPath().equals(absPath)) {
                    found = true;
View Full Code Here

    /** Helper method to execute a JCR query */
    public static QueryResult query(Session session, String query,
            String language) throws RepositoryException {
        QueryManager qManager = session.getWorkspace().getQueryManager();
        Query q = qManager.createQuery(query, language);
        return q.execute();
    }
View Full Code Here

    private Iterator<JobStatus> getEngineJobs() {
        return executionEngine.getMatchingJobStatus(null);
    }
   
    private Iterator<JobStatus> getStoredJobs(Session s) throws RepositoryException {
        final Query q = s.getWorkspace().getQueryManager().createQuery(JOB_QUERY, Query.SQL);
        final NodeIterator it = q.execute().getNodes();
        return new Iterator<JobStatus>() {

            public boolean hasNext() {
                return it.hasNext();
            }
View Full Code Here

        resolver = new ResourceResolver() {

            public Iterator<Resource> findResources(String query,
                    String language) {
                try {
                    final Query q = getSession().getWorkspace().getQueryManager().createQuery(query, language);
                    final QueryResult result = q.execute();
                    final NodeIterator nodes = result.getNodes();
                    return new Iterator<Resource>() {
                        public boolean hasNext() {
                            return nodes.hasNext();
                        }

                        public Resource next() {
                            Node node = nodes.nextNode();
                            try {
                                return new JcrNodeResource(resolver, node, null ,null);
                            } catch (RepositoryException e) {
                                throw new IllegalStateException(e);
                            }
                        }

                        public void remove() {
                            throw new UnsupportedOperationException("remove");
                        }
                    };
                } catch (NamingException ne) {
                    return null;
                } catch (RepositoryException re) {
                    return null;
                }
            }

            public Resource getResource(Resource base, String path) {
                // TODO Auto-generated method stub
                return null;
            }

            public Resource getResource(String path) {
                // TODO Auto-generated method stub
                return null;
            }

            public String[] getSearchPath() {
                return new String[] {"/apps/", "/libs/"};
            }

            public Iterator<Resource> listChildren(Resource parent) {
                // TODO Auto-generated method stub
                return null;
            }

            public String map(HttpServletRequest request, String resourcePath) {
                // TODO Auto-generated method stub
                return null;
            }

            public String map(String resourcePath) {
                // TODO Auto-generated method stub
                return null;
            }

            public Iterator<Map<String, Object>> queryResources(String query,
                    String language) {
                try {
                    final Query q = getSession().getWorkspace().getQueryManager().createQuery(query, language);
                    final QueryResult result = q.execute();
                    final String[] colNames = result.getColumnNames();
                    final RowIterator rows = result.getRows();
                    return new Iterator<Map<String, Object>>() {
                        public boolean hasNext() {
                            return rows.hasNext();
View Full Code Here

        MockControl qmCtrl = MockControl.createControl(QueryManager.class);
        QueryManager qm = (QueryManager) qmCtrl.getMock();
       
        MockControl queryCtrl = MockControl.createControl(Query.class);
        Query query = (Query) queryCtrl.getMock();

        MockControl resultCtrl = MockControl.createControl(QueryResult.class);
        QueryResult result = (QueryResult) resultCtrl.getMock();

        sessionControl.expectAndReturn(session.getWorkspace(), ws);
        wsCtrl.expectAndReturn(ws.getQueryManager(), qm);
        qmCtrl.expectAndReturn(qm.getQuery(nd), query);
        queryCtrl.expectAndReturn(query.execute(), result);
       
        sfControl.replay();
        sessionControl.replay();
        wsCtrl.replay();
        qmCtrl.replay();
View Full Code Here

        MockControl qmCtrl = MockControl.createControl(QueryManager.class);
        QueryManager qm = (QueryManager) qmCtrl.getMock();
       
        MockControl queryCtrl = MockControl.createControl(Query.class);
        Query query = (Query) queryCtrl.getMock();

        MockControl resultCtrl = MockControl.createControl(QueryResult.class);
        QueryResult result = (QueryResult) resultCtrl.getMock();

        String stmt = "//*/@bogus:title";
        String language = Query.XPATH;

        sessionControl.expectAndReturn(session.getWorkspace(), ws);
        wsCtrl.expectAndReturn(ws.getQueryManager(), qm);
        qmCtrl.expectAndReturn(qm.createQuery(stmt, language), query);
        queryCtrl.expectAndReturn(query.execute(), result);
       
        sfControl.replay();
        sessionControl.replay();
        wsCtrl.replay();
        qmCtrl.replay();
View Full Code Here

TOP

Related Classes of javax.jcr.query.Query

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.