Search in sources :

Example 1 with QueryStatsAttribute

use of com.google.gerrit.server.data.QueryStatsAttribute in project gerrit by GerritCodeReview.

the class OutputStreamQuery method query.

public void query(String queryString) throws IOException {
    out = new //
    PrintWriter(new //
    BufferedWriter(new OutputStreamWriter(outputStream, UTF_8)));
    try {
        if (queryProcessor.isDisabled()) {
            ErrorMessage m = new ErrorMessage();
            m.message = "query disabled";
            show(m);
            return;
        }
        try {
            final QueryStatsAttribute stats = new QueryStatsAttribute();
            stats.runTimeMilliseconds = TimeUtil.nowMs();
            Map<Project.NameKey, Repository> repos = new HashMap<>();
            Map<Project.NameKey, RevWalk> revWalks = new HashMap<>();
            QueryResult<ChangeData> results = queryProcessor.query(queryBuilder.parse(queryString));
            try {
                for (ChangeData d : results.entities()) {
                    show(buildChangeAttribute(d, repos, revWalks));
                }
            } finally {
                closeAll(revWalks.values(), repos.values());
            }
            stats.rowCount = results.entities().size();
            stats.moreChanges = results.more();
            stats.runTimeMilliseconds = TimeUtil.nowMs() - stats.runTimeMilliseconds;
            show(stats);
        } catch (OrmException err) {
            log.error("Cannot execute query: " + queryString, err);
            ErrorMessage m = new ErrorMessage();
            m.message = "cannot query database";
            show(m);
        } catch (QueryParseException e) {
            ErrorMessage m = new ErrorMessage();
            m.message = e.getMessage();
            show(m);
        }
    } finally {
        try {
            out.flush();
        } finally {
            out = null;
        }
    }
}
Also used : HashMap(java.util.HashMap) RevWalk(org.eclipse.jgit.revwalk.RevWalk) BufferedWriter(java.io.BufferedWriter) QueryParseException(com.google.gerrit.server.query.QueryParseException) Repository(org.eclipse.jgit.lib.Repository) OrmException(com.google.gwtorm.server.OrmException) QueryStatsAttribute(com.google.gerrit.server.data.QueryStatsAttribute) OutputStreamWriter(java.io.OutputStreamWriter)

Aggregations

QueryStatsAttribute (com.google.gerrit.server.data.QueryStatsAttribute)1 QueryParseException (com.google.gerrit.server.query.QueryParseException)1 OrmException (com.google.gwtorm.server.OrmException)1 BufferedWriter (java.io.BufferedWriter)1 OutputStreamWriter (java.io.OutputStreamWriter)1 HashMap (java.util.HashMap)1 Repository (org.eclipse.jgit.lib.Repository)1 RevWalk (org.eclipse.jgit.revwalk.RevWalk)1