Search in sources :

Example 1 with DBException

use of jetbrains.buildServer.serverSide.db.DBException 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);
                }
            }
        }
    };
}
Also used : DBException(jetbrains.buildServer.serverSide.db.DBException) DBFunctions(jetbrains.buildServer.serverSide.db.DBFunctions) AggregatingItemHolder(jetbrains.buildServer.server.rest.data.util.AggregatingItemHolder) DBActionNoResults(jetbrains.buildServer.serverSide.db.DBActionNoResults) NotNull(org.jetbrains.annotations.NotNull) SQLRunnerEx(jetbrains.buildServer.serverSide.db.SQLRunnerEx) IOException(java.io.IOException) DBException(jetbrains.buildServer.serverSide.db.DBException) ItemProcessor(jetbrains.buildServer.util.ItemProcessor) BuildProblem(jetbrains.buildServer.serverSide.problems.BuildProblem) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

IOException (java.io.IOException)1 AggregatingItemHolder (jetbrains.buildServer.server.rest.data.util.AggregatingItemHolder)1 DBActionNoResults (jetbrains.buildServer.serverSide.db.DBActionNoResults)1 DBException (jetbrains.buildServer.serverSide.db.DBException)1 DBFunctions (jetbrains.buildServer.serverSide.db.DBFunctions)1 SQLRunnerEx (jetbrains.buildServer.serverSide.db.SQLRunnerEx)1 BuildProblem (jetbrains.buildServer.serverSide.problems.BuildProblem)1 ItemProcessor (jetbrains.buildServer.util.ItemProcessor)1 NotNull (org.jetbrains.annotations.NotNull)1