use of javax.jcr.query.Row in project jackrabbit by apache.
the class DescendantNodeJoinMerger method getRightJoinConstraints.
@Override
public List<Constraint> getRightJoinConstraints(Collection<Row> leftRows) throws RepositoryException {
Set<String> paths = new HashSet<String>();
for (Row row : leftRows) {
paths.addAll(getLeftValues(row));
}
List<Constraint> constraints = new ArrayList<Constraint>();
for (String path : paths) {
if (rightSelectors.contains(descendantSelector)) {
constraints.add(factory.descendantNode(descendantSelector, path));
} else {
constraints.add(factory.sameNode(ancestorSelector, path));
}
}
return constraints;
}
use of javax.jcr.query.Row in project jackrabbit by apache.
the class EquiJoinMerger method getRightJoinConstraints.
@Override
public List<Constraint> getRightJoinConstraints(Collection<Row> leftRows) throws RepositoryException {
Map<String, Literal> literals = new HashMap<String, Literal>();
for (Row leftRow : leftRows) {
for (Value value : evaluator.getValues(leftProperty, leftRow)) {
literals.put(value.getString(), factory.literal(value));
}
}
List<Constraint> constraints = new ArrayList<Constraint>(literals.size());
for (Literal literal : literals.values()) {
constraints.add(factory.comparison(rightProperty, JCR_OPERATOR_EQUAL_TO, literal));
}
return constraints;
}
use of javax.jcr.query.Row in project jackrabbit by apache.
the class SameNodeJoinMerger method getRightJoinConstraints.
@Override
public List<Constraint> getRightJoinConstraints(Collection<Row> leftRows) throws RepositoryException {
Set<String> paths = new HashSet<String>();
for (Row row : leftRows) {
paths.addAll(getLeftValues(row));
}
List<Constraint> constraints = new ArrayList<Constraint>();
for (String path : paths) {
if (rightSelectors.contains(selector1)) {
constraints.add(factory.sameNode(selector1, path));
} else {
constraints.add(factory.sameNode(selector2, path));
}
}
return constraints;
}
use of javax.jcr.query.Row 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);
}
}
}
use of javax.jcr.query.Row in project jackrabbit by apache.
the class SearchResourceImpl method queryResultToMultiStatus.
/**
* Build a <code>MultiStatus</code> object from the specified query result.
*
* @param query the query to execute.
* @return <code>MultiStatus</code> object listing the query result in
* Webdav compatible form.
* @throws RepositoryException if an error occurs.
*/
private void queryResultToMultiStatus(QueryResult result, MultiStatus ms) throws RepositoryException {
List<String> columnNames = new ArrayList<String>();
ValueFactory vf = getRepositorySession().getValueFactory();
List<RowValue> descr = new ArrayList<RowValue>();
for (String columnName : result.getColumnNames()) {
if (!isPathOrScore(columnName)) {
columnNames.add(columnName);
descr.add(new PlainValue(columnName, null, vf));
}
}
// add path and score for each selector
String[] sns = result.getSelectorNames();
boolean join = sns.length > 1;
for (String selectorName : sns) {
descr.add(new PathValue(JcrConstants.JCR_PATH, selectorName, vf));
columnNames.add(JcrConstants.JCR_PATH);
descr.add(new ScoreValue(JcrConstants.JCR_SCORE, selectorName, vf));
columnNames.add(JcrConstants.JCR_SCORE);
}
int n = 0;
String root = getHref("/");
String[] selectorNames = createSelectorNames(descr);
String[] colNames = columnNames.toArray(new String[columnNames.size()]);
RowIterator rowIter = result.getRows();
while (rowIter.hasNext()) {
Row row = rowIter.nextRow();
List<Value> values = new ArrayList<Value>();
for (RowValue rv : descr) {
values.add(rv.getValue(row));
}
// create a new ms-response for this row of the result set
String href;
if (join) {
// We need a distinct href for each join result row to
// allow the MultiStatus response to keep them separate
href = root + "?" + n++;
} else {
href = getHref(row.getPath());
}
MultiStatusResponse resp = new MultiStatusResponse(href, null);
// build the s-r-property
SearchResultProperty srp = new SearchResultProperty(colNames, selectorNames, values.toArray(new Value[values.size()]));
resp.add(srp);
ms.addResponse(resp);
}
}
Aggregations