private List<Node> getItemNodesToBeExecuted(final Session session) throws RepositoryException { final List<Node> initializeItems = new ArrayList<>(); final QueryManager queryManager = session.getWorkspace().getQueryManager(); final Query getInitializeItems = queryManager.createQuery(PENDING_INITIALIZE_ITEMS_QUERY, Query.SQL); final NodeIterator nodes = getInitializeItems.execute().getNodes(); while(nodes.hasNext()) { initializeItems.add(nodes.nextNode()); } return initializeItems; }
private void checkDeprecatedTypeNotInUse(final String nodeType) throws RepositoryException { final Query query = qm.createQuery("//element(*, " + nodeType + ")", Query.XPATH); final QueryResult queryResult = query.execute(); if (queryResult.getNodes().hasNext()) { final Node node = queryResult.getNodes().nextNode(); throw new RepositoryException(String.format( "Deprecated node type %s still in use at '%s'. Remove all usage of this node type before upgrading to v12", nodeType, node.getPath())); } }
/** * @return the overall size of the query without limit */ private long getResultSetSize(String queryString) throws RepositoryException { QueryResult qr = doQuery(queryString, Integer.MAX_VALUE, 0); NodeIterator iter = NodeUtil.filterDuplicates(NodeUtil.filterParentNodeType(qr.getNodes(), NodeTypes.Page.NAME)); long count = 0; while (iter.hasNext()) { iter.nextNode(); count++; } return count; }
public void testParentWithAnd() throws RepositoryException { String stmt = testPath + "//child[../@foo1 = 'bar1 and @foo2']"; QueryResult result = qm.createQuery(stmt, Query.XPATH).execute(); assertEquals("Wrong size of NodeIterator in result", 0, result.getNodes().getSize()); } }
public boolean hasTranslation(String language) throws RepositoryException { String id = node.getProperty(HippoTranslationNodeType.ID).getString(); Query query = node.getSession().getWorkspace().getQueryManager().createQuery( "SELECT * FROM " + HippoTranslationNodeType.NT_TRANSLATED + " WHERE " + HippoTranslationNodeType.ID + "='" + id + "'" + " AND " + HippoTranslationNodeType.LOCALE + "='" + language + "'", Query.SQL); final QueryResult result = query.execute(); NodeIterator nodes = result.getNodes(); return nodes.hasNext(); }
/** * @inheritDoc */ @Override public Node findNode(Name propertyName, String value, Name ntName) throws RepositoryException { Query query = buildQuery(value, Collections.singleton(propertyName), ntName, true, 1); NodeIterator res = query.execute().getNodes(); if (res.hasNext()) { return res.nextNode(); } return null; }
@Test @FixFor( "MODE-2220" ) public void shouldSupportUpperCaseOperand() throws Exception { String sql = "SELECT [jcr:path] FROM [nt:unstructured] AS node WHERE UPPER(node.something) LIKE '%FOX%'"; Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2); NodeIterator nodes = query.execute().getNodes(); assertEquals(1, nodes.getSize()); assertEquals("/Other/NodeA", nodes.nextNode().getPath()); }
/** * Tests the method <code>NodeIterator.getPosition()</code> on an empty * <code>NodeIterator</code>. * @throws NotExecutableException */ public void testGetPositionEmptyIterator() throws RepositoryException, NotExecutableException { QueryResult rs = execute(xpathRoot + "/" + nodeName4, qsXPATH); NodeIterator it = rs.getNodes(); assertFalse("NodeIterator must be empty.", it.hasNext()); assertEquals("Empty NodeIterator must return 0 on getPosition()", 0, it.getPosition()); }
static NodeIterator executeQuery(final Session session, final Node templateQueryNode) throws RepositoryException { final String statement = templateQueryNode.getProperty("jcr:statement").getString(); final String language = templateQueryNode.getProperty("jcr:language").getString(); final QueryManager queryManager = session.getWorkspace().getQueryManager(); final Query query = queryManager.createQuery(statement, language); final QueryResult queryResult = query.execute(); return queryResult.getNodes(); }
/** * @inheritDoc */ @Override public Node findNode(Name propertyName, String value, Name ntName) throws RepositoryException { Query query = buildQuery(value, Collections.singleton(propertyName), ntName, true, 1); NodeIterator res = query.execute().getNodes(); if (res.hasNext()) { return res.nextNode(); } return null; }
/** * Tests the method <code>NodeIterator.getPosition()</code>. */ public void testGetPosition() throws RepositoryException, NotExecutableException { QueryResult rs = execute(xpathRoot + "//*", qsXPATH); // getPosition initially returns 0 NodeIterator it = rs.getNodes(); assertEquals("Initial call to getPosition() must return 0.", 0, it.getPosition()); // check getPosition while iterating int index = 0; while (it.hasNext()) { it.nextNode(); assertEquals("Wrong position returned by getPosition()", ++index, it.getPosition()); } }
private void check(Session session) throws RepositoryException { check(session.getRootNode()); Query query = session.getWorkspace().getQueryManager().createQuery("//element(*,nt:base)", Query.XPATH); QueryResult result = query.execute(); for (NodeIterator iter = result.getNodes(); iter.hasNext();) { Node node = iter.nextNode(); if (node != null && log.isTraceEnabled()) { log.trace("query: {}", node.getPath()); } } }
public static boolean userExists(String username) { String queryString = QUERY_USER_EXISTS.replace("{}", username); try { Query query = getQueryManager().createQuery(queryString, Query.SQL); if (query.execute().getNodes().hasNext()) { return true; } } catch (RepositoryException e) { log.error("Unable to check if user '{}' exists, returning true", username, e); return true; } return false; }
private void check(Session session) throws RepositoryException { check(session.getRootNode()); Query query = session.getWorkspace().getQueryManager().createQuery("//element(*,nt:base)", Query.XPATH); QueryResult result = query.execute(); for (NodeIterator iter = result.getNodes(); iter.hasNext();) { Node node = iter.nextNode(); if (node != null && log.isTraceEnabled()) { log.trace("query: {}", node.getPath()); } } }
public static boolean exists(String groupname) { String queryString = QUERY_GROUP_EXISTS.replace("{}", groupname); try { Query query = getQueryManager().createQuery(queryString, Query.SQL); if (query.execute().getNodes().hasNext()) { return true; } } catch (RepositoryException e) { log.error("Unable to check if group '{}' exists, returning true", groupname, e); return true; } return false; }
/** * Find nodes located in the provided node or in sub-folders within it that have the provided nodeType. * As this method uses jcr queries to find nodes, it might not see nodes that have been created but not saved yet (i.e. during installation of a module). */ protected NodeIterator findPrincipalNodes(final Node node, final String nodeType) throws RepositoryException { final StringBuilder builder = new StringBuilder("select * from [").append(nodeType).append("]"); if (!"/".equals(node.getPath())) { builder.append(" where isdescendantnode(['").append(node.getPath()).append("'])"); } final String queryString = builder.toString(); log.debug("Executing query \"{}\".", queryString); final Query query = node.getSession().getWorkspace().getQueryManager().createQuery(queryString, Query.JCR_SQL2); return query.execute().getNodes(); }