@Override
  public void execute(final Context context) throws SQLException {
    final Date now = new Date(system.now());

    Connection connection = null;
    PreparedStatement pstmt = null;
    try {
      connection = openConnection();
      pstmt = connection.prepareStatement("SELECT p.uuid as uuid FROM projects p WHERE p.kee=?");

      MassUpdate massUpdate = context.prepareMassUpdate();
      massUpdate.select(
          "SELECT f.id, f.data FROM issue_filters f WHERE f.data like '%componentRoots=%'");
      massUpdate.update("UPDATE issue_filters SET data=?, updated_at=? WHERE id=?");
      final PreparedStatement finalPstmt = pstmt;
      massUpdate.execute(
          new MassUpdate.Handler() {
            @Override
            public boolean handle(Select.Row row, SqlStatement update) throws SQLException {
              Long id = row.getNullableLong(1);
              String data = row.getNullableString(2);
              if (data == null) {
                return false;
              }
              update.setString(1, convertData(finalPstmt, data));
              update.setDate(2, now);
              update.setLong(3, id);
              return true;
            }
          });
    } finally {
      DbUtils.closeQuietly(connection);
      DbUtils.closeQuietly(pstmt);
    }
  }
 @Override
 public void execute(Context context) throws SQLException {
   MassUpdate massUpdate = context.prepareMassUpdate();
   massUpdate.select("select id from project_measures where analysis_uuid is null");
   massUpdate.update("delete from project_measures where id=?");
   massUpdate.rowPluralName("measures");
   massUpdate.execute(
       (row, update) -> {
         update.setLong(1, row.getLong(1));
         return true;
       });
 }
Ejemplo n.º 3
0
  @Override
  public void execute(Context context) throws SQLException {
    RowReader<Long> simpleLongReader =
        new RowReader<Long>() {
          @Override
          public Long read(Row row) throws SQLException {
            Long longValue = row.getNullableLong(1);
            return longValue == null ? Long.valueOf(0L) : longValue;
          }
        };
    Long revisionMetricId =
        context
            .prepareSelect("SELECT id FROM metrics WHERE name = 'revisions_by_line'")
            .get(simpleLongReader);
    Long authorMetricId =
        context
            .prepareSelect("SELECT id FROM metrics WHERE name = 'authors_by_line'")
            .get(simpleLongReader);
    Long datesMetricId =
        context
            .prepareSelect("SELECT id FROM metrics WHERE name = 'last_commit_datetimes_by_line'")
            .get(simpleLongReader);
    Long utCoverageHitsByLineMetricId =
        context
            .prepareSelect("SELECT id FROM metrics WHERE name = 'coverage_line_hits_data'")
            .get(simpleLongReader);
    Long utConditionsByLineMetricId =
        context
            .prepareSelect("SELECT id FROM metrics WHERE name = 'conditions_by_line'")
            .get(simpleLongReader);
    Long utCoveredConditionsByLineMetricId =
        context
            .prepareSelect("SELECT id FROM metrics WHERE name = 'covered_conditions_by_line'")
            .get(simpleLongReader);
    Long itCoverageHitsByLineMetricId =
        context
            .prepareSelect("SELECT id FROM metrics WHERE name = 'it_coverage_line_hits_data'")
            .get(simpleLongReader);
    Long itConditionsByLineMetricId =
        context
            .prepareSelect("SELECT id FROM metrics WHERE name = 'it_conditions_by_line'")
            .get(simpleLongReader);
    Long itCoveredConditionsByLineMetricId =
        context
            .prepareSelect("SELECT id FROM metrics WHERE name = 'it_covered_conditions_by_line'")
            .get(simpleLongReader);
    Long overallCoverageHitsByLineMetricId =
        context
            .prepareSelect("SELECT id FROM metrics WHERE name = 'overall_coverage_line_hits_data'")
            .get(simpleLongReader);
    Long overallConditionsByLineMetricId =
        context
            .prepareSelect("SELECT id FROM metrics WHERE name = 'overall_conditions_by_line'")
            .get(simpleLongReader);
    Long overallCoveredConditionsByLineMetricId =
        context
            .prepareSelect(
                "SELECT id FROM metrics WHERE name = 'overall_covered_conditions_by_line'")
            .get(simpleLongReader);
    Long duplicationDataMetricId =
        context
            .prepareSelect("SELECT id FROM metrics WHERE name = 'duplications_data'")
            .get(simpleLongReader);

    MassUpdate massUpdate = context.prepareMassUpdate();
    massUpdate
        .select(SELECT_FILES_AND_MEASURES_SQL)
        .setBoolean(1, true)
        .setLong(2, zeroIfNull(revisionMetricId))
        .setLong(3, zeroIfNull(authorMetricId))
        .setLong(4, zeroIfNull(datesMetricId))
        .setLong(5, zeroIfNull(utCoverageHitsByLineMetricId))
        .setLong(6, zeroIfNull(utConditionsByLineMetricId))
        .setLong(7, zeroIfNull(utCoveredConditionsByLineMetricId))
        .setLong(8, zeroIfNull(itCoverageHitsByLineMetricId))
        .setLong(9, zeroIfNull(itConditionsByLineMetricId))
        .setLong(10, zeroIfNull(itCoveredConditionsByLineMetricId))
        .setLong(11, zeroIfNull(overallCoverageHitsByLineMetricId))
        .setLong(12, zeroIfNull(overallConditionsByLineMetricId))
        .setLong(13, zeroIfNull(overallCoveredConditionsByLineMetricId))
        .setLong(14, zeroIfNull(duplicationDataMetricId))
        .setBoolean(15, true);

    massUpdate.update(
        "INSERT INTO file_sources"
            + "(project_uuid, file_uuid, created_at, updated_at, data, line_hashes, data_hash)"
            + "VALUES "
            + "(?, ?, ?, ?, ?, ?, ?)");
    massUpdate.rowPluralName("files");

    massUpdate.execute(new FileSourceBuilder(system));
  }