use of javax.jcr.query.QueryResult in project jackrabbit by apache.
the class QueryEngine method buildLeftRowsJoin.
private Set<Row> buildLeftRowsJoin(ConstraintSplitInfo csi, Comparator<Row> comparator, int printIndentation) throws RepositoryException {
if (csi.isMultiple()) {
if (log.isDebugEnabled()) {
log.debug(genString(printIndentation) + "SQL2 JOIN LEFT SIDE there are multiple inner splits.");
}
Set<Row> leftRows = new TreeSet<Row>(comparator);
leftRows.addAll(buildLeftRowsJoin(csi.getLeftInnerConstraints(), comparator, printIndentation + printIndentStep));
leftRows.addAll(buildLeftRowsJoin(csi.getRightInnerConstraints(), comparator, printIndentation + printIndentStep));
return leftRows;
}
Set<Row> leftRows = new TreeSet<Row>(comparator);
QueryResult leftResult = execute(null, csi.getSource().getLeft(), csi.getLeftConstraint(), null, 0, -1, printIndentation);
for (Row row : JcrUtils.getRows(leftResult)) {
leftRows.add(row);
}
return leftRows;
}
use of javax.jcr.query.QueryResult in project jackrabbit by apache.
the class QueryEngine method execute.
protected QueryResult execute(Column[] columns, Selector selector, Constraint constraint, Ordering[] orderings, long offset, long limit, int printIndentation) throws RepositoryException {
long time = System.currentTimeMillis();
Map<String, NodeType> selectorMap = getSelectorNames(selector);
String[] selectorNames = selectorMap.keySet().toArray(new String[selectorMap.size()]);
Map<String, PropertyValue> columnMap = getColumnMap(columns, selectorMap);
String[] columnNames = columnMap.keySet().toArray(new String[columnMap.size()]);
Sort sort = new Sort();
if (NATIVE_SORT) {
sort = new Sort(createSortFields(orderings, session));
}
// if true it means that the LuceneQueryFactory should just let the
// QueryEngine take care of sorting and applying offset and limit
// constraints
boolean externalSort = !NATIVE_SORT;
RowIterator rows = null;
try {
rows = new RowIteratorAdapter(lqf.execute(columnMap, selector, constraint, sort, externalSort, offset, limit));
} catch (IOException e) {
throw new RepositoryException("Failed to access the query index", e);
} finally {
log.debug("{}SQL2 SELECT took {} ms. selector: {}, columns: {}, constraint: {}, offset {}, limit {}", new Object[] { genString(printIndentation), System.currentTimeMillis() - time, selector, Arrays.toString(columnNames), constraint, offset, limit });
}
QueryResult result = new SimpleQueryResult(columnNames, selectorNames, rows);
if (NATIVE_SORT) {
return result;
}
long timeSort = System.currentTimeMillis();
QueryResult sorted = sort(result, orderings, evaluator, offset, limit);
log.debug("{}SQL2 SORT took {} ms.", genString(printIndentation), System.currentTimeMillis() - timeSort);
return sorted;
}
use of javax.jcr.query.QueryResult in project jackrabbit by apache.
the class QueryEngine method buildRightRowsJoin.
/**
* @param csi
* contains 'WHERE' constraints and the source information
* @param rightConstraints
* contains 'ON' constraints
* @param ignoreWhereConstraints
* @param comparator
* used to merge similar rows together
* @param printIndentation
* used in logging
* @return the right-side dataset of the join operation
* @throws RepositoryException
*/
private Set<Row> buildRightRowsJoin(ConstraintSplitInfo csi, List<Constraint> rightConstraints, boolean ignoreWhereConstraints, Comparator<Row> comparator, int printIndentation) throws RepositoryException {
if (csi.isMultiple()) {
if (log.isDebugEnabled()) {
log.debug(genString(printIndentation) + "SQL2 JOIN RIGHT SIDE there are multiple inner splits.");
}
Set<Row> rightRows = new TreeSet<Row>(comparator);
rightRows.addAll(buildRightRowsJoin(csi.getLeftInnerConstraints(), rightConstraints, ignoreWhereConstraints, comparator, printIndentation + printIndentStep));
rightRows.addAll(buildRightRowsJoin(csi.getRightInnerConstraints(), rightConstraints, ignoreWhereConstraints, comparator, printIndentation + printIndentStep));
return rightRows;
}
if (rightConstraints.size() < 500) {
Set<Row> rightRows = new TreeSet<Row>(comparator);
List<Constraint> localRightContraints = rightConstraints;
Constraint rightConstraint = Constraints.and(qomFactory, Constraints.or(qomFactory, localRightContraints), csi.getRightConstraint());
if (ignoreWhereConstraints) {
rightConstraint = Constraints.or(qomFactory, localRightContraints);
}
QueryResult rightResult = execute(null, csi.getSource().getRight(), rightConstraint, null, 0, -1, printIndentation);
for (Row row : JcrUtils.getRows(rightResult)) {
rightRows.add(row);
}
return rightRows;
}
// the 'batch by 500' approach
Set<Row> rightRows = new TreeSet<Row>(comparator);
for (int i = 0; i < rightConstraints.size(); i += 500) {
if (log.isDebugEnabled()) {
log.debug(genString(printIndentation) + "SQL2 JOIN RIGHT SIDE executing batch # " + i + ".");
}
List<Constraint> localRightContraints = rightConstraints.subList(i, Math.min(i + 500, rightConstraints.size()));
Constraint rightConstraint = Constraints.and(qomFactory, Constraints.or(qomFactory, localRightContraints), csi.getRightConstraint());
if (ignoreWhereConstraints) {
rightConstraint = Constraints.or(qomFactory, localRightContraints);
}
QueryResult rightResult = execute(null, csi.getSource().getRight(), rightConstraint, null, 0, -1, printIndentation);
for (Row row : JcrUtils.getRows(rightResult)) {
rightRows.add(row);
}
}
return rightRows;
}
use of javax.jcr.query.QueryResult in project jackrabbit by apache.
the class QueryEngine method execute.
public QueryResult execute(Column[] columns, Source source, Constraint constraint, Ordering[] orderings, long offset, long limit) throws RepositoryException {
long time = System.currentTimeMillis();
QueryResult qr = execute(columns, source, constraint, orderings, offset, limit, 2);
log.debug("SQL2 QUERY execute took {} ms. native sort is {}.", System.currentTimeMillis() - time, NATIVE_SORT);
return qr;
}
use of javax.jcr.query.QueryResult in project jackrabbit by apache.
the class SQL2QueryResultTest method executeAndCheckColumns.
private void executeAndCheckColumns(String sql2, int expected, String... cols) throws RepositoryException {
QueryResult r = executeSQL2Query(sql2);
assertEquals("Got more columns than expected: " + Arrays.toString(r.getColumnNames()), expected, r.getColumnNames().length);
if (expected > 0) {
assertEquals(expected, cols.length);
List<String> expectedCols = new ArrayList<String>(Arrays.asList(cols));
expectedCols.removeAll(new ArrayList<String>(Arrays.asList(r.getColumnNames())));
assertTrue("Got unexpected columns: " + expectedCols, expectedCols.isEmpty());
for (Row row : JcrUtils.getRows(r)) {
assertNotNull(row.getValues());
assertEquals(expected, row.getValues().length);
}
}
}
Aggregations