Search in sources :

Example 1 with QueryResult

use of com.google.gerrit.index.query.QueryResult in project gerrit by GerritCodeReview.

the class QueryChanges method query.

private List<List<ChangeInfo>> query() throws QueryParseException, PermissionBackendException {
    ChangeQueryProcessor queryProcessor = queryProcessorProvider.get();
    if (queryProcessor.isDisabled()) {
        throw new QueryParseException("query disabled");
    }
    if (limit != null) {
        queryProcessor.setUserProvidedLimit(limit);
    }
    if (start != null) {
        queryProcessor.setStart(start);
    }
    if (noLimit != null) {
        queryProcessor.setNoLimit(noLimit);
    }
    if (skipVisibility != null) {
        queryProcessor.enforceVisibility(!skipVisibility);
    }
    dynamicBeans.forEach((p, b) -> queryProcessor.setDynamicBean(p, b));
    if (queries == null || queries.isEmpty()) {
        queries = Collections.singletonList("status:open");
    } else if (queries.size() > 10) {
        // users from submitting too much to the server in a single call.
        throw new QueryParseException("limit of 10 queries");
    }
    int cnt = queries.size();
    List<QueryResult<ChangeData>> results = queryProcessor.query(qb.parse(queries));
    List<List<ChangeInfo>> res = json.create(options, queryProcessor.getInfosFactory()).format(results);
    for (int n = 0; n < cnt; n++) {
        List<ChangeInfo> info = res.get(n);
        if (results.get(n).more() && !info.isEmpty()) {
            Iterables.getLast(info)._moreChanges = true;
        }
    }
    return res;
}
Also used : QueryResult(com.google.gerrit.index.query.QueryResult) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ChangeQueryProcessor(com.google.gerrit.server.query.change.ChangeQueryProcessor) ArrayList(java.util.ArrayList) List(java.util.List) QueryParseException(com.google.gerrit.index.query.QueryParseException)

Aggregations

ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)1 QueryParseException (com.google.gerrit.index.query.QueryParseException)1 QueryResult (com.google.gerrit.index.query.QueryResult)1 ChangeQueryProcessor (com.google.gerrit.server.query.change.ChangeQueryProcessor)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1