Refine search
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; }
/** * Uses JCR directly to only retrieve the identifiers of persisted ProducerInfos to avoid having to create full ProducerInfoMappings when we only want the identifiers. This * *should* be faster but I guess that depends on the JCR implementation and would need to be evaluated. * * @param session the ChromatticSession used to access the JCR store * @return a RowIterator JCR view over the ProducerInfo identifiers * @throws RepositoryException */ private RowIterator getProducerInfoIds(ChromatticSession session) throws RepositoryException { final Session jcrSession = session.getJCRSession(); final Query query = jcrSession.getWorkspace().getQueryManager().createQuery("select producerid from wsrp:producerinfo", Query.SQL); final QueryResult queryResult = query.execute(); return queryResult.getRows(); }
/** * Verifies that searching for a property from a single node returns only * one row and has the searched property * * @throws NotExecutableException if {@link #testRootNode} does not have any * child nodes. */ public void testSingleProperty() throws RepositoryException, NotExecutableException { if (!testRootNode.hasNodes()) { throw new NotExecutableException("Workspace does not contains enough content."); } // build search query statement String firstChildpath = testRootNode.getNodes().nextNode().getPath(); String propQuery = "/" + jcrRoot + firstChildpath + "[@" + jcrPrimaryType + "]"; // execute search query Query query = session.getWorkspace().getQueryManager().createQuery(propQuery, qsXPATH); QueryResult result = query.execute(); assertEquals("Should have only 1 result", 1, getSize(result.getRows())); assertTrue("Should contain the searched property", Arrays.asList(result.getColumnNames()).contains(jcrPrimaryType)); } }
/** * Creates a new query info based on a given <code>result</code>. * * @param result the JCR query result. * @param idFactory the id factory. * @param resolver the name path resolver. * @param qValueFactory the QValue factory. * @throws RepositoryException if an error occurs while reading from * <code>result</code>. */ public QueryInfoImpl(QueryResult result, IdFactoryImpl idFactory, NamePathResolver resolver, QValueFactory qValueFactory) throws RepositoryException { this.result = result; this.idFactory = idFactory; this.resolver = resolver; this.qValueFactory = qValueFactory; this.columnNames = result.getColumnNames(); this.selectorNames = result.getSelectorNames(); }
public Object call(Query query) throws RepositoryException { QueryResult result = query.execute(); String[] names = result.getSelectorNames(); assertNotNull(names); assertEquals(1, names.length); assertEquals("s", names[0]); NodeIterator it = result.getNodes(); while (it.hasNext()) { assertTrue("Wrong node type", it.nextNode().isNodeType(testNodeType)); } return null; } });
@Test public void testOak1171() throws RepositoryException { Session session = createAdminSession(); Node p = session.getRootNode().addNode("etc"); p.addNode("p1").setProperty("title", "test"); p.addNode("p2").setProperty("title", 1); session.save(); Query q = session.getWorkspace().getQueryManager() .createQuery("//*[@title = 'test']", "xpath"); QueryResult qr = q.execute(); NodeIterator ni = qr.getNodes(); assertTrue(ni.hasNext()); Node n = ni.nextNode(); assertEquals("/etc/p1", n.getPath()); assertFalse(ni.hasNext()); session.logout(); }
public void testVersionFromQuery() throws RepositoryException, NotExecutableException { Node n = testRootNode.addNode(nodeName1, testNodeType); n.addMixin(mixVersionable); superuser.save(); VersionManager vMgr = superuser.getWorkspace().getVersionManager(); vMgr.checkpoint(n.getPath()); QueryManager qm = superuser.getWorkspace().getQueryManager(); Version v = vMgr.getBaseVersion(n.getPath()); Query q = qm.createQuery("//element(*, nt:version)[@jcr:uuid = '" + v.getIdentifier() + "']", Query.XPATH); NodeIterator nodes = q.execute().getNodes(); assertTrue(nodes.hasNext()); assertTrue(nodes.nextNode() instanceof Version); RowIterator rows = q.execute().getRows(); assertTrue(rows.hasNext()); assertTrue(rows.nextRow().getNode() instanceof Version); }
public void testParentInAttribute1() throws RepositoryException { String stmt = testPath + "//child[../@foo1]"; QueryResult result = qm.createQuery(stmt, Query.XPATH).execute(); assertTrue("Wrong size of NodeIterator in result", result.getNodes().getSize() > 0); assertEquals("child", result.getNodes().nextNode().getName()); }
@Test public void date() throws Exception { Session session = getAdminSession(); Node t1 = session.getRootNode().addNode("t1"); t1.setProperty("x", "22.06.07"); Node t2 = session.getRootNode().addNode("t2"); t2.setProperty("x", "2007-06-22T01:02:03.000Z", PropertyType.DATE); session.save(); String query = "//*[x='a' or x='b']"; QueryResult r = session.getWorkspace(). getQueryManager().createQuery( query, "xpath").execute(); NodeIterator it = r.getNodes(); assertFalse(it.hasNext()); }
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(); }
public void testGetSizeOrderByScore() throws RepositoryException { QueryManager qm = superuser.getWorkspace().getQueryManager(); for (int i = 0; i < 10; i++) { String stmt = testPath + "/*[@" + propertyName1 + " < 1000] order by jcr:score()"; QueryResult result = qm.createQuery(stmt, Query.XPATH).execute(); assertEquals("Wrong size of NodeIterator in result", INITIAL_NODE_NUM - i, result.getNodes().getSize()); // remove node for the next iteration testRootNode.getNode("node" + i).remove(); testRootNode.save(); } }
@Test public void firstSelector() throws Exception { Session session = getAdminSession(); Node root = session.getRootNode(); Node a = root.addNode("a"); a.setProperty("test", true); Node b = a.addNode("b"); b.setProperty("test", true); session.save(); QueryResult r = session.getWorkspace().getQueryManager() .createQuery("//a[@test]/b[@test]", "xpath").execute(); String firstSelector = r.getSelectorNames()[0]; RowIterator rows = r.getRows(); Row row = rows.nextRow(); String path = row.getPath(firstSelector); assertEquals("/a/b", path); }
protected void nodeExists( Session session, String parentPath, String childName, boolean exists ) throws Exception { Node parent = session.getNode(parentPath); assertThat(parent.hasNode(childName), is(exists)); String path = parent.getPath(); if (parent.getDepth() != 0) path = path + "/"; path = path + childName; String sql = "SELECT * FROM [nt:base] WHERE PATH() = '" + path + "'"; Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2); QueryResult result = query.execute(); assertThat(result.getNodes().getSize(), is(exists ? 1L : 0L)); }
public StoreIterator(final Class assignClass) throws Exception { super(); this.assignClass = assignClass; javax.jcr.query.QueryManager qm = LifeTimeJCRSessionUtil.getHierarchyManager(WorkflowConstants.WORKSPACE_EXPRESSION).getWorkspace().getQueryManager(); final javax.jcr.query.Query query = qm.createQuery(WorkflowConstants.STORE_ITERATOR_QUERY, Query.SQL); final javax.jcr.query.QueryResult qr = query.execute(); if (log.isDebugEnabled()) { log.debug("() query found " + qr.getNodes().getSize() + " elements"); } this.rootIterator = qr.getNodes(); this.next = fetchNext(); }
/** * 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(); }
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())); } }
@Override protected void runTest() throws Exception { QueryManager qm = session.getWorkspace().getQueryManager(); Query q = qm.createQuery(getQuery(), Query.JCR_SQL2); QueryResult r = q.execute(); NodeIterator nodes = r.getNodes(); int counter = 0; while(nodes.hasNext() && counter++<FETCH_NODES) { nodes.next(); } }
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(); }
/** * Verify that the jcr:path is present in the query result. */ public void testJcrPath() throws RepositoryException, NotExecutableException { String nodeTypeName = session.getRootNode().getPrimaryNodeType().getName(); String queryStatement = "//element(*, " + nodeTypeName + ")"; // execute the search query Query query = session.getWorkspace().getQueryManager().createQuery(queryStatement, qsXPATH); QueryResult result = query.execute(); assertTrue("jcr:path must be present in query result row", Arrays.asList(result.getColumnNames()).contains(jcrPath)); } }
private void run0() throws RepositoryException { session.refresh(false); QueryManager qm = session.getWorkspace().getQueryManager(); Query q = qm.createQuery("select * from [nt:base] where [" + indexedPropName + "] = $status " + "option(index tag fooIndex)", Query.JCR_SQL2); q.bindValue("status", session.getValueFactory().createValue(randomStatus())); QueryResult result = q.execute(); //With property index at time traversing index wins (somehow reporting lower cost) //and that leads to warning. So limit the iterator size resultSize += Iterators.size(Iterators.limit(result.getNodes(), 500)); } }