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;
}
}
}
Aggregations