@Override public String getSelectorPath(String selector) { return row.getPath(selector); }
@Override public String apply(ResultRow row) { return PathUtils.concat(row.getPath(), propertyName); } });
@Override public String getPath() throws RepositoryException { try { return row.getPath(pathSelector); } catch (IllegalArgumentException e) { throw new RepositoryException(e); } }
@Override public String apply(ResultRow row) { return PathUtils.concat(row.getPath(), propertyName); } });
@Override public String getPath(String selectorName) throws RepositoryException { try { return row.getPath(selectorName); } catch (IllegalArgumentException e) { throw new RepositoryException(e); } }
@Override public String getPath(String selectorName) throws RepositoryException { try { return row.getPath(selectorName); } catch (IllegalArgumentException e) { throw new RepositoryException(e); } }
@Override public String getPath(String selectorName) throws RepositoryException { try { return row.getPath(selectorName); } catch (IllegalArgumentException e) { throw new RepositoryException(e); } }
@Override public String getPath() throws RepositoryException { try { return row.getPath(pathSelector); } catch (IllegalArgumentException e) { throw new RepositoryException(e); } }
@Override public String getPath() throws RepositoryException { try { return row.getPath(pathSelector); } catch (IllegalArgumentException e) { throw new RepositoryException(e); } }
@Override public String apply(ResultRow row) { return PathUtils.concat(row.getPath(), propertyName); } });
private String resolveUUID(PropertyValue uuid) { try { Map<String, PropertyValue> bindings = Collections.singletonMap("id", uuid); Result result = root.getQueryEngine().executeQuery( "SELECT * FROM [nt:base] WHERE [jcr:uuid] = $id " + "OPTION(INDEX NAME [uuid], INDEX TAG [uuid])" + QueryEngine.INTERNAL_SQL2_QUERY, Query.JCR_SQL2, bindings, NO_MAPPINGS); String path = null; for (ResultRow rr : result.getRows()) { if (path != null) { log.error("multiple results for identifier lookup: " + path + " vs. " + rr.getPath()); return null; } else { path = rr.getPath(); } } return path; } catch (ParseException ex) { log.error("query failed", ex); return null; } }
private String resolveUUID(PropertyValue uuid) { try { Map<String, PropertyValue> bindings = Collections.singletonMap("id", uuid); Result result = root.getQueryEngine().executeQuery( "SELECT * FROM [nt:base] WHERE [jcr:uuid] = $id " + "OPTION(INDEX NAME [uuid], INDEX TAG [uuid])" + QueryEngine.INTERNAL_SQL2_QUERY, Query.JCR_SQL2, bindings, NO_MAPPINGS); String path = null; for (ResultRow rr : result.getRows()) { if (path != null) { log.error("multiple results for identifier lookup: " + path + " vs. " + rr.getPath()); return null; } else { path = rr.getPath(); } } return path; } catch (ParseException ex) { log.error("query failed", ex); return null; } }
private String resolveUUID(PropertyValue uuid) { try { Map<String, PropertyValue> bindings = Collections.singletonMap("id", uuid); Result result = root.getQueryEngine().executeQuery( "SELECT * FROM [nt:base] WHERE [jcr:uuid] = $id " + "OPTION(INDEX NAME [uuid], INDEX TAG [uuid])" + QueryEngine.INTERNAL_SQL2_QUERY, Query.JCR_SQL2, bindings, NO_MAPPINGS); String path = null; for (ResultRow rr : result.getRows()) { if (path != null) { log.error("multiple results for identifier lookup: " + path + " vs. " + rr.getPath()); return null; } else { path = rr.getPath(); } } return path; } catch (ParseException ex) { log.error("query failed", ex); return null; } }
@Override protected Principal getNext() { while (rows.hasNext()) { String userPath = rows.next().getPath(); try { Authorizable authorizable = userManager.getAuthorizableByPath(userPath); if (authorizable != null) { return authorizable.getPrincipal(); } } catch (RepositoryException e) { log.debug("{}", e.getMessage()); } } return null; } }
@Nullable private JackrabbitAccessControlList createPrincipalACL(@Nullable String oakPath, @NotNull Principal principal) throws RepositoryException { Root root = getRoot(); Result aceResult = searchAces(Collections.<Principal>singleton(principal), root); RestrictionProvider restrProvider = new PrincipalRestrictionProvider(restrictionProvider); List<ACE> entries = new ArrayList<>(); for (ResultRow row : aceResult.getRows()) { Tree aceTree = root.getTree(row.getPath()); if (Util.isACE(aceTree, ntMgr)) { String aclPath = Text.getRelativeParent(aceTree.getPath(), 1); String path; if (aclPath.endsWith(REP_REPO_POLICY)) { path = null; } else { path = Text.getRelativeParent(aclPath, 1); } entries.add(createACE(path, aceTree, restrProvider)); } } if (entries.isEmpty()) { // nothing found return null; } else { return new PrincipalACL(oakPath, principal, entries, restrProvider); } }
@Nullable private JackrabbitAccessControlList createPrincipalACL(@Nullable String oakPath, @NotNull Principal principal) throws RepositoryException { Root root = getRoot(); Result aceResult = searchAces(Collections.<Principal>singleton(principal), root); RestrictionProvider restrProvider = new PrincipalRestrictionProvider(restrictionProvider); List<ACE> entries = new ArrayList<>(); for (ResultRow row : aceResult.getRows()) { Tree aceTree = root.getTree(row.getPath()); if (Util.isACE(aceTree, ntMgr)) { String aclPath = Text.getRelativeParent(aceTree.getPath(), 1); String path; if (aclPath.endsWith(REP_REPO_POLICY)) { path = null; } else { path = Text.getRelativeParent(aclPath, 1); } entries.add(createACE(path, aceTree, restrProvider)); } } if (entries.isEmpty()) { // nothing found return null; } else { return new PrincipalACL(oakPath, principal, entries, restrProvider); } }
private static List<String> queryUuid(ContentSession session, String uuid) throws ParseException { Map<String, PropertyValue> bindings = Collections.singletonMap("id", PropertyValues.newString(uuid)); Result result = session.getLatestRoot().getQueryEngine().executeQuery( "SELECT * FROM [nt:base] WHERE [jcr:uuid] = $id" + QueryEngine.INTERNAL_SQL2_QUERY, Query.JCR_SQL2, bindings, NO_MAPPINGS); return StreamSupport.stream(result.getRows().spliterator(), false) .map(r -> r.getPath()) .collect(Collectors.toList()); }
@Test public void testOrderLimitOffset() throws Exception { String left = "SELECT [jcr:path] FROM [nt:base] AS a WHERE ISDESCENDANTNODE(a, '/UnionQueryTest')"; String right = "SELECT [jcr:path] FROM [nt:base] AS a WHERE ISDESCENDANTNODE(a, '/UnionQueryTest')"; String order = "ORDER BY [jcr:path]"; String union = String.format("%s UNION %s %s", left, right, order); final int limit = 3; final int offset = 2; String[] expected = { "/UnionQueryTest/a/b/c", "/UnionQueryTest/a/b/c/d", "/UnionQueryTest/a/b/c/d/e" }; Result result = qe.executeQuery(union, QueryEngineImpl.SQL2, limit, offset, QueryEngine.NO_BINDINGS, QueryEngine.NO_MAPPINGS); List<ResultRow> rows = Lists.newArrayList(result.getRows()); assertEquals(expected.length, rows.size()); int i = 0; for (ResultRow rr: result.getRows()) { assertEquals(rr.getPath(), expected[i++]); } } }
@Test public void bindVariableTest() throws Exception { Tree tree = root.getTree("/"); Tree test = tree.addChild("test"); test.addChild("hello").setProperty("id", "1"); test.addChild("world").setProperty("id", "2"); root.commit(); Map<String, PropertyValue> sv = new HashMap<String, PropertyValue>(); sv.put("id", PropertyValues.newString("1")); Iterator<? extends ResultRow> result; result = executeQuery("select * from [nt:base] where id = $id", SQL2, sv).getRows().iterator(); assertTrue(result.hasNext()); assertEquals("/test/hello", result.next().getPath()); sv.put("id", PropertyValues.newString("2")); result = executeQuery("select * from [nt:base] where id = $id", SQL2, sv).getRows().iterator(); assertTrue(result.hasNext()); assertEquals("/test/world", result.next().getPath()); }
@Test public void queryOnStableRevision() throws Exception { ContentSession s = repository.login(null, null); Root r = s.getLatestRoot(); Tree t = r.getTree("/").addChild("test"); t.addChild("node1").setProperty("jcr:primaryType", "nt:base"); t.addChild("node2").setProperty("jcr:primaryType", "nt:base"); t.addChild("node3").setProperty("jcr:primaryType", "nt:base"); r.commit(); ContentSession s2 = repository.login(null, null); Root r2 = s2.getLatestRoot(); r.getTree("/test").getChild("node2").remove(); r.commit(); Result result = r2.getQueryEngine().executeQuery( "test//element(*, nt:base)", Query.XPATH, QueryEngine.NO_BINDINGS, QueryEngine.NO_MAPPINGS); Set<String> paths = new HashSet<String>(); for (ResultRow rr : result.getRows()) { paths.add(rr.getPath()); } assertEquals(new HashSet<String>(Arrays.asList("/test/node1", "/test/node2", "/test/node3")), paths); }