@NotNull public QueryEngine getQueryEngine() { return root.getQueryEngine(); }
@NotNull public QueryEngine getQueryEngine() { return root.getQueryEngine(); }
@Nonnull public QueryEngine getQueryEngine() { return root.getQueryEngine(); }
@NotNull @Override public QueryEngine getQueryEngine() { return base.getQueryEngine(); }
QueryEngine queryEngine = root.getQueryEngine(); return queryEngine.executeQuery( stmt.toString(), Query.XPATH,
@NotNull private Iterator<Authorizable> findAuthorizables(@NotNull String statement, long limit, long offset, @Nullable AuthorizableType type) throws RepositoryException { try { Result query = root.getQueryEngine().executeQuery( statement, javax.jcr.query.Query.XPATH, limit, offset, NO_BINDINGS, namePathMapper.getSessionLocalMappings()); Iterable<? extends ResultRow> resultRows = query.getRows(); Iterator<Authorizable> authorizables = Iterators.transform(resultRows.iterator(), new ResultRowToAuthorizable(userManager, root, type)); return Iterators.filter(authorizables, new UniqueResultPredicate()); } catch (ParseException e) { log.warn("Invalid user query: " + statement, e); throw new RepositoryException(e); } }
@Nullable Tree getAuthorizableByPrincipal(@NotNull Principal principal) { if (principal instanceof TreeBasedPrincipal) { return root.getTree(((TreeBasedPrincipal) principal).getOakPath()); } // NOTE: in contrast to JR2 the extra shortcut for ID==principalName // can be omitted as principals names are stored in user defined // index as well. try { StringBuilder stmt = new StringBuilder(); stmt.append("SELECT * FROM [").append(UserConstants.NT_REP_AUTHORIZABLE).append(']'); stmt.append(" WHERE [").append(UserConstants.REP_PRINCIPAL_NAME).append("] = $principalName"); stmt.append(QueryEngine.INTERNAL_SQL2_QUERY); Result result = root.getQueryEngine().executeQuery(stmt.toString(), Query.JCR_SQL2, 1, 0, Collections.singletonMap("principalName", PropertyValues.newString(principal.getName())), NO_MAPPINGS); Iterator<? extends ResultRow> rows = result.getRows().iterator(); if (rows.hasNext()) { String path = rows.next().getPath(); return root.getTree(path); } } catch (ParseException ex) { log.error("Failed to retrieve authorizable by principal", ex); } return null; }
@Nullable Tree getAuthorizableByPrincipal(@NotNull Principal principal) { if (principal instanceof TreeBasedPrincipal) { return root.getTree(((TreeBasedPrincipal) principal).getOakPath()); } // NOTE: in contrast to JR2 the extra shortcut for ID==principalName // can be omitted as principals names are stored in user defined // index as well. try { StringBuilder stmt = new StringBuilder(); stmt.append("SELECT * FROM [").append(UserConstants.NT_REP_AUTHORIZABLE).append(']'); stmt.append(" WHERE [").append(UserConstants.REP_PRINCIPAL_NAME).append("] = $principalName"); stmt.append(QueryEngine.INTERNAL_SQL2_QUERY); Result result = root.getQueryEngine().executeQuery(stmt.toString(), Query.JCR_SQL2, 1, 0, Collections.singletonMap("principalName", PropertyValues.newString(principal.getName())), NO_MAPPINGS); Iterator<? extends ResultRow> rows = result.getRows().iterator(); if (rows.hasNext()) { String path = rows.next().getPath(); return root.getTree(path); } } catch (ParseException ex) { log.error("Failed to retrieve authorizable by principal", ex); } return null; }
@NotNull private Iterator<Authorizable> findAuthorizables(@NotNull String statement, long limit, long offset, @Nullable AuthorizableType type) throws RepositoryException { try { Result query = root.getQueryEngine().executeQuery( statement, javax.jcr.query.Query.XPATH, limit, offset, NO_BINDINGS, namePathMapper.getSessionLocalMappings()); Iterable<? extends ResultRow> resultRows = query.getRows(); Iterator<Authorizable> authorizables = Iterators.transform(resultRows.iterator(), new ResultRowToAuthorizable(userManager, root, type)); return Iterators.filter(authorizables, new UniqueResultPredicate()); } catch (ParseException e) { log.warn("Invalid user query: " + statement, e); throw new RepositoryException(e); } }
@Nonnull private Iterator<Authorizable> findAuthorizables(@Nonnull String statement, long limit, long offset, @Nullable AuthorizableType type) throws RepositoryException { try { Result query = root.getQueryEngine().executeQuery( statement, javax.jcr.query.Query.XPATH, limit, offset, NO_BINDINGS, namePathMapper.getSessionLocalMappings()); Iterable<? extends ResultRow> resultRows = query.getRows(); Iterator<Authorizable> authorizables = Iterators.transform(resultRows.iterator(), new ResultRowToAuthorizable(userManager, root, type)); return Iterators.filter(authorizables, new UniqueResultPredicate()); } catch (ParseException e) { log.warn("Invalid user query: " + statement, e); throw new RepositoryException(e); } }
/** * Runs an Oak query searching for {@link #REP_EXTERNAL_PRINCIPAL_NAMES} properties * that match the given name or name hint. * * NOTE: ignore any principals listed in the {@link DefaultSyncConfig.User#autoMembership} * because they are expected to exist in the system and thus will be found * by another principal provider instance. * * @param nameHint The principal name or name hint to be searched for. * @param exactMatch boolean flag indicating if the query should search for * exact matching. * @return The query result. */ @Nullable private Result findPrincipals(@NotNull String nameHint, boolean exactMatch) { try { Map<String, ? extends PropertyValue> bindings = buildBinding(nameHint, exactMatch); String op = (exactMatch) ? " = " : " LIKE "; String statement = "SELECT '" + REP_EXTERNAL_PRINCIPAL_NAMES + "' FROM [rep:User] WHERE PROPERTY([" + REP_EXTERNAL_PRINCIPAL_NAMES + "], '" + PropertyType.TYPENAME_STRING + "')" + op + "$" + BINDING_PRINCIPAL_NAMES + QueryEngine.INTERNAL_SQL2_QUERY; return root.getQueryEngine().executeQuery(statement, Query.JCR_SQL2, bindings, namePathMapper.getSessionLocalMappings()); } catch (ParseException e) { 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; } }
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 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()); }
Set<String> getSuggestions(String nodeType, String suggestFor) throws Exception { Set<String> ret = Sets.newHashSet(); String suggQuery = createSuggestQuery(nodeType, suggestFor); QueryEngine qe = root.getQueryEngine(); Result result = qe.executeQuery(suggQuery, Query.JCR_SQL2, null, null); for (ResultRow row : result.getRows()) { ret.add(row.getValue("suggestion").toString()); } return ret; }
@Before public void before() throws Exception { session = createRepository().login(null, null); root = session.getLatestRoot(); qe = root.getQueryEngine(); }
@Before public void before() throws Exception { session = createRepository().login(null, null); root = session.getLatestRoot(); qe = root.getQueryEngine(); createTestIndexNode(); }
@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); }
@Before public void before() throws Exception { session = createRepository().login(null, null); root = session.getLatestRoot(); qe = root.getQueryEngine(); root.getTree("/oak:index/counter").setProperty("resolution", 100); root.getTree("/oak:index/counter").setProperty("seed", 1); Tree content = root.getTree("/").addChild("content"); // add 200'000 nodes under /content for (int i = 0; i < 2000; i++) { Tree t = content.addChild("test" + i); for (int j = 0; j < 100; j++) { t.addChild("n" + j); } } root.commit(); runAsyncIndex(); }