You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ConvertIssueDebtToMinutesMigrationStep.java 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * SonarQube, open source software quality management tool.
  3. * Copyright (C) 2008-2014 SonarSource
  4. * mailto:contact AT sonarsource DOT com
  5. *
  6. * SonarQube is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * SonarQube is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.server.db.migrations.v43;
  21. import java.sql.SQLException;
  22. import java.util.Date;
  23. import org.sonar.api.utils.System2;
  24. import org.sonar.db.Database;
  25. import org.sonar.db.property.PropertiesDao;
  26. import org.sonar.server.db.migrations.BaseDataChange;
  27. import org.sonar.server.db.migrations.MassUpdate;
  28. import org.sonar.server.db.migrations.Select;
  29. import org.sonar.server.db.migrations.SqlStatement;
  30. /**
  31. * Used in the Active Record Migration 513.
  32. * WARNING - this migration is not re-entrant.
  33. *
  34. * @since 4.3
  35. */
  36. public class ConvertIssueDebtToMinutesMigrationStep extends BaseDataChange {
  37. private final WorkDurationConvertor workDurationConvertor;
  38. private final System2 system2;
  39. public ConvertIssueDebtToMinutesMigrationStep(Database database, PropertiesDao propertiesDao, System2 system2) {
  40. super(database);
  41. this.workDurationConvertor = new WorkDurationConvertor(propertiesDao);
  42. this.system2 = system2;
  43. }
  44. @Override
  45. public void execute(Context context) throws SQLException {
  46. workDurationConvertor.init();
  47. final Date now = new Date(system2.now());
  48. MassUpdate massUpdate = context.prepareMassUpdate();
  49. // See https://jira.sonarsource.com/browse/SONAR-5394
  50. // The SQL request should not set the filter on technical_debt is not null. There's no index
  51. // on this column, so filtering is done programmatically.
  52. massUpdate.select("select id, technical_debt from issues");
  53. massUpdate.update("update issues set technical_debt=?, updated_at=? where id=?");
  54. massUpdate.execute(new MassUpdate.Handler() {
  55. @Override
  56. public boolean handle(Select.Row row, SqlStatement update) throws SQLException {
  57. Long debt = row.getNullableLong(2);
  58. if (debt != null) {
  59. Long id = row.getNullableLong(1);
  60. update.setLong(1, workDurationConvertor.createFromLong(debt));
  61. update.setDate(2, now);
  62. update.setLong(3, id);
  63. return true;
  64. }
  65. return false;
  66. }
  67. });
  68. }
  69. }