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(); }
public void testScoreWithOr() throws Exception { Session session = superuser; QueryManager qm = session.getWorkspace().getQueryManager(); Node n1 = testRootNode.addNode("node1"); n1.setProperty("text", "hello"); n1.setProperty("id", "1"); session.save(); String xpath = "/jcr:root//*[jcr:contains(@text, 'hello') or @id = '1']"; Query q = qm.createQuery(xpath, "xpath"); String result = getResult(q.execute(), "jcr:path"); assertEquals("/testroot/node1", result); }
public void testOuterJoinExtraNodeWithCondition() throws Exception { Node n3 = testRootNode.addNode("node3", "test:SamplePage"); n3.setProperty("n1prop1", "page1"); testRootNode.getSession().save(); StringBuilder join = new StringBuilder(); join.append(" Select * from [test:SamplePage] as page left outer join [test:SampleContent] as content on ISDESCENDANTNODE(content,page) where page.n1prop1 = 'page1' and content.n2prop1 = 'XXX' "); checkResult(qm.createQuery(join.toString(), JCR_SQL2).execute(), 0); }
@Test public void shouldGetNodesOrderedByPath() throws RepositoryException { String sql = "SELECT * FROM [nt:unstructured] WHERE ISCHILDNODE('/Cars') ORDER BY [jcr:path]"; Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2); validateQuery().rowCount(4).validate(query, query.execute()); }
@Ignore("OAK-3992") @Test public void ambiguousSubtreeIndexWithDescendantConstraint() throws Exception { String query = createSuggestQuery(NT_OAK_UNSTRUCTURED, "te", "/content2"); String explainQuery = "EXPLAIN " + createSuggestQuery(NT_OAK_UNSTRUCTURED, "te", "/content2"); QueryManager queryManager = session.getWorkspace().getQueryManager(); QueryResult result = queryManager.createQuery(explainQuery, Query.JCR_SQL2).execute(); RowIterator rows = result.getRows(); String explanation = rows.nextRow().toString(); assertTrue("Subtree index should get picked", explanation.contains("lucene:sugg-idx(/content2/oak:index/sugg-idx)")); validateSuggestions(query, newHashSet("test4")); }
@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()); }
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()); }
public void testSimpleQuerySQL4() throws Exception { Node foo = testRootNode.addNode("foo"); foo.setProperty("bla", new String[]{"bla"}); Node bla = testRootNode.addNode("bla"); bla.setProperty("bla", new String[]{"bla"}); testRootNode.save(); String sql = "SELECT * FROM nt:unstructured WHERE jcr:path LIKE '" + testRoot + "/%'"; Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL); QueryResult result = q.execute(); checkResult(result, 2); }
@FixFor( "MODE-2286" ) @Test public void shouldFindSystemNodesUsingPathLikeCriteriaWithAllSnsIndexSpecified() throws Exception { String sql = "select [jcr:path] from [nt:base] where [jcr:path] like '/Other[1]/NodeA[%]'"; Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2); validateQuery().rowCount(3).validate(query, query.execute()); }
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; }
public void testLikeWithLineTerminator() throws Exception { Node n = testRootNode.addNode("node1"); n.setProperty("value", new String[]{"foo\nbar"}); testRootNode.save(); String sql = "SELECT * FROM nt:base WHERE jcr:path LIKE '" + testRoot + "/%' AND value LIKE 'foo%bar'"; Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL); QueryResult result = q.execute(); checkResult(result, 1); sql = "SELECT * FROM nt:base WHERE jcr:path LIKE '" + testRoot + "/%' AND value LIKE 'foo_bar'"; q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL); result = q.execute(); checkResult(result, 1); }
@SuppressWarnings( "deprecation" ) @Test public void shouldBeAbleToCreateAndExecuteSqlQueryWithOrderByPathClause() throws RepositoryException { String sql = "SELECT car:model FROM car:Car WHERE car:model IS NOT NULL ORDER BY PATH() ASC"; Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.SQL); QueryResult result = query.execute(); validateQuery().rowCount(13).hasColumns("jcr:path", "jcr:score", "car:model").validate(query, result); }
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 testSimpleQuerySQL1() throws Exception { Node foo = testRootNode.addNode("foo"); foo.setProperty("bla", new String[]{"bla"}); testRootNode.save(); String sql = "SELECT * FROM nt:base" + " WHERE jcr:path LIKE '" + testRoot + "/foo'" + " AND bla = 'bla'"; Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL); QueryResult result = q.execute(); checkResult(result, 1); }
@SuppressWarnings( "deprecation" ) @Test public void shouldBeAbleToCreateAndExecuteSqlQueryWithPathCriteriaAndOrderByClause() throws RepositoryException { String sql = "SELECT car:model FROM car:Car WHERE jcr:path LIKE '/Cars/%' ORDER BY car:model ASC"; Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.SQL); QueryResult result = query.execute(); validateQuery().rowCount(13).hasColumns("jcr:path", "jcr:score", "car:model").validate(query, result); }
/** * 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(); }
public void testFulltextSimpleSQL() throws Exception { Node foo = testRootNode.addNode("foo"); foo.setProperty("mytext", new String[]{"the quick brown fox jumps over the lazy dog."}); testRootNode.save(); String sql = "SELECT * FROM [nt:unstructured]" + " WHERE ISCHILDNODE([" + testRoot + "])" + " AND CONTAINS(mytext, 'fox')"; Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2); QueryResult result = q.execute(); checkResult(result, 1); }
@SuppressWarnings( "deprecation" ) @Test public void shouldBeAbleToExecuteXPathQueryToFindNodesWithAllSnsIndexesUnderPath() throws RepositoryException { String xpath = " /jcr:root//NodeA"; Query query = session.getWorkspace().getQueryManager().createQuery(xpath, Query.XPATH); QueryResult result = query.execute(); validateQuery().rowCount(3).hasColumns("jcr:primaryType", "jcr:path", "jcr:score").validate(query, result); }
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 void testContainsStarXPath() throws RepositoryException { Node n = testRootNode.addNode("node1"); n.setProperty("title", new String[]{"tEst text"}); n.setProperty("mytext", new String[]{"The quick brown Fox jumps over the lazy dog."}); n = testRootNode.addNode("node2"); n.setProperty("title", new String[]{"The quick brown Fox jumps over the lazy dog."}); n.setProperty("mytext", new String[]{"text text"}); testRootNode.save(); String sql = "/jcr:root" + testRoot + "/element(*, nt:unstructured)" + "[jcr:contains(., 'quick fox')]"; Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.XPATH); checkResult(q.execute(), 2); }