Search in sources :

Example 11 with Row

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;
}
Also used : Constraint(javax.jcr.query.qom.Constraint) ArrayList(java.util.ArrayList) Row(javax.jcr.query.Row) HashSet(java.util.HashSet)

Example 12 with Row

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;
}
Also used : HashMap(java.util.HashMap) Constraint(javax.jcr.query.qom.Constraint) Literal(javax.jcr.query.qom.Literal) Value(javax.jcr.Value) PropertyValue(javax.jcr.query.qom.PropertyValue) ArrayList(java.util.ArrayList) Row(javax.jcr.query.Row)

Example 13 with Row

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;
}
Also used : Constraint(javax.jcr.query.qom.Constraint) ArrayList(java.util.ArrayList) Row(javax.jcr.query.Row) HashSet(java.util.HashSet)

Example 14 with Row

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);
        }
    }
}
Also used : QueryResult(javax.jcr.query.QueryResult) ArrayList(java.util.ArrayList) Row(javax.jcr.query.Row)

Example 15 with Row

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);
    }
}
Also used : ArrayList(java.util.ArrayList) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) ValueFactory(javax.jcr.ValueFactory) RowIterator(javax.jcr.query.RowIterator) Value(javax.jcr.Value) Row(javax.jcr.query.Row)

Aggregations

Row (javax.jcr.query.Row)52 RowIterator (javax.jcr.query.RowIterator)27 QueryResult (javax.jcr.query.QueryResult)21 QueryManager (javax.jcr.query.QueryManager)14 ArrayList (java.util.ArrayList)13 Node (javax.jcr.Node)13 Value (javax.jcr.Value)9 Query (javax.jcr.query.Query)9 Test (org.junit.Test)9 Constraint (javax.jcr.query.qom.Constraint)8 RepositoryException (javax.jcr.RepositoryException)7 Session (javax.jcr.Session)7 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)6 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)6 ValueFactory (javax.jcr.ValueFactory)5 HashSet (java.util.HashSet)4 TreeSet (java.util.TreeSet)4 HashMap (java.util.HashMap)3 NoSuchElementException (java.util.NoSuchElementException)3 NodeIterator (javax.jcr.NodeIterator)2