ChecklistExporter { List<ForcedRoot> query(final Session session, final String statement) throws RepositoryException { final QueryManager qm = session.getWorkspace().getQueryManager(); final NamespaceMapping mapping = new NamespaceMapping(new SessionNamespaceResolver(session)); final String language = statement.toUpperCase().replaceFirst("^\\s*((MEASURE|EXPLAIN)\\s*)*", "") .startsWith("SELECT") ? Query.JCR_SQL2 : Query.XPATH; final Query query = qm.createQuery(statement, language); final QueryResult result = query.execute(); final Map<String, ForcedRoot> roots = new LinkedHashMap<>(); for (NodeIterator nodes = result.getNodes(); nodes.hasNext(); ) { nodeToRoot(nodes.nextNode(), mapping).ifPresent(root -> roots.put(root.getPath(), root)); } return new ArrayList<>(roots.values()); } private  ChecklistExporter(final List<Op> operations,
                              final List<String> exportTypeDefs,
                              final List<Rule> pathScopes,
                              final List<Rule> nodeTypeFilters,
                              final List<JcrNs> jcrNamespaces); void updateChecklist(final WriterOpener writerOpener,
                                final Session session,
                                final Checklist checklist,
                                final ForcedRootUpdatePolicy updatePolicy); List<ForcedRoot> findRoots(final Session session); static final ForcedRootUpdatePolicy DEFAULT_UPDATE_POLICY; static final String COVARIANT_PREFIX; }
@Test public void testQuery() throws Exception { TestUtil.withInMemoryRepo(session -> { TestUtil.installCndFromURL(session, getClass().getResource("/sling_nodetypes.cnd")); final int sample = 5; List<String> paths = IntStream.range(0, sample).mapToObj(val -> "/test/node" + val).collect(Collectors.toList()); assertEquals("should generate n paths: ", sample, paths.size()); paths.forEach(Fun.tryOrVoid1(path -> JcrUtils.getOrCreateByPath(path, "nt:folder", "sling:Folder", session, true))); final ChecklistExporter exporter = new ChecklistExporter.Builder().build(); List<ForcedRoot> byXPath = exporter.query(session, " for (String path : paths) { ForcedRoot root0 = byXPath.stream().filter(root -> path.equals(root.getPath())).findFirst().orElse(null); assertNotNull(String.format("root for path %s should not be null", path), root0); assertEquals(String.format("root primaryType for path %s should be sling:Folder", path), "sling:Folder", root0.getPrimaryType()); } List<ForcedRoot> bySQL2 = exporter.query(session, "select * from [sling:Folder]"); for (String path : paths) { ForcedRoot root0 = bySQL2.stream().filter(root -> path.equals(root.getPath())).findFirst().orElse(null); assertNotNull(String.format("root for path %s should not be null", path), root0); assertEquals(String.format("root primaryType for path %s should be sling:Folder", path), "sling:Folder", root0.getPrimaryType()); } }); }