use of javax.jcr.query.QueryResult in project jackrabbit-oak by apache.
the class LuceneIndexSuggestionTest method checkSuggestions.
/**
* Utility method to check suggestion over {@code queryNodeType} when the index definition is created for
* {@code indexNodeType}
*/
private void checkSuggestions(final String indexNodeType, final String queryNodeType, final String indexPropName, final String indexPropValue, final boolean addFullText, final boolean useUserSession, final String suggestQueryText, final boolean shouldSuggest, final boolean suggestAnalyzed) throws Exception {
createSuggestIndex("lucene-suggest", indexNodeType, indexPropName, addFullText, suggestAnalyzed);
Node indexedNode = root.addNode("indexedNode1", queryNodeType);
if (indexPropValue != null) {
indexedNode.setProperty(indexPropName, indexPropValue + " 1");
indexedNode = root.addNode("indexedNode2", queryNodeType);
indexedNode.setProperty(indexPropName, indexPropValue + " 2");
}
if (useUserSession) {
session.getUserManager().createUser(TEST_USER_NAME, TEST_USER_NAME);
}
session.save();
Session userSession = session;
if (useUserSession) {
AccessControlUtils.allow(indexedNode, TEST_USER_NAME, Privilege.JCR_READ);
session.save();
userSession = repository.login(new SimpleCredentials(TEST_USER_NAME, TEST_USER_NAME.toCharArray()));
}
String suggQuery = createSuggestQuery(queryNodeType, suggestQueryText);
QueryManager queryManager = userSession.getWorkspace().getQueryManager();
QueryResult result = queryManager.createQuery(suggQuery, Query.JCR_SQL2).execute();
RowIterator rows = result.getRows();
String value = null;
while (rows.hasNext()) {
Row firstRow = rows.nextRow();
value = firstRow.getValue("suggestion").getString();
}
if (shouldSuggest) {
assertNotNull("There should be some suggestion", value);
} else {
assertNull("There shouldn't be any suggestion", value);
}
userSession.logout();
}
use of javax.jcr.query.QueryResult in project sling by apache.
the class MockQueryManagerTest method testQueryResults_ResultHandler_Rows.
@SuppressWarnings("unchecked")
@Test
public void testQueryResults_ResultHandler_Rows() throws RepositoryException {
final List<String> columnNames = ImmutableList.of("stringProp", "intProp", "optionalStringProp");
MockJcr.addQueryResultHandler(queryManager, new MockQueryResultHandler() {
@Override
public MockQueryResult executeQuery(MockQuery query) {
return new MockQueryResult(sampleNodes, columnNames);
}
});
Query query = queryManager.createQuery("query1", Query.JCR_SQL2);
QueryResult result = query.execute();
assertEquals(sampleNodes, ImmutableList.copyOf(result.getNodes()));
assertEquals(columnNames, ImmutableList.copyOf(result.getColumnNames()));
List<Row> rows = ImmutableList.copyOf(result.getRows());
assertEquals("value1", rows.get(0).getValue("stringProp").getString());
assertEquals(1L, rows.get(0).getValue("intProp").getLong());
assertEquals("optValue1", rows.get(0).getValue("optionalStringProp").getString());
assertEquals("value2", rows.get(1).getValues()[0].getString());
assertEquals(2L, rows.get(1).getValues()[1].getLong());
assertNull(rows.get(1).getValues()[2]);
assertEquals("value3", rows.get(2).getValues()[0].getString());
assertEquals(3L, rows.get(2).getValues()[1].getLong());
assertNull(rows.get(2).getValues()[2]);
}
use of javax.jcr.query.QueryResult in project sling by apache.
the class MockQueryManagerTest method testNoQueryResults.
@Test
public void testNoQueryResults() throws RepositoryException {
Query query = queryManager.createQuery("dummy", Query.JCR_SQL2);
QueryResult result = query.execute();
assertFalse(result.getNodes().hasNext());
}
use of javax.jcr.query.QueryResult in project jackrabbit by apache.
the class QueryImpl method execute.
/**
* This method simply forwards the <code>execute</code> call to the
* {@link ExecutableQuery} object returned by
* {@link QueryHandler#createExecutableQuery}.
* {@inheritDoc}
*/
public QueryResult execute() throws RepositoryException {
checkInitialized();
long time = System.nanoTime();
QueryResult result = sessionContext.getSessionState().perform(new SessionOperation<QueryResult>() {
public QueryResult perform(SessionContext context) throws RepositoryException {
return query.execute(offset, limit);
}
public String toString() {
return "query.execute(" + statement + ")";
}
});
time = System.nanoTime() - time;
final long timeMs = time / 1000000;
log.debug("executed in {} ms. ({})", timeMs, statement);
RepositoryStatisticsImpl statistics = sessionContext.getRepositoryContext().getRepositoryStatistics();
statistics.getCounter(Type.QUERY_COUNT).incrementAndGet();
statistics.getCounter(Type.QUERY_DURATION).addAndGet(timeMs);
sessionContext.getRepositoryContext().getStatManager().getQueryStat().logQuery(language, statement, timeMs);
return result;
}
use of javax.jcr.query.QueryResult in project jackrabbit by apache.
the class QueryObjectModelImpl method execute.
public QueryResult execute() throws RepositoryException {
long time = System.nanoTime();
final QueryResult result = sessionContext.getSessionState().perform(new SessionOperation<QueryResult>() {
public QueryResult perform(SessionContext context) throws RepositoryException {
final QueryEngine engine = new QueryEngine(sessionContext.getSessionImpl(), lqf, variables);
return engine.execute(getColumns(), getSource(), getConstraint(), getOrderings(), offset, limit);
}
public String toString() {
return "query.execute(" + statement + ")";
}
});
time = System.nanoTime() - time;
final long timeMs = time / 1000000;
log.debug("executed in {} ms. ({})", timeMs, statement);
RepositoryStatisticsImpl statistics = sessionContext.getRepositoryContext().getRepositoryStatistics();
statistics.getCounter(Type.QUERY_COUNT).incrementAndGet();
statistics.getCounter(Type.QUERY_DURATION).addAndGet(timeMs);
sessionContext.getRepositoryContext().getStatManager().getQueryStat().logQuery(language, statement, timeMs);
return result;
}
Aggregations