use of jetbrains.buildServer.serverSide.db.DBActionNoResults in project teamcity-rest by JetBrains.
the class ProblemOccurrenceFinder method getProblemOccurrences.
@NotNull
private static ItemHolder<BuildProblem> getProblemOccurrences(@NotNull final Long problemId, @NotNull final ServiceLocator serviceLocator, @NotNull final BuildFinder buildFinder) {
// todo: TeamCity API (VB): how to do this?
final ArrayList<Long> buildIds = new ArrayList<Long>();
try {
// final SQLRunner sqlRunner = myServiceLocator.getSingletonService(SQLRunner.class);
// workaround for http://youtrack.jetbrains.com/issue/TW-25260
final SQLRunnerEx sqlRunner = serviceLocator.getSingletonService(BuildServerEx.class).getSQLRunner();
sqlRunner.withDB(new DBActionNoResults() {
public void run(final DBFunctions dbf) throws DBException {
dbf.queryForTuples(new Object() {
public void getBuildProblem(String build_state_id) throws IOException {
try {
// do nothing within database connection
buildIds.add(Long.valueOf(build_state_id));
} catch (NumberFormatException e) {
LOG.infoAndDebugDetails("Non-number build promotion id " + build_state_id + " retrieved from the database for problemId: " + problemId + ", ignoring.", e);
}
}
}, "getBuildProblem", "select build_state_id from build_problem where problem_id = ? order by build_state_id desc", problemId);
}
});
} catch (Exception e) {
throw new OperationException("Error performing database query: " + e.toString(), e);
}
return new ItemHolder<BuildProblem>() {
@Override
public void process(@NotNull final ItemProcessor<BuildProblem> processor) {
for (Long buildId : buildIds) {
try {
final BuildPromotion buildByPromotionId = buildFinder.getBuildByPromotionId(Long.valueOf(buildId));
if (buildByPromotionId.getBuildType() == null) {
// missing build type, skip. Workaround for http://youtrack.jetbrains.com/issue/TW-34733
} else {
final BuildProblem problem = findProblem(buildByPromotionId, problemId);
if (problem != null) {
processor.processItem(problem);
}
}
} catch (RuntimeException e) {
// addressing TW-41636
LOG.infoAndDebugDetails("Error getting problems for build promotion with id " + buildId + ", problemId: " + problemId + ", ignoring. Cause", e);
}
}
}
};
}
Aggregations