use of javax.jcr.query.RowIterator in project jackrabbit-oak by apache.
the class LuceneIndexDescendantSuggestionTest method ambiguousSubtreeIndexWithDescendantConstraint.
@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"));
}
use of javax.jcr.query.RowIterator in project jackrabbit-oak by apache.
the class LuceneIndexDescendantSuggestionTest method getSuggestions.
private Set<String> getSuggestions(String query) throws Exception {
QueryManager queryManager = session.getWorkspace().getQueryManager();
QueryResult result = queryManager.createQuery(query, Query.JCR_SQL2).execute();
RowIterator rows = result.getRows();
Set<String> suggestions = newHashSet();
while (rows.hasNext()) {
suggestions.add(rows.nextRow().getValue("suggestion").getString());
}
return suggestions;
}
use of javax.jcr.query.RowIterator in project jackrabbit-oak by apache.
the class JsonIndexCommand method runQuery.
private void runQuery(String query, String language, String columnName, boolean quiet, int depth) throws RepositoryException {
ArrayList<String> list = new ArrayList<String>();
columnName = query.startsWith("explain") ? "plan" : columnName;
QueryManager qm = session.getWorkspace().getQueryManager();
Query q = qm.createQuery(query, language);
for (String b : q.getBindVariableNames()) {
ValueFactory vf = session.getValueFactory();
q.bindValue(b, vf.createValue(data.get("$" + b).toString()));
}
QueryResult result = q.execute();
if (depth != 0) {
NodeIterator ni = result.getNodes();
JsopBuilder builder = new JsopBuilder().array();
while (ni.hasNext()) {
Node n = ni.nextNode();
builder.key(n.getPath());
appendNode(builder, n, depth - 1);
}
output.println(JsopBuilder.prettyPrint(builder.endArray().toString()));
return;
}
RowIterator ri = result.getRows();
while (ri.hasNext()) {
Row r = ri.nextRow();
if (columnName != null) {
String x = r.getValue(columnName).getString();
list.add(x);
if (!quiet) {
output.println(x);
}
} else {
String[] columnNames = result.getColumnNames();
for (String cn : columnNames) {
Value v = r.getValue(cn);
String x = v == null ? null : v.getString();
if (columnNames.length == 1) {
list.add(x);
if (!quiet) {
output.println(x);
}
} else {
list.add(x);
if (!quiet) {
output.println(cn + ": " + x);
}
}
}
}
}
data.put("$resultSize", (long) list.size());
data.put("$result", list.toArray(new String[0]));
}
use of javax.jcr.query.RowIterator in project jackrabbit-oak by apache.
the class LuceneIndexSuggestionTest method avoidInfiniteSuggestions.
@Test
public void avoidInfiniteSuggestions() throws Exception {
final String nodeType = "nt:unstructured";
final String indexPropName = "description";
final String higherRankPropValue = "DD DD DD DD";
final String exceptionThrowingPropValue = "DD~@#$%^&*()_+{}\":?><`1234567890-=[]";
final String suggestQueryText = "dd";
createSuggestIndex("lucene-suggest", nodeType, indexPropName);
root.addNode("higherRankNode", nodeType).setProperty(indexPropName, higherRankPropValue);
root.addNode("exceptionThrowingNode", nodeType).setProperty(indexPropName, exceptionThrowingPropValue);
session.save();
String suggQuery = createSuggestQuery(nodeType, suggestQueryText);
QueryManager queryManager = session.getWorkspace().getQueryManager();
QueryResult result = queryManager.createQuery(suggQuery, Query.JCR_SQL2).execute();
RowIterator rows = result.getRows();
int count = 0;
while (count < 3 && rows.hasNext()) {
count++;
rows.nextRow();
}
assertTrue("There must not be more than 2 suggestions", count <= 2);
}
use of javax.jcr.query.RowIterator in project sling by apache.
the class JcrResourceBundleTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
cleanRepository();
RepositoryUtil.registerNodeType(getSession(), getClass().getResourceAsStream("/SLING-INF/nodetypes/jcrlanguage.cnd"));
RepositoryUtil.registerNodeType(getSession(), getClass().getResourceAsStream("/SLING-INF/nodetypes/message.cnd"));
resolver = new ResourceResolver() {
@Override
public Iterator<Resource> findResources(String query, String language) {
try {
final Query q = getSession().getWorkspace().getQueryManager().createQuery(query, language);
final QueryResult result = q.execute();
final NodeIterator nodes = result.getNodes();
return new Iterator<Resource>() {
@Override
public boolean hasNext() {
return nodes.hasNext();
}
@Override
public Resource next() {
final Node node = nodes.nextNode();
return new TestResource(resolver, node);
}
@Override
public void remove() {
throw new UnsupportedOperationException("remove");
}
};
} catch (NamingException ne) {
return null;
} catch (RepositoryException re) {
return null;
}
}
@Override
public Resource getResource(Resource base, String path) {
// TODO Auto-generated method stub
return null;
}
@Override
public Resource getResource(String path) {
try {
final Node n = getSession().getNode(path);
return new TestResource(resolver, n);
} catch (NamingException ne) {
//ignore
} catch (RepositoryException re) {
//ignore
}
return null;
}
@Override
public String[] getSearchPath() {
return new String[] { "/apps/", "/libs/" };
}
@Override
public Iterator<Resource> listChildren(final Resource parent) {
try {
final Node n = getSession().getNode(parent.getPath());
final NodeIterator nodes = n.getNodes();
return new Iterator<Resource>() {
@Override
public boolean hasNext() {
return nodes.hasNext();
}
@Override
public Resource next() {
final Node node = nodes.nextNode();
return new TestResource(resolver, node);
}
@Override
public void remove() {
throw new UnsupportedOperationException("remove");
}
};
} catch (final RepositoryException re) {
// ignore
return null;
} catch (final NamingException e) {
// ignore
return null;
}
}
@Override
public String map(HttpServletRequest request, String resourcePath) {
// TODO Auto-generated method stub
return null;
}
@Override
public String map(String resourcePath) {
// TODO Auto-generated method stub
return null;
}
@Override
public Iterator<Map<String, Object>> queryResources(String query, String language) {
try {
final Query q = getSession().getWorkspace().getQueryManager().createQuery(query, language);
final QueryResult result = q.execute();
final String[] colNames = result.getColumnNames();
final RowIterator rows = result.getRows();
return new Iterator<Map<String, Object>>() {
@Override
public boolean hasNext() {
return rows.hasNext();
}
@Override
public Map<String, Object> next() {
Map<String, Object> row = new HashMap<String, Object>();
try {
Value[] values = rows.nextRow().getValues();
for (int i = 0; i < values.length; i++) {
Value v = values[i];
if (v != null) {
row.put(colNames[i], values[i].getString());
}
}
} catch (RepositoryException re) {
// ignore
}
return row;
}
@Override
public void remove() {
throw new UnsupportedOperationException("remove");
}
};
} catch (NamingException ne) {
return null;
} catch (RepositoryException re) {
return null;
}
}
@Override
public Resource resolve(HttpServletRequest request, String absPath) {
// TODO Auto-generated method stub
return null;
}
@Override
public Resource resolve(HttpServletRequest request) {
// TODO Auto-generated method stub
return null;
}
@Override
public Resource resolve(String absPath) {
// TODO Auto-generated method stub
return null;
}
@Override
public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
// TODO Auto-generated method stub
return null;
}
@Override
public void close() {
// nothing to do
}
@Override
public String getUserID() {
return null;
}
@Override
public boolean isLive() {
return true;
}
@Override
public ResourceResolver clone(Map<String, Object> authenticationInfo) {
return null;
}
@Override
public Iterator<String> getAttributeNames() {
return null;
}
@Override
public Object getAttribute(String name) {
return null;
}
@Override
public Iterable<Resource> getChildren(Resource parent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void delete(Resource resource) throws PersistenceException {
// TODO Auto-generated method stub
}
@Override
public Resource create(Resource parent, String name, Map<String, Object> properties) throws PersistenceException {
// TODO Auto-generated method stub
return null;
}
@Override
public void revert() {
// TODO Auto-generated method stub
}
@Override
public void commit() throws PersistenceException {
// TODO Auto-generated method stub
}
@Override
public boolean hasChanges() {
// TODO Auto-generated method stub
return false;
}
@Override
public String getParentResourceType(Resource resource) {
// TODO Auto-generated method stub
return null;
}
@Override
public String getParentResourceType(String resourceType) {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean isResourceType(final Resource resource, final String resourceType) {
return resourceType.equals(resource.getResourceType());
}
@Override
public void refresh() {
// TODO Auto-generated method stub
}
@Override
public Resource getParent(Resource child) {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean hasChildren(Resource resource) {
// TODO Auto-generated method stub
return false;
}
@Override
public Resource copy(String srcAbsPath, String destAbsPath) throws PersistenceException {
// TODO Auto-generated method stub
return null;
}
@Override
public Resource move(String srcAbsPath, String destAbsPath) throws PersistenceException {
// TODO Auto-generated method stub
return null;
}
};
createTestContent();
}
Aggregations