]> source.dussan.org Git - sonarqube.git/commitdiff
change analysis_reports timestamp columns to bigint/long
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Mon, 12 Jan 2015 17:53:34 +0000 (18:53 +0100)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Tue, 13 Jan 2015 10:47:44 +0000 (11:47 +0100)
41 files changed:
server/sonar-server/src/main/java/org/sonar/server/computation/AnalysisReportLog.java
server/sonar-server/src/main/java/org/sonar/server/computation/AnalysisReportQueue.java
server/sonar-server/src/main/java/org/sonar/server/computation/ComputationService.java
server/sonar-server/src/main/java/org/sonar/server/computation/db/AnalysisReportDao.java
server/sonar-server/src/main/java/org/sonar/server/computation/ws/QueueWsAction.java
server/sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigrations.java
server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedAnalysisReportsLongDates.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/computation/AnalysisReportLogMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/db/AnalysisReportDaoTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/ws/QueueWsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedAnalysisReportsLongDatesTest.java [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/component/db/SnapshotDaoTest/snapshots.xml
server/sonar-server/src/test/resources/org/sonar/server/computation/AnalysisReportServiceTest/report-folder/snapshots.xml
server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/any-analysis-reports.xml
server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/book_available_report_analysis_while_having_one_working_on_another_project.xml
server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/insert-result.xml
server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/one_analysis_report.xml
server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/one_available_analysis.xml
server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/one_available_analysis_but_another_busy_on_same_project.xml
server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/one_busy_report_analysis.xml
server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/pop_null_if_no_pending_reports.xml
server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/pop_oldest_pending.xml
server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/select.xml
server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/select_oldest_available_report_with_working_reports_older.xml
server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/three_analysis_reports.xml
server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/update-all-to-status-pending-result.xml
server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/update-all-to-status-pending.xml
server/sonar-server/src/test/resources/org/sonar/server/computation/step/SwitchSnapshotStepTest/snapshots-result.xml
server/sonar-server/src/test/resources/org/sonar/server/computation/step/SwitchSnapshotStepTest/snapshots.xml
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedAnalysisReportsLongDatesTest/before.xml [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedAnalysisReportsLongDatesTest/schema.sql [new file with mode: 0644]
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/763_add_analysis_reports_long_dates.rb [new file with mode: 0644]
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/764_feed_analysis_reports_long_dates.rb [new file with mode: 0644]
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/765_rename_analysis_reports_long_dates.rb [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportDto.java
sonar-core/src/main/java/org/sonar/core/computation/db/AnalysisReportMapper.java
sonar-core/src/main/java/org/sonar/core/computation/dbcleaner/DefaultPurgeTask.java
sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java
sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql
sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl
sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java

index 65ad9e73e22fa65b7920a0b54e506dac7d1e0404..bf61b9b38df5c40e0a20a8bff0fbea0281cb8919 100644 (file)
 package org.sonar.server.computation;
 
 import com.google.common.collect.ImmutableMap;
-import org.sonar.api.utils.DateUtils;
 import org.sonar.core.activity.ActivityLog;
 import org.sonar.core.component.ComponentDto;
 import org.sonar.core.computation.db.AnalysisReportDto;
 
 import java.util.Map;
 
+import static org.sonar.api.utils.DateUtils.formatDateTimeNullSafe;
+import static org.sonar.api.utils.DateUtils.timeToDate;
+
 public class AnalysisReportLog implements ActivityLog {
 
   private static final String ACTION = "LOG_ANALYSIS_REPORT";
@@ -48,9 +50,9 @@ public class AnalysisReportLog implements ActivityLog {
       .put("projectName", project.name())
       .put("projectUuid", project.uuid())
       .put("status", String.valueOf(report.getStatus()))
-      .put("submittedAt", DateUtils.formatDateTimeNullSafe(report.getCreatedAt()))
-      .put("startedAt", DateUtils.formatDateTimeNullSafe(report.getStartedAt()))
-      .put("finishedAt", DateUtils.formatDateTimeNullSafe(report.getFinishedAt()))
+      .put("submittedAt", formatDateTimeNullSafe(timeToDate(report.getCreatedAt())))
+      .put("startedAt", formatDateTimeNullSafe(timeToDate(report.getStartedAt())))
+      .put("finishedAt", formatDateTimeNullSafe(timeToDate(report.getFinishedAt())))
       .build();
   }
 
index 02dc5d43a878a1da8807489529eb0a5bf3fbd020..3c57b1c5e9158f017dac557204995ec8d75a8f47 100644 (file)
@@ -32,7 +32,6 @@ import org.sonar.server.user.UserSession;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 import java.io.InputStream;
-import java.util.Date;
 import java.util.List;
 
 import static com.google.common.base.Preconditions.checkArgument;
@@ -89,7 +88,7 @@ public class AnalysisReportQueue implements ServerComponent {
 
     DbSession session = dbClient.openSession(false);
     try {
-      report.setFinishedAt(new Date(system2.now()));
+      report.setFinishedAt(system2.now());
       dbClient.analysisReportDao().delete(session, report.getId());
       session.commit();
     } finally {
index 6b2e98efb41c55a0bb7cf02739eb8d369c91265e..598625b81177be326d179083c4825ade00684055 100644 (file)
@@ -99,7 +99,7 @@ public class ComputationService implements ServerComponent {
   }
 
   private void logActivity(DbSession session, AnalysisReportDto report, ComponentDto project) {
-    report.setFinishedAt(System2.INSTANCE.newDate());
+    report.setFinishedAt(System2.INSTANCE.now());
     activityService.write(session, Activity.Type.ANALYSIS_REPORT, new AnalysisReportLog(report, project));
   }
 }
index 42c00ffc326e11f1b4dc9b89e5204e4c2e9341ed..d1778622f6046015769cf6c1c8b71b4442b70d48 100644 (file)
@@ -37,12 +37,7 @@ import javax.annotation.Nullable;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Timestamp;
-import java.util.Date;
+import java.sql.*;
 import java.util.List;
 
 import static org.sonar.core.computation.db.AnalysisReportDto.Status.PENDING;
@@ -65,7 +60,7 @@ public class AnalysisReportDao implements DaoComponent {
    * Update all rows with: STATUS='PENDING', STARTED_AT=NULL, UPDATED_AT={now}
    */
   public void resetAllToPendingStatus(DbSession session) {
-    mapper(session).resetAllToPendingStatus(system2.newDate());
+    mapper(session).resetAllToPendingStatus(system2.now());
   }
 
   public void truncate(DbSession session) {
@@ -95,7 +90,7 @@ public class AnalysisReportDao implements DaoComponent {
   @VisibleForTesting
   AnalysisReportDto tryToPop(DbSession session, long reportId) {
     AnalysisReportMapper mapper = mapper(session);
-    int nbOfReportBooked = mapper.updateWithBookingReport(reportId, system2.newDate(), PENDING, WORKING);
+    int nbOfReportBooked = mapper.updateWithBookingReport(reportId, system2.now(), PENDING, WORKING);
     if (nbOfReportBooked == 0) {
       return null;
     }
@@ -110,8 +105,8 @@ public class AnalysisReportDao implements DaoComponent {
   }
 
   public AnalysisReportDto insert(DbSession session, AnalysisReportDto report) {
-    report.setCreatedAt(system2.newDate());
-    report.setUpdatedAt(system2.newDate());
+    report.setCreatedAt(system2.now());
+    report.setUpdatedAt(system2.now());
 
     Connection connection = session.getConnection();
     PreparedStatement ps = null;
@@ -124,10 +119,10 @@ public class AnalysisReportDao implements DaoComponent {
       ps.setLong(2, report.getSnapshotId());
       ps.setString(3, report.getStatus().toString());
       setData(ps, 4, report.getData());
-      ps.setTimestamp(5, dateToTimestamp(report.getCreatedAt()));
-      ps.setTimestamp(6, dateToTimestamp(report.getUpdatedAt()));
-      ps.setTimestamp(7, dateToTimestamp(report.getStartedAt()));
-      ps.setTimestamp(8, dateToTimestamp(report.getFinishedAt()));
+      ps.setLong(5, report.getCreatedAt());
+      setLong(ps, 6, report.getUpdatedAt());
+      setLong(ps, 7, report.getStartedAt());
+      setLong(ps, 8, report.getFinishedAt());
 
       ps.executeUpdate();
       connection.commit();
@@ -140,6 +135,14 @@ public class AnalysisReportDao implements DaoComponent {
     return report;
   }
 
+  private void setLong(PreparedStatement ps, int index, @Nullable Long time) throws SQLException {
+    if (time == null) {
+      ps.setNull(index, Types.BIGINT);
+    } else {
+      ps.setLong(index, time);
+    }
+  }
+
   private void setData(PreparedStatement ps, int parameterIndex, @Nullable InputStream reportDataStream) throws IOException, SQLException {
     if (reportDataStream == null) {
       ps.setBytes(parameterIndex, null);
@@ -176,13 +179,6 @@ public class AnalysisReportDao implements DaoComponent {
     }
   }
 
-  private Timestamp dateToTimestamp(@Nullable Date date) {
-    if (date == null) {
-      return null;
-    }
-    return new Timestamp(date.getTime());
-  }
-
   public void delete(DbSession session, long id) {
     mapper(session).delete(id);
   }
index 0d7681a55f3ddd3b551ed249013d9a2401c78e1e..29175569e69174fed0c404e8fa8e33997deba9a2 100644 (file)
@@ -30,6 +30,8 @@ import org.sonar.server.computation.AnalysisReportQueue;
 
 import java.util.List;
 
+import static org.sonar.api.utils.DateUtils.timeToDate;
+
 /**
  * @since 5.0
  */
@@ -67,9 +69,9 @@ public class QueueWsAction implements ComputationWsAction, RequestHandler {
       json.prop("key", report.getId());
       json.prop("projectKey", report.getProjectKey());
       json.prop("projectName", report.getProjectKey());
-      json.propDateTime("startedAt", report.getStartedAt());
-      json.propDateTime("finishedAt", report.getFinishedAt());
-      json.propDateTime("submittedAt", report.getCreatedAt());
+      json.propDateTime("startedAt", timeToDate(report.getStartedAt()));
+      json.propDateTime("finishedAt", timeToDate(report.getFinishedAt()));
+      json.propDateTime("submittedAt", timeToDate(report.getCreatedAt()));
       json.prop("status", report.getStatus().toString());
       json.endObject();
     }
index c825fe86383460cc1583644bdf9b0b4d55bf42e0..4fd0f755497b93e9fe9ee355d40a60008de4d8e2 100644 (file)
@@ -81,6 +81,7 @@ public interface DatabaseMigrations {
     FeedUsersLongDates.class,
     RenameComponentRelatedParamsInIssueFilters.class,
     CopyScmAccountsFromAuthorsToUsers.class,
-    FeedIssueChangesLongDates.class
+    FeedIssueChangesLongDates.class,
+    FeedAnalysisReportsLongDates.class
     );
 }
diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedAnalysisReportsLongDates.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedAnalysisReportsLongDates.java
new file mode 100644 (file)
index 0000000..7f2fc39
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+package org.sonar.server.db.migrations.v51;
+
+import org.sonar.api.utils.System2;
+import org.sonar.core.persistence.Database;
+import org.sonar.server.db.migrations.BaseDataChange;
+import org.sonar.server.db.migrations.MassUpdate;
+import org.sonar.server.db.migrations.Select;
+import org.sonar.server.db.migrations.SqlStatement;
+
+import java.sql.SQLException;
+import java.util.Date;
+
+public class FeedAnalysisReportsLongDates extends BaseDataChange {
+
+  private final System2 system;
+
+  public FeedAnalysisReportsLongDates(Database db, System2 system) {
+    super(db);
+    this.system = system;
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    final long now = system.now();
+
+    MassUpdate massUpdate = context.prepareMassUpdate();
+    massUpdate.select("SELECT a.created_at, a.updated_at, a.started_at, a.finished_at, a.id FROM analysis_reports a WHERE created_at_ms IS NULL");
+    massUpdate.update("UPDATE analysis_reports SET created_at_ms=?, updated_at_ms=?, started_at_ms=?, finished_at_ms=? WHERE id=?");
+    massUpdate.rowPluralName("analysis_reports");
+    massUpdate.execute(new MassUpdate.Handler() {
+      @Override
+      public boolean handle(Select.Row row, SqlStatement update) throws SQLException {
+        Date createdAt = row.getDate(1);
+        Date updatedAt = row.getDate(2);
+        Date startedAt = row.getDate(3);
+        Date finishedAt = row.getDate(4);
+        Long id = row.getLong(5);
+
+        updateColumn(update, 1, createdAt);
+        updateColumn(update, 2, updatedAt);
+        update.setLong(3, startedAt == null ? null : startedAt.getTime());
+        update.setLong(4, finishedAt == null ? null : finishedAt.getTime());
+        update.setLong(5, id);
+        return true;
+      }
+
+      private void updateColumn(SqlStatement update, int position, Date time) throws SQLException {
+        if (time == null) {
+          update.setLong(position, now);
+        } else {
+          update.setLong(position, Math.min(now, time.getTime()));
+        }
+      }
+    });
+  }
+
+}
index 200aa32f00efc8a1eef91961ff3b1cd8476ae131..986a364c59c67751c46cad194aea55b615f18116 100644 (file)
@@ -68,10 +68,10 @@ public class AnalysisReportLogMediumTest {
     AnalysisReportDto report = AnalysisReportDto.newForTests(1L)
       .setProjectKey("projectKey")
       .setStatus(FAILED)
-      .setCreatedAt(DateUtils.parseDate("2014-10-15"))
-      .setUpdatedAt(DateUtils.parseDate("2014-10-16"))
-      .setStartedAt(DateUtils.parseDate("2014-10-17"))
-      .setFinishedAt(DateUtils.parseDate("2014-10-18"));
+      .setCreatedAt(DateUtils.parseDate("2014-10-15").getTime())
+      .setUpdatedAt(DateUtils.parseDate("2014-10-16").getTime())
+      .setStartedAt(DateUtils.parseDate("2014-10-17").getTime())
+      .setFinishedAt(DateUtils.parseDate("2014-10-18").getTime());
     ComponentDto project = ComponentTesting.newProjectDto();
 
     service.write(dbSession, ANALYSIS_REPORT, new AnalysisReportLog(report, project));
index 436bfdb8c4498cb4fe5d7b40cf069cf688520f22..9cab6044c2a0f1b313f1c97be93591d411090c59 100644 (file)
@@ -27,7 +27,6 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 import org.junit.rules.TemporaryFolder;
-import org.sonar.api.utils.DateUtils;
 import org.sonar.api.utils.System2;
 import org.sonar.core.computation.db.AnalysisReportDto;
 import org.sonar.core.persistence.DbSession;
@@ -42,6 +41,7 @@ import java.util.List;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
+import static org.sonar.api.utils.DateUtils.parseDate;
 import static org.sonar.core.computation.db.AnalysisReportDto.Status.PENDING;
 import static org.sonar.core.computation.db.AnalysisReportDto.Status.WORKING;
 
@@ -67,8 +67,8 @@ public class AnalysisReportDaoTest {
     this.system2 = mock(System2.class);
     this.sut = new AnalysisReportDao(system2);
 
-    when(system2.now()).thenReturn(DateUtils.parseDate("2014-09-26").getTime());
-    when(system2.newDate()).thenReturn(DateUtils.parseDate("2014-09-26"));
+    when(system2.now()).thenReturn(parseDate("2014-09-26").getTime());
+    when(system2.newDate()).thenReturn(parseDate("2014-09-26"));
   }
 
   @After
@@ -168,10 +168,10 @@ public class AnalysisReportDaoTest {
     AnalysisReportDto report = sut.selectById(session, 1L);
 
     assertThat(report.getProjectKey()).isEqualTo(DEFAULT_PROJECT_KEY);
-    assertThat(report.getCreatedAt()).isEqualTo(DateUtils.parseDate("2014-09-24"));
-    assertThat(report.getUpdatedAt()).isEqualTo(DateUtils.parseDate("2014-09-25"));
-    assertThat(report.getStartedAt()).isEqualTo(DateUtils.parseDate("2014-09-26"));
-    assertThat(report.getFinishedAt()).isEqualTo(DateUtils.parseDate("2014-09-27"));
+    assertThat(report.getCreatedAt()).isEqualTo(parseDate("2014-09-24").getTime());
+    assertThat(report.getUpdatedAt()).isEqualTo(parseDate("2014-09-25").getTime());
+    assertThat(report.getStartedAt()).isEqualTo(parseDate("2014-09-26").getTime());
+    assertThat(report.getFinishedAt()).isEqualTo(parseDate("2014-09-27").getTime());
     assertThat(report.getStatus()).isEqualTo(WORKING);
     assertThat(report.getData()).isNull();
     assertThat(report.getKey()).isEqualTo("1");
index 3618bcefda6e0597030417c3102b4bd2d78bd80f..f3821946deb671d2e3f9236f5a4501918160f8c8 100644 (file)
@@ -53,9 +53,9 @@ public class QueueWsActionTest {
       .setProjectKey("project-key")
       .setStatus(PENDING)
       .setData(null)
-      .setCreatedAt(DateUtils.parseDateTime("2014-10-13T00:00:00+0200"))
-      .setStartedAt(DateUtils.parseDateTime("2014-10-13T00:00:00+0200"))
-      .setFinishedAt(DateUtils.parseDateTime("2014-10-13T00:00:00+0200"));
+      .setCreatedAt(DateUtils.parseDateTime("2014-10-13T00:00:00+0200").getTime())
+      .setStartedAt(DateUtils.parseDateTime("2014-10-13T00:00:00+0200").getTime())
+      .setFinishedAt(DateUtils.parseDateTime("2014-10-13T00:00:00+0200").getTime());
     List<AnalysisReportDto> reports = Lists.newArrayList(report);
     when(queue.all()).thenReturn(reports);
 
diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedAnalysisReportsLongDatesTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedAnalysisReportsLongDatesTest.java
new file mode 100644 (file)
index 0000000..2086736
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+package org.sonar.server.db.migrations.v51;
+
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.sonar.api.utils.System2;
+import org.sonar.core.persistence.DbTester;
+import org.sonar.server.db.migrations.DatabaseMigration;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class FeedAnalysisReportsLongDatesTest {
+  @ClassRule
+  public static DbTester db = new DbTester().schema(FeedAnalysisReportsLongDatesTest.class, "schema.sql");
+
+  @Test
+  public void execute() throws Exception {
+    db.prepareDbUnit(getClass(), "before.xml");
+
+    System2 system = mock(System2.class);
+    when(system.now()).thenReturn(1500000000000L);
+    DatabaseMigration migration = new FeedAnalysisReportsLongDates(db.database(), system);
+    migration.execute();
+
+    int count = db.countSql("select count(*) from analysis_reports where created_at_ms is not null and updated_at_ms is not null");
+    assertThat(count).isEqualTo(3);
+
+    int countWithAllDateFieldsNull = db
+      .countSql("select count(*) from analysis_reports where created_at_ms is not null and updated_at_ms is not null and started_at_ms is not null and finished_at_ms is not null");
+    assertThat(countWithAllDateFieldsNull).isEqualTo(2);
+  }
+}
index 9781e1280fcc29c9aae56541f554183eb90e57d1..7cfc057296de49393cea7c49e08944b4f20d94ef 100644 (file)
@@ -41,7 +41,7 @@
              depth="1" scope="DIR" qualifier="PAC" created_at="2008-12-02" build_date="2011-09-29"
              version="2.1-SNAPSHOT" path="1.2."/>
 
-  <!-- PROJECT_ID = 3  no last snapshot -->
+  <!-- PROJECT_ID = 3 - no last snapshot -->
   <snapshots id="5" project_id="3" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="3"
              status="P" islast="[false]" purge_status="1"
              period1_mode="days1" period1_param="30" period1_date="2011-09-24"
index 642ac79c0261a3edc2ec885d615f4c7b88ad656c..965eb1081aaff96f14fc704473916dd00edf1c03 100644 (file)
@@ -28,7 +28,7 @@
              period5_mode="days5" period5_param="34" period5_date="2011-09-28"
              depth="1" scope="DIR" qualifier="PAC" created_at="2008-12-03" build_date="2011-09-29"
              version="2.1-SNAPSHOT" path="1.2."/>
-  <!-- PROJECT_ID = 3  no last snapshot -->
+  <!-- PROJECT_ID = 3 - no last snapshot -->
   <snapshots id="4" project_id="3" parent_snapshot_id="2" root_project_id="123" root_snapshot_id="1"
              status="U" islast="[false]" purge_status="1"
              period1_mode="days1" period1_param="30" period1_date="2011-09-24"
@@ -77,7 +77,7 @@
              period5_mode="days5" period5_param="34" period5_date="2011-09-28"
              depth="1" scope="DIR" qualifier="PAC" created_at="2008-12-02" build_date="2011-09-29"
              version="2.1-SNAPSHOT" path="1.2."/>
-  <!-- PROJECT_ID = 3  no last snapshot -->
+  <!-- PROJECT_ID = 3 - no last snapshot -->
   <snapshots id="24" project_id="3" parent_snapshot_id="2" root_project_id="123" root_snapshot_id="21"
              status="P" islast="[true]" purge_status="1"
              period1_mode="days1" period1_param="30" period1_date="2011-09-24"
              period5_mode="days5" period5_param="34" period5_date="2011-09-28"
              depth="1" scope="DIR" qualifier="PAC" created_at="2008-12-01" build_date="2011-09-29"
              version="2.1-SNAPSHOT" path="1.2."/>
-  <!-- PROJECT_ID = 3  no last snapshot -->
+  <!-- PROJECT_ID = 3 - no last snapshot -->
   <snapshots id="49" project_id="3" parent_snapshot_id="2" root_project_id="123" root_snapshot_id="46"
              status="P" islast="[false]" purge_status="1"
              period1_mode="days1" period1_param="30" period1_date="2011-09-24"
index 235bdc82bf4b905d71525584c173d7549cd797d4..b72284f5d10a1f31037d4f27b8fe8750f1f3183b 100644 (file)
@@ -5,8 +5,8 @@
       snapshot_id="123"
       report_data="data-project"
       report_status="WORKING"
-      created_at="2014-09-24"
-      updated_at="2014-09-24"
+      created_at="1411509600000"
+      updated_at="1411509600000"
       />
   <analysis_reports
       id="2"
@@ -14,8 +14,8 @@
       snapshot_id="123"
       report_data="data-project"
       report_status="WORKING"
-      created_at="2014-09-25"
-      updated_at="2014-09-25"
+      created_at="1411596000000"
+      updated_at="1411596000000"
       />
   <analysis_reports
       id="3"
@@ -23,7 +23,7 @@
       snapshot_id="123"
       report_data="data-project"
       report_status="PENDING"
-      created_at="2014-09-26"
-      updated_at="2014-09-26"
+      created_at="1411682400000"
+      updated_at="1411682400000"
       />
 </dataset>
\ No newline at end of file
index 0ea21d7befe4ea2d1a832eefdcacd511dfedd1cd..26126affff8a81db08d7cca1fb735921f6e619f8 100644 (file)
@@ -5,8 +5,8 @@
       snapshot_id="123"
       report_data="data-project"
       report_status="PENDING"
-      created_at="2014-09-24"
-      updated_at="2014-09-25"
+      created_at="1411509600000"
+      updated_at="1411596000000"
       />
   <analysis_reports
       id="2"
@@ -14,7 +14,7 @@
       snapshot_id="123"
       report_data="data-project"
       report_status="WORKING"
-      created_at="2014-09-23"
-      updated_at="2014-09-26"
+      created_at="1411423200000"
+      updated_at="1411682400000"
       />
 </dataset>
\ No newline at end of file
index 9af285cc1f727fa1ad5f905dd53479aeb9d9fb5f..a3043ec3238470ee07e197ee5b35909963dd9854 100644 (file)
@@ -8,8 +8,8 @@
       report_status="PENDING"
       started_at="[null]"
       finished_at="[null]"
-      created_at="2014-09-26 00:00:00.0"
-      updated_at="2014-09-26 00:00:00.0"
+      created_at="1411682400000"
+      updated_at="1411682400000"
       />
   <analysis_reports
       id="2"
@@ -20,7 +20,7 @@
       report_status="PENDING"
       started_at="[null]"
       finished_at="[null]"
-      created_at="2014-09-26 00:00:00.0"
-      updated_at="2014-09-26 00:00:00.0"
+      created_at="1411682400000"
+      updated_at="1411682400000"
       />
 </dataset>
index d0288e72615b58ee6d3e0b002a926938c63195bf..ca3013e2f84f7c8e526a7af389c78c003ae4bb05 100644 (file)
@@ -5,9 +5,9 @@
       snapshot_id="123"
       report_data="data-project"
       report_status="WORKING"
-      created_at="2014-09-24"
-      updated_at="2014-09-25"
-      started_at="2014-09-26"
-      finished_at="2014-09-27"
+      created_at="1411509600000"
+      updated_at="1411596000000"
+      started_at="1411682400000"
+      finished_at="1411768800000"
       />
 </dataset>
\ No newline at end of file
index 93d6b5a633170cd8795db2f25dfe8ef74c95c848..b26ec14839a77ef6442b429998660c7f6fd4c70e 100644 (file)
@@ -5,8 +5,8 @@
       snapshot_id="123"
       report_data="data-project"
       report_status="PENDING"
-      created_at="2014-09-24"
-      updated_at="2014-09-25"
+      created_at="1411509600000"
+      updated_at="1411596000000"
       />
   <analysis_reports
       id="2"
@@ -14,7 +14,7 @@
       snapshot_id="123"
       report_data="data-project"
       report_status="PENDING"
-      created_at="2014-09-24"
-      updated_at="2014-09-25"
+      created_at="1411509600000"
+      updated_at="1411596000000"
       />
 </dataset>
index 5dd3839051eb1bf68311f469e3440be5b46add7a..f48e5e111b1d5879e4e4094a0b6f1141d7d44038 100644 (file)
@@ -5,8 +5,8 @@
       snapshot_id="123"
       report_data="data-project"
       report_status="PENDING"
-      created_at="2014-09-24"
-      updated_at="2014-09-25"
+      created_at="1411509600000"
+      updated_at="1411596000000"
       />
   <analysis_reports
       id="2"
@@ -14,7 +14,7 @@
       snapshot_id="123"
       report_data="data-project"
       report_status="WORKING"
-      created_at="2014-09-23"
-      updated_at="2014-09-26"
+      created_at="1411423200000"
+      updated_at="1411682400000"
       />
 </dataset>
\ No newline at end of file
index 574cd7317f77e037b7c491355ea4bb545ae71078..f853e443a39d0e96236ffde55597d3fd8416a9a3 100644 (file)
@@ -5,7 +5,7 @@
       snapshot_id="123"
       report_data="data-project"
       report_status="WORKING"
-      created_at="2014-09-24"
-      updated_at="2014-09-25"
+      created_at="1411509600000"
+      updated_at="1411596000000"
       />
 </dataset>
index a0d357a7dbd0d99bfc69a6cfc3a2040234c9f680..21eb7f1fb43f3de30868c310148039c1ec4d512d 100644 (file)
@@ -5,8 +5,8 @@
       snapshot_id="123"
       report_data="data-project"
       report_status="WORKING"
-      created_at="2014-09-25"
-      updated_at="2014-09-26"
+      created_at="1411596000000"
+      updated_at="1411682400000"
       />
   <analysis_reports
       id="2"
@@ -14,8 +14,8 @@
       snapshot_id="123"
       report_data="data-project"
       report_status="WORKING"
-      created_at="2014-09-24"
-      updated_at="2014-09-26"
+      created_at="1411509600000"
+      updated_at="1411682400000"
       />
   <!-- not select as the previous report which is working is on the same project -->
   <analysis_reports
@@ -24,7 +24,7 @@
       snapshot_id="123"
       report_data="data-project"
       report_status="PENDING"
-      created_at="2014-09-25"
-      updated_at="2014-09-26"
+      created_at="1411596000000"
+      updated_at="1411682400000"
       />
 </dataset>
\ No newline at end of file
index 95f9b47934c2bb03e3028dadda1170f73dd2fce0..cae6dec371cc5a35540996db4116452ce19dcc7c 100644 (file)
@@ -6,8 +6,8 @@
     snapshot_id="1"
     report_data="data-project"
     report_status="WORKING"
-    created_at="2014-09-25"
-    updated_at="2014-09-26"
+    created_at="1411596000000"
+    updated_at="1411682400000"
     />
 
   <!-- PENDING on P1, which is already being WORKING-->
@@ -17,8 +17,8 @@
     snapshot_id="2"
     report_data="data-project"
     report_status="PENDING"
-    created_at="2014-09-24"
-    updated_at="2014-09-26"
+    created_at="1411509600000"
+    updated_at="1411682400000"
     />
   <analysis_reports
     id="3"
@@ -26,8 +26,8 @@
     snapshot_id="3"
     report_data="data-project"
     report_status="PENDING"
-    created_at="2014-09-25"
-    updated_at="2014-09-26"
+    created_at="1411596000000"
+    updated_at="1411682400000"
     />
   <analysis_reports
     id="4"
@@ -35,7 +35,7 @@
     snapshot_id="4"
     report_data="data-project"
     report_status="PENDING"
-    created_at="2015-01-01"
-    updated_at="2015-01-01"
+    created_at="1420066800000"
+    updated_at="1420066800000"
     />
 </dataset>
index 3a24ab33e3771fea3c7a8c3ccd6212e7cda794fc..8fff6461280729eff9ccf04507d6062702c40926 100644 (file)
@@ -5,8 +5,8 @@
       snapshot_id="123"
       report_data="data-project"
       report_status="WORKING"
-      created_at="2014-09-24"
-      updated_at="2014-09-25"
+      created_at="1411509600000"
+      updated_at="1411596000000"
       />
   <analysis_reports
       id="2"
@@ -14,8 +14,8 @@
       snapshot_id="123"
       report_data="data-project"
       report_status="WORKING"
-      created_at="2014-09-25"
-      updated_at="2014-09-25"
+      created_at="1411596000000"
+      updated_at="1411596000000"
       />
   <analysis_reports
       id="3"
@@ -23,7 +23,7 @@
       snapshot_id="123"
       report_data="data-project"
       report_status="PENDING"
-      created_at="2014-09-26"
-      updated_at="2014-09-26"
+      created_at="1411682400000"
+      updated_at="1411682400000"
       />
 </dataset>
\ No newline at end of file
index 94ff919df315f66745f077b5bb79baa56e349eb4..282458ef695485f81e4f89e797e700ebd8fbd284 100644 (file)
@@ -5,8 +5,8 @@
       snapshot_id="123"
       report_data="data-project"
       report_status="WORKING"
-      created_at="2014-09-23"
-      updated_at="2014-09-26"
+      created_at="1411423200000"
+      updated_at="1411682400000"
       />
   <analysis_reports
       id="2"
@@ -14,8 +14,8 @@
       snapshot_id="123"
       report_data="data-project"
       report_status="PENDING"
-      created_at="2014-09-24"
-      updated_at="2014-09-26"
+      created_at="1411509600000"
+      updated_at="1411682400000"
       />
   <analysis_reports
       id="3"
@@ -23,7 +23,7 @@
       snapshot_id="123"
       report_data="data-project"
       report_status="WORKING"
-      created_at="2014-09-25"
-      updated_at="2014-09-26"
+      created_at="1411596000000"
+      updated_at="1411682400000"
       />
 </dataset>
\ No newline at end of file
index 3a24ab33e3771fea3c7a8c3ccd6212e7cda794fc..8fff6461280729eff9ccf04507d6062702c40926 100644 (file)
@@ -5,8 +5,8 @@
       snapshot_id="123"
       report_data="data-project"
       report_status="WORKING"
-      created_at="2014-09-24"
-      updated_at="2014-09-25"
+      created_at="1411509600000"
+      updated_at="1411596000000"
       />
   <analysis_reports
       id="2"
@@ -14,8 +14,8 @@
       snapshot_id="123"
       report_data="data-project"
       report_status="WORKING"
-      created_at="2014-09-25"
-      updated_at="2014-09-25"
+      created_at="1411596000000"
+      updated_at="1411596000000"
       />
   <analysis_reports
       id="3"
@@ -23,7 +23,7 @@
       snapshot_id="123"
       report_data="data-project"
       report_status="PENDING"
-      created_at="2014-09-26"
-      updated_at="2014-09-26"
+      created_at="1411682400000"
+      updated_at="1411682400000"
       />
 </dataset>
\ No newline at end of file
index 9ec0b642bc755651881383be346830858b45aef5..a57c6282dd13d24cb92fb2af8d365aa84f0f6294 100644 (file)
@@ -7,8 +7,8 @@
       snapshot_id="1"
       report_data="data-project"
       report_status="PENDING"
-      created_at="2014-09-24"
-      updated_at="2014-09-26 00:00:00.0"
+      created_at="1411509600000"
+      updated_at="1411682400000"
       started_at="[null]"
       finished_at="[null]"
       />
@@ -19,8 +19,8 @@
       snapshot_id="123"
       report_data="data-project"
       report_status="PENDING"
-      created_at="2014-09-25"
-      updated_at="2014-09-26 00:00:00.0"
+      created_at="1411596000000"
+      updated_at="1411682400000"
       started_at="[null]"
       finished_at="[null]"
       />
@@ -31,8 +31,8 @@
       snapshot_id="123"
       report_data="data-project"
       report_status="PENDING"
-      created_at="2014-09-26"
-      updated_at="2014-09-26 00:00:00.0"
+      created_at="1411682400000"
+      updated_at="1411682400000"
       started_at="[null]"
       finished_at="[null]"
       />
index 1274dcf2508c3841391280600b3d3d927a2611c4..50edcc5da9762d9131f9409de0146c5f84dee6bf 100644 (file)
@@ -6,9 +6,9 @@
       snapshot_id="1"
       report_data="data-project"
       report_status="WORKING"
-      created_at="2014-09-24"
-      updated_at="2014-09-24"
-      started_at="2014-09-24"
+      created_at="1411509600000"
+      updated_at="1411509600000"
+      started_at="1411509600000"
       finished_at="[null]"
       />
   <analysis_reports
@@ -18,9 +18,9 @@
       snapshot_id="123"
       report_data="data-project"
       report_status="WORKING"
-      created_at="2014-09-25"
-      updated_at="2014-09-25"
-      started_at="2014-09-24"
+      created_at="1411596000000"
+      updated_at="1411596000000"
+      started_at="1411509600000"
       finished_at="[null]"
       />
   <analysis_reports
@@ -30,8 +30,8 @@
       snapshot_id="123"
       report_data="data-project"
       report_status="PENDING"
-      created_at="2014-09-26"
-      updated_at="2014-09-26"
+      created_at="1411682400000"
+      updated_at="1411682400000"
       started_at="[null]"
       finished_at="[null]"
       />
index c4b90750ee0072c3f0e918a961ec37c43793c77b..86714d163a052c3bb259c0e4505a59e1ac10ed9c 100644 (file)
@@ -28,7 +28,7 @@
              period5_mode="days5" period5_param="34" period5_date="2011-09-28"
              depth="1" scope="DIR" qualifier="PAC" created_at="2008-12-03" build_date="2011-09-29"
              version="2.1-SNAPSHOT" path="1.2."/>
-  <!-- PROJECT_ID = 3  no last snapshot -->
+  <!-- PROJECT_ID = 3 - no last snapshot -->
   <snapshots id="4" project_id="3" parent_snapshot_id="2" root_project_id="123" root_snapshot_id="1"
              status="P" islast="[true]" purge_status="1"
              period1_mode="days1" period1_param="30" period1_date="2011-09-24"
@@ -77,7 +77,7 @@
              period5_mode="days5" period5_param="34" period5_date="2011-09-28"
              depth="1" scope="DIR" qualifier="PAC" created_at="2008-12-02" build_date="2011-09-29"
              version="2.1-SNAPSHOT" path="1.2."/>
-  <!-- PROJECT_ID = 3  no last snapshot -->
+  <!-- PROJECT_ID = 3 - no last snapshot -->
   <snapshots id="24" project_id="3" parent_snapshot_id="2" root_project_id="123" root_snapshot_id="21"
              status="P" islast="[false]" purge_status="1"
              period1_mode="days1" period1_param="30" period1_date="2011-09-24"
              period5_mode="days5" period5_param="34" period5_date="2011-09-28"
              depth="1" scope="DIR" qualifier="PAC" created_at="2008-12-01" build_date="2011-09-29"
              version="2.1-SNAPSHOT" path="1.2."/>
-  <!-- PROJECT_ID = 3  no last snapshot -->
+  <!-- PROJECT_ID = 3 - no last snapshot -->
   <snapshots id="49" project_id="3" parent_snapshot_id="2" root_project_id="123" root_snapshot_id="46"
              status="P" islast="[false]" purge_status="1"
              period1_mode="days1" period1_param="30" period1_date="2011-09-24"
index 642ac79c0261a3edc2ec885d615f4c7b88ad656c..965eb1081aaff96f14fc704473916dd00edf1c03 100644 (file)
@@ -28,7 +28,7 @@
              period5_mode="days5" period5_param="34" period5_date="2011-09-28"
              depth="1" scope="DIR" qualifier="PAC" created_at="2008-12-03" build_date="2011-09-29"
              version="2.1-SNAPSHOT" path="1.2."/>
-  <!-- PROJECT_ID = 3  no last snapshot -->
+  <!-- PROJECT_ID = 3 - no last snapshot -->
   <snapshots id="4" project_id="3" parent_snapshot_id="2" root_project_id="123" root_snapshot_id="1"
              status="U" islast="[false]" purge_status="1"
              period1_mode="days1" period1_param="30" period1_date="2011-09-24"
@@ -77,7 +77,7 @@
              period5_mode="days5" period5_param="34" period5_date="2011-09-28"
              depth="1" scope="DIR" qualifier="PAC" created_at="2008-12-02" build_date="2011-09-29"
              version="2.1-SNAPSHOT" path="1.2."/>
-  <!-- PROJECT_ID = 3  no last snapshot -->
+  <!-- PROJECT_ID = 3 - no last snapshot -->
   <snapshots id="24" project_id="3" parent_snapshot_id="2" root_project_id="123" root_snapshot_id="21"
              status="P" islast="[true]" purge_status="1"
              period1_mode="days1" period1_param="30" period1_date="2011-09-24"
              period5_mode="days5" period5_param="34" period5_date="2011-09-28"
              depth="1" scope="DIR" qualifier="PAC" created_at="2008-12-01" build_date="2011-09-29"
              version="2.1-SNAPSHOT" path="1.2."/>
-  <!-- PROJECT_ID = 3  no last snapshot -->
+  <!-- PROJECT_ID = 3 - no last snapshot -->
   <snapshots id="49" project_id="3" parent_snapshot_id="2" root_project_id="123" root_snapshot_id="46"
              status="P" islast="[false]" purge_status="1"
              period1_mode="days1" period1_param="30" period1_date="2011-09-24"
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedAnalysisReportsLongDatesTest/before.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedAnalysisReportsLongDatesTest/before.xml
new file mode 100644 (file)
index 0000000..771b77c
--- /dev/null
@@ -0,0 +1,52 @@
+<dataset>
+  <!-- new migration -->
+  <analysis_reports
+      id="1"
+      project_key="123456789-987654321"
+      snapshot_id="123"
+      report_data="data-project"
+      report_status="WORKING"
+      created_at="2014-09-25"
+      updated_at="2014-09-24"
+      started_at="2014-09-23"
+      finished_at="2014-09-22"
+      created_at_ms="[null]"
+      updated_at_ms="[null]"
+      started_at_ms="[null]"
+      finished_at_ms="[null]"
+      />
+
+  <!-- re-entrant migration - ignore the issues that are already fed with new dates -->
+  <analysis_reports
+      id="2"
+      project_key="123456789-987654321"
+      snapshot_id="123"
+      report_data="data-project"
+      report_status="WORKING"
+      created_at="2014-09-25"
+      updated_at="2014-09-24"
+      started_at="2014-09-23"
+      finished_at="2014-09-22"
+      created_at_ms="1500000000000"
+      updated_at_ms="1500000000000"
+      started_at_ms="1500000000000"
+      finished_at_ms="1500000000000"
+      />
+
+  <!-- NULL dates -->
+  <analysis_reports
+      id="3"
+      project_key="123456789-987654321"
+      snapshot_id="123"
+      report_data="data-project"
+      report_status="WORKING"
+      created_at="[null]"
+      updated_at="[null]"
+      started_at="[null]"
+      finished_at="[null]"
+      created_at_ms="[null]"
+      updated_at_ms="[null]"
+      started_at_ms="[null]"
+      finished_at_ms="[null]"
+      />
+</dataset>
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedAnalysisReportsLongDatesTest/schema.sql b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedAnalysisReportsLongDatesTest/schema.sql
new file mode 100644 (file)
index 0000000..c2187b6
--- /dev/null
@@ -0,0 +1,16 @@
+CREATE TABLE "ANALYSIS_REPORTS" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "PROJECT_KEY" VARCHAR(400) NOT NULL,
+  "PROJECT_NAME" VARCHAR(256) NULL,
+  "SNAPSHOT_ID" INTEGER NOT NULL,
+  "REPORT_STATUS" VARCHAR(20) NOT NULL,
+  "REPORT_DATA" BLOB(2147483647),
+  "CREATED_AT" TIMESTAMP,
+  "UPDATED_AT" TIMESTAMP,
+  "STARTED_AT" TIMESTAMP,
+  "FINISHED_AT" TIMESTAMP,
+  "CREATED_AT_MS" BIGINT,
+  "UPDATED_AT_MS" BIGINT,
+  "STARTED_AT_MS" BIGINT,
+  "FINISHED_AT_MS" BIGINT
+);
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/763_add_analysis_reports_long_dates.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/763_add_analysis_reports_long_dates.rb
new file mode 100644 (file)
index 0000000..4c520db
--- /dev/null
@@ -0,0 +1,32 @@
+#
+# SonarQube, open source software quality management tool.
+# Copyright (C) 2008-2014 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# SonarQube is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3 of the License, or (at your option) any later version.
+#
+# SonarQube is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+#
+
+#
+# SonarQube 5.1
+#
+class AddAnalysisReportsLongDates < ActiveRecord::Migration
+
+  def self.up
+    add_column 'analysis_reports', :created_at_ms, :big_integer, :null => true
+    add_column 'analysis_reports', :updated_at_ms, :big_integer, :null => true
+    add_column 'analysis_reports', :started_at_ms, :big_integer, :null => true
+    add_column 'analysis_reports', :finished_at_ms, :big_integer, :null => true
+  end
+end
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/764_feed_analysis_reports_long_dates.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/764_feed_analysis_reports_long_dates.rb
new file mode 100644 (file)
index 0000000..dc59f53
--- /dev/null
@@ -0,0 +1,31 @@
+#
+# SonarQube, open source software quality management tool.
+# Copyright (C) 2008-2014 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# SonarQube is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3 of the License, or (at your option) any later version.
+#
+# SonarQube is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+#
+
+#
+# SonarQube 5.1
+#
+class FeedAnalysisReportsLongDates < ActiveRecord::Migration
+
+  def self.up
+    execute_java_migration('org.sonar.server.db.migrations.v51.FeedAnalysisReportsLongDates')
+  end
+
+end
+
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/765_rename_analysis_reports_long_dates.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/765_rename_analysis_reports_long_dates.rb
new file mode 100644 (file)
index 0000000..df6c66c
--- /dev/null
@@ -0,0 +1,37 @@
+#
+# SonarQube, open source software quality management tool.
+# Copyright (C) 2008-2014 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# SonarQube is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3 of the License, or (at your option) any later version.
+#
+# SonarQube is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+#
+
+#
+# SonarQube 5.1
+#
+class RenameAnalysisReportsLongDates < ActiveRecord::Migration
+
+  def self.up
+    remove_column 'analysis_reports', 'created_at'
+    remove_column 'analysis_reports', 'updated_at'
+    remove_column 'analysis_reports', 'started_at'
+    remove_column 'analysis_reports', 'finished_at'
+    rename_column 'analysis_reports', 'created_at_ms', 'created_at'
+    rename_column 'analysis_reports', 'updated_at_ms', 'updated_at'
+    rename_column 'analysis_reports', 'started_at_ms', 'started_at'
+    rename_column 'analysis_reports', 'finished_at_ms', 'finished_at'
+  end
+end
+
index 3aa668dfda9e7aa876727b493414fec9bfc4edd9..bd21be2f473924456cbb3cbb76313012631f1e54 100644 (file)
@@ -21,30 +21,22 @@ package org.sonar.core.computation.db;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Objects;
-import org.sonar.core.persistence.Dto;
 
+import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 
 import java.io.InputStream;
-import java.util.Date;
-
-public class AnalysisReportDto extends Dto<String> {
-
-  public static enum Status {
-    PENDING, WORKING, SUCCESS, FAILED;
-
-    public boolean isInFinalState() {
-      return SUCCESS.equals(this) || FAILED.equals(this);
-    }
-  }
 
+public class AnalysisReportDto {
   private Long id;
   private String projectKey;
   private Status status;
   private InputStream data;
   private Long snapshotId;
-  private Date startedAt;
-  private Date finishedAt;
+  private Long createdAt;
+  private Long updatedAt;
+  private Long startedAt;
+  private Long finishedAt;
 
   @VisibleForTesting
   public static AnalysisReportDto newForTests(Long id) {
@@ -89,7 +81,6 @@ public class AnalysisReportDto extends Dto<String> {
     return this;
   }
 
-  @Override
   public String getKey() {
     return String.valueOf(getId());
   }
@@ -120,33 +111,49 @@ public class AnalysisReportDto extends Dto<String> {
     return this;
   }
 
-  public Date getStartedAt() {
+  @CheckForNull
+  public Long getStartedAt() {
     return startedAt;
   }
 
-  public AnalysisReportDto setStartedAt(Date startedAt) {
+  public AnalysisReportDto setStartedAt(Long startedAt) {
     this.startedAt = startedAt;
     return this;
   }
 
-  public Date getFinishedAt() {
+  @CheckForNull
+  public Long getFinishedAt() {
     return finishedAt;
   }
 
-  public AnalysisReportDto setFinishedAt(Date finishedAt) {
+  public AnalysisReportDto setFinishedAt(Long finishedAt) {
     this.finishedAt = finishedAt;
     return this;
   }
 
-  @Override
-  public AnalysisReportDto setUpdatedAt(Date datetime) {
-    super.setUpdatedAt(datetime);
+  public Long getCreatedAt() {
+    return createdAt;
+  }
+
+  public AnalysisReportDto setCreatedAt(Long createdAt) {
+    this.createdAt = createdAt;
     return this;
   }
 
-  @Override
-  public AnalysisReportDto setCreatedAt(Date datetime) {
-    super.setCreatedAt(datetime);
+  public Long getUpdatedAt() {
+    return updatedAt;
+  }
+
+  public AnalysisReportDto setUpdatedAt(Long updatedAt) {
+    this.updatedAt = updatedAt;
     return this;
   }
+
+  public static enum Status {
+    PENDING, WORKING, SUCCESS, FAILED;
+
+    public boolean isInFinalState() {
+      return SUCCESS.equals(this) || FAILED.equals(this);
+    }
+  }
 }
index fd279dec2ea1302c3e671622c3adb8fef4d741f9..223eacbe69ef973c429ccbe11db035eed2928abc 100644 (file)
@@ -21,7 +21,6 @@ package org.sonar.core.computation.db;
 
 import org.apache.ibatis.annotations.Param;
 
-import java.util.Date;
 import java.util.List;
 
 public interface AnalysisReportMapper {
@@ -31,13 +30,13 @@ public interface AnalysisReportMapper {
     @Param("availableStatus") AnalysisReportDto.Status availableStatus,
     @Param("busyStatus") AnalysisReportDto.Status busyStatus);
 
-  void resetAllToPendingStatus(@Param("updatedAt") Date updatedAt);
+  void resetAllToPendingStatus(@Param("updatedAt") long updatedAt);
 
   void truncate();
 
   int update(AnalysisReportDto report);
 
-  int updateWithBookingReport(@Param("id") Long id, @Param("startedAt") Date startedAt,
+  int updateWithBookingReport(@Param("id") Long id, @Param("startedAt") long startedAt,
     @Param("availableStatus") AnalysisReportDto.Status availableStatus,
     @Param("busyStatus") AnalysisReportDto.Status busyStatus);
 
index db8cb2ea33ee97128295fc2a3523998b76c03c09..c9e317ec9dfe57f3dde6a46d013624f6bddf33e6 100644 (file)
@@ -27,11 +27,11 @@ import org.sonar.api.CoreProperties;
 import org.sonar.api.config.Settings;
 import org.sonar.api.resources.Qualifiers;
 import org.sonar.api.utils.TimeUtils;
+import org.sonar.core.computation.dbcleaner.period.DefaultPeriodCleaner;
 import org.sonar.core.purge.*;
 import org.sonar.core.resource.ResourceDao;
 import org.sonar.core.resource.ResourceDto;
 import org.sonar.plugins.dbcleaner.api.PurgeTask;
-import org.sonar.core.computation.dbcleaner.period.DefaultPeriodCleaner;
 
 import static org.sonar.core.purge.PurgeConfiguration.newDefaultPurgeConfiguration;
 
@@ -91,7 +91,7 @@ public class DefaultPurgeTask implements PurgeTask {
     try {
       periodCleaner.clean(resourceId);
     } catch (Exception e) {
-      // purge errors must no fail the batch
+      // purge errors must not fail the batch
       LOG.error("Fail to clean historical data [id=" + resourceId + "]", e);
     }
   }
@@ -100,7 +100,7 @@ public class DefaultPurgeTask implements PurgeTask {
     try {
       purgeDao.purge(newPurgeConfigurationOnResource(resourceId), PurgeListener.EMPTY);
     } catch (Exception e) {
-      // purge errors must no fail the report analysis
+      // purge errors must not fail the report analysis
       LOG.error("Fail to purge data [id=" + resourceId + "]", e);
     }
   }
index 83c1660265d84f12286d840bd8c5e7b42e72b29b..eb1b82b063f300c226ab5852a6d983ff3fc43c84 100644 (file)
@@ -33,7 +33,7 @@ import java.util.List;
  */
 public class DatabaseVersion implements BatchComponent, ServerComponent {
 
-  public static final int LAST_VERSION = 762;
+  public static final int LAST_VERSION = 765;
 
   /**
    * List of all the tables.n
index b067306fe9a51524de40262a64d132adb96079a7..398b51673554bdd7d03b2aa236dd0ef315f62e13 100644 (file)
@@ -291,6 +291,9 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('759');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('760');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('761');
 INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('762');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('763');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('764');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('765');
 
 INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '1418215735482', '1418215735482', null, null);
 ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
index 3b79cb47b02481643f0bc8a3ce1822d10e04a888..b5175c645c3e89a8fdd16a6dea9e48857abab2ea 100644 (file)
@@ -554,10 +554,10 @@ CREATE TABLE "ANALYSIS_REPORTS" (
   "SNAPSHOT_ID" INTEGER NOT NULL,
   "REPORT_STATUS" VARCHAR(20) NOT NULL,
   "REPORT_DATA" BLOB(2147483647),
-  "CREATED_AT" TIMESTAMP NOT NULL,
-  "UPDATED_AT" TIMESTAMP,
-  "STARTED_AT" TIMESTAMP,
-  "FINISHED_AT" TIMESTAMP
+  "CREATED_AT" BIGINT,
+  "UPDATED_AT" BIGINT,
+  "STARTED_AT" BIGINT,
+  "FINISHED_AT" BIGINT
 );
 
 CREATE TABLE "FILE_SOURCES" (
index a36ce0a44eac59e90aea190012b09d1f27a5ac2d..556db4866213b6f5cc1c2188e40a507c715d7ec4 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.api.utils;
 
 import javax.annotation.Nullable;
-
 import java.io.NotSerializableException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
@@ -64,6 +63,10 @@ public final class DateUtils {
     return THREAD_SAFE_DATETIME_FORMAT.format(date);
   }
 
+  public static Date timeToDate(@Nullable Long time) {
+    return time == null ? null : new Date(time);
+  }
+
   /**
    * @param s string in format {@link #DATE_FORMAT}
    * @throws SonarException when string cannot be parsed