From: Teryk Bellahsene Date: Mon, 12 Jan 2015 13:19:54 +0000 (+0100) Subject: change issue_changes timestamp columns to bigint/long X-Git-Tag: latest-silver-master-#65~247 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=60ca04b430be84f72e05728c1351c23b3cf751b2;p=sonarqube.git change issue_changes timestamp columns to bigint/long --- diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssueTrackingDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssueTrackingDecoratorTest.java index 45cc268f96e..337f16b94fe 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssueTrackingDecoratorTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssueTrackingDecoratorTest.java @@ -38,6 +38,7 @@ import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RuleFinder; import org.sonar.api.utils.Duration; +import org.sonar.api.utils.System2; import org.sonar.batch.issue.IssueCache; import org.sonar.batch.scan.LastLineHashes; import org.sonar.batch.scan.filesystem.InputPathCache; @@ -538,10 +539,10 @@ public class IssueTrackingDecoratorTest { @Test public void merge_issue_changelog_with_previous_changelog() throws Exception { - when(initialOpenIssues.selectChangelog("ABCDE")).thenReturn(newArrayList(new IssueChangeDto().setIssueKey("ABCD"))); + when(initialOpenIssues.selectChangelog("ABCDE")).thenReturn(newArrayList(new IssueChangeDto().setIssueKey("ABCD").setCreatedAt(System2.INSTANCE.now()))); IssueDto previousIssue = new IssueDto().setKee("ABCDE").setResolution(null).setStatus("OPEN").setRuleKey("squid", "AvoidCycle") - .setLine(10).setMessage("Message").setEffortToFix(1.5).setDebt(1L); + .setLine(10).setMessage("Message").setEffortToFix(1.5).setDebt(1L).setCreatedAt(System2.INSTANCE.now()); DefaultIssue issue = new DefaultIssue(); IssueTrackingResult trackingResult = mock(IssueTrackingResult.class); diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigrations.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigrations.java index 87c8c509a20..c825fe86383 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigrations.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/DatabaseMigrations.java @@ -30,10 +30,7 @@ import org.sonar.server.db.migrations.v45.DeleteMeasuresOnDeletedProfilesMigrati import org.sonar.server.db.migrations.v451.AddMissingCustomRuleParametersMigration; import org.sonar.server.db.migrations.v451.DeleteUnescapedActivities; import org.sonar.server.db.migrations.v50.*; -import org.sonar.server.db.migrations.v51.CopyScmAccountsFromAuthorsToUsers; -import org.sonar.server.db.migrations.v51.FeedIssueTags; -import org.sonar.server.db.migrations.v51.FeedUsersLongDates; -import org.sonar.server.db.migrations.v51.RenameComponentRelatedParamsInIssueFilters; +import org.sonar.server.db.migrations.v51.*; import java.util.List; @@ -83,6 +80,7 @@ public interface DatabaseMigrations { FeedIssueTags.class, FeedUsersLongDates.class, RenameComponentRelatedParamsInIssueFilters.class, - CopyScmAccountsFromAuthorsToUsers.class - ); + CopyScmAccountsFromAuthorsToUsers.class, + FeedIssueChangesLongDates.class + ); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedIssueChangesLongDates.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedIssueChangesLongDates.java new file mode 100644 index 00000000000..2db5dc0ea39 --- /dev/null +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedIssueChangesLongDates.java @@ -0,0 +1,79 @@ +/* + * 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 FeedIssueChangesLongDates extends BaseDataChange { + + private final System2 system; + + public FeedIssueChangesLongDates(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 i.created_at, i.updated_at, i.issue_change_creation_date_ms, i.id FROM issue_changes i WHERE created_at_ms IS NULL"); + massUpdate.update("UPDATE issue_changes SET created_at_ms=?, updated_at_ms=?, issue_change_creation_date_ms=? WHERE id=?"); + massUpdate.rowPluralName("issue_changes"); + 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 functionalCreatedAt = row.getDate(3); + Long id = row.getLong(4); + + updateColumn(update, 1, createdAt); + updateColumn(update, 2, updatedAt); + if (functionalCreatedAt == null) { + update.setLong(3, null); + } else { + update.setLong(3, functionalCreatedAt.getTime()); + } + update.setLong(4, 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())); + } + } + }); + } + +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueCommentService.java b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueCommentService.java index 2db001c4598..d889d8f600e 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueCommentService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueCommentService.java @@ -27,6 +27,7 @@ import org.sonar.api.issue.IssueComment; import org.sonar.api.issue.internal.DefaultIssue; import org.sonar.api.issue.internal.DefaultIssueComment; import org.sonar.api.issue.internal.IssueChangeContext; +import org.sonar.api.utils.System2; import org.sonar.core.issue.IssueUpdater; import org.sonar.core.issue.db.IssueChangeDao; import org.sonar.core.issue.db.IssueChangeDto; @@ -143,7 +144,7 @@ public class IssueCommentService implements ServerComponent { issueService.getByKey(comment.issueKey()); IssueChangeDto dto = IssueChangeDto.of(comment); - dto.setUpdatedAt(new Date()); + dto.setUpdatedAt(System2.INSTANCE.now()); dto.setChangeData(text); changeDao.update(dto); diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedIssueChangesLongDatesTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedIssueChangesLongDatesTest.java new file mode 100644 index 00000000000..5cd281bca35 --- /dev/null +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v51/FeedIssueChangesLongDatesTest.java @@ -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 FeedIssueChangesLongDatesTest { + @ClassRule + public static DbTester db = new DbTester().schema(FeedIssueChangesLongDatesTest.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 FeedIssueChangesLongDates(db.database(), system); + migration.execute(); + + int count = db.countSql("select count(*) from issue_changes 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 issue_changes where created_at_ms is not null and updated_at_ms is not null and issue_change_creation_date_ms is not null"); + assertThat(countWithAllDateFieldsNull).isEqualTo(1); + } +} diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java index 4c2efa43f02..5f52d466439 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java @@ -221,14 +221,14 @@ public class SearchActionMediumTest { .setChangeData("*My comment*") .setChangeType(IssueChangeDto.TYPE_COMMENT) .setUserLogin("john") - .setCreatedAt(DateUtils.parseDate("2014-09-09"))); + .setCreatedAt(DateUtils.parseDate("2014-09-09").getTime())); tester.get(IssueChangeDao.class).insert(session, new IssueChangeDto().setIssueKey(issue.getKey()) .setKey("COMMENT-ABCE") .setChangeData("Another comment") .setChangeType(IssueChangeDto.TYPE_COMMENT) .setUserLogin("fabrice") - .setCreatedAt(DateUtils.parseDate("2014-09-10"))); + .setCreatedAt(DateUtils.parseDate("2014-09-10").getTime())); session.commit(); tester.get(IssueIndexer.class).indexAll(); diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedIssueChangesLongDatesTest/before.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedIssueChangesLongDatesTest/before.xml new file mode 100644 index 00000000000..e8e59f0d053 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedIssueChangesLongDatesTest/before.xml @@ -0,0 +1,31 @@ + + + + + /> + + + + + + + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedIssueChangesLongDatesTest/schema.sql b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedIssueChangesLongDatesTest/schema.sql new file mode 100644 index 00000000000..240e5cedf2d --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v51/FeedIssueChangesLongDatesTest/schema.sql @@ -0,0 +1,14 @@ +CREATE TABLE "ISSUE_CHANGES" ( + "ID" BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), + "KEE" VARCHAR(50), + "ISSUE_KEY" VARCHAR(50) NOT NULL, + "USER_LOGIN" VARCHAR(255), + "CHANGE_TYPE" VARCHAR(40), + "CHANGE_DATA" VARCHAR(16777215), + "CREATED_AT" TIMESTAMP, + "UPDATED_AT" TIMESTAMP, + "ISSUE_CHANGE_CREATION_DATE" TIMESTAMP, + "CREATED_AT_MS" BIGINT, + "UPDATED_AT_MS" BIGINT, + "ISSUE_CHANGE_CREATION_DATE_MS" BIGINT +); diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/760_add_issue_changes_long_dates.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/760_add_issue_changes_long_dates.rb new file mode 100644 index 00000000000..6b954482072 --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/760_add_issue_changes_long_dates.rb @@ -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 AddIssueChangesLongDates < ActiveRecord::Migration + + def self.up + add_column 'issue_changes', :created_at_ms, :big_integer, :null => true + add_column 'issue_changes', :updated_at_ms, :big_integer, :null => true + add_column 'issue_changes', :issue_change_creation_date_ms, :big_integer, :null => true + end +end + diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/761_feed_issue_changes_long_dates.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/761_feed_issue_changes_long_dates.rb new file mode 100644 index 00000000000..2d6d3398d2b --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/761_feed_issue_changes_long_dates.rb @@ -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 FeedIssueChangesLongDates < ActiveRecord::Migration + + def self.up + execute_java_migration('org.sonar.server.db.migrations.v51.FeedIssueChangesLongDates') + end + +end + diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/762_rename_issue_changes_long_dates.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/762_rename_issue_changes_long_dates.rb new file mode 100644 index 00000000000..921f3c4398c --- /dev/null +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/762_rename_issue_changes_long_dates.rb @@ -0,0 +1,35 @@ +# +# 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 RenameIssueChangesLongDates < ActiveRecord::Migration + + def self.up + remove_column 'issue_changes', 'created_at' + remove_column 'issue_changes', 'updated_at' + remove_column 'issue_changes', 'issue_change_creation_date' + rename_column 'issue_changes', 'created_at_ms', 'created_at' + rename_column 'issue_changes', 'updated_at_ms', 'updated_at' + rename_column 'issue_changes', 'issue_change_creation_date_ms', 'issue_change_creation_date' + end +end + diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDto.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDto.java index d3f8d59239a..18b731018f1 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDto.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDto.java @@ -23,6 +23,7 @@ import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; import org.sonar.api.issue.internal.DefaultIssueComment; import org.sonar.api.issue.internal.FieldDiffs; +import org.sonar.api.utils.System2; import javax.annotation.CheckForNull; import javax.annotation.Nullable; @@ -30,6 +31,8 @@ import javax.annotation.Nullable; import java.io.Serializable; import java.util.Date; +import static com.google.common.base.Preconditions.checkNotNull; + /** * @since 3.6 */ @@ -46,11 +49,40 @@ public final class IssueChangeDto implements Serializable { private String changeData; // technical dates - private Date createdAt; - private Date updatedAt; + private Long createdAt; + private Long updatedAt; // functional date - private Date issueChangeCreationDate; + private Long issueChangeCreationDate; + + public static IssueChangeDto of(DefaultIssueComment comment) { + IssueChangeDto dto = newDto(comment.issueKey()); + dto.setKey(comment.key()); + dto.setChangeType(IssueChangeDto.TYPE_COMMENT); + dto.setChangeData(comment.markdownText()); + dto.setUserLogin(comment.userLogin()); + dto.setIssueChangeCreationDate(comment.createdAt() == null ? null : comment.createdAt().getTime()); + return dto; + } + + public static IssueChangeDto of(String issueKey, FieldDiffs diffs) { + IssueChangeDto dto = newDto(issueKey); + dto.setChangeType(IssueChangeDto.TYPE_FIELD_CHANGE); + dto.setChangeData(diffs.toString()); + dto.setUserLogin(diffs.userLogin()); + dto.setIssueChangeCreationDate(diffs.creationDate() == null ? null : diffs.creationDate().getTime()); + return dto; + } + + private static IssueChangeDto newDto(String issueKey) { + IssueChangeDto dto = new IssueChangeDto(); + dto.setIssueKey(issueKey); + + // technical dates - do not use the context date + dto.setCreatedAt(System2.INSTANCE.now()); + dto.setUpdatedAt(System2.INSTANCE.now()); + return dto; + } public Long getId() { return id; @@ -107,29 +139,29 @@ public final class IssueChangeDto implements Serializable { return this; } - public Date getCreatedAt() { + public Long getCreatedAt() { return createdAt; } - public IssueChangeDto setCreatedAt(Date createdAt) { - this.createdAt = createdAt; + public IssueChangeDto setCreatedAt(Long createdAt) { + this.createdAt = checkNotNull(createdAt); return this; } - public Date getUpdatedAt() { + public Long getUpdatedAt() { return updatedAt; } - public IssueChangeDto setUpdatedAt(Date updatedAt) { + public IssueChangeDto setUpdatedAt(@Nullable Long updatedAt) { this.updatedAt = updatedAt; return this; } - public Date getIssueChangeCreationDate() { + public Long getIssueChangeCreationDate() { return issueChangeCreationDate; } - public IssueChangeDto setIssueChangeCreationDate(Date issueChangeCreationDate) { + public IssueChangeDto setIssueChangeCreationDate(@Nullable Long issueChangeCreationDate) { this.issueChangeCreationDate = issueChangeCreationDate; return this; } @@ -139,42 +171,12 @@ public final class IssueChangeDto implements Serializable { return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); } - public static IssueChangeDto of(DefaultIssueComment comment) { - IssueChangeDto dto = newDto(comment.issueKey()); - dto.setKey(comment.key()); - dto.setChangeType(IssueChangeDto.TYPE_COMMENT); - dto.setChangeData(comment.markdownText()); - dto.setUserLogin(comment.userLogin()); - dto.setIssueChangeCreationDate(comment.createdAt()); - return dto; - } - - public static IssueChangeDto of(String issueKey, FieldDiffs diffs) { - IssueChangeDto dto = newDto(issueKey); - dto.setChangeType(IssueChangeDto.TYPE_FIELD_CHANGE); - dto.setChangeData(diffs.toString()); - dto.setUserLogin(diffs.userLogin()); - dto.setIssueChangeCreationDate(diffs.creationDate()); - return dto; - } - - private static IssueChangeDto newDto(String issueKey) { - IssueChangeDto dto = new IssueChangeDto(); - dto.setIssueKey(issueKey); - - // technical dates - do not use the context date - Date now = new Date(); - dto.setCreatedAt(now); - dto.setUpdatedAt(new Date()); - return dto; - } - public DefaultIssueComment toComment() { return new DefaultIssueComment() .setMarkdownText(changeData) .setKey(kee) - .setCreatedAt(createdAt) - .setUpdatedAt(updatedAt) + .setCreatedAt(new Date(createdAt)) + .setUpdatedAt(updatedAt == null ? null : new Date(updatedAt)) .setUserLogin(userLogin) .setIssueKey(issueKey) .setNew(false); @@ -184,7 +186,7 @@ public final class IssueChangeDto implements Serializable { return FieldDiffs.parse(changeData) .setUserLogin(userLogin) // issueChangeCreationDate can be null as it has been introduced after createdAt - .setCreationDate(issueChangeCreationDate != null ? issueChangeCreationDate : createdAt) + .setCreationDate(issueChangeCreationDate != null ? new Date(issueChangeCreationDate) : new Date(createdAt)) .setIssueKey(issueKey); } } diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java index 3b2cbb8d129..83c1660265d 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DatabaseVersion.java @@ -33,7 +33,7 @@ import java.util.List; */ public class DatabaseVersion implements BatchComponent, ServerComponent { - public static final int LAST_VERSION = 759; + public static final int LAST_VERSION = 762; /** * List of all the tables.n diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql index 8914d74ec14..b067306fe9a 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/rows-h2.sql @@ -288,6 +288,9 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('756'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('757'); INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('758'); 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 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; diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl index 03ce64c522c..3b79cb47b02 100644 --- a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl +++ b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl @@ -474,9 +474,9 @@ CREATE TABLE "ISSUE_CHANGES" ( "USER_LOGIN" VARCHAR(255), "CHANGE_TYPE" VARCHAR(40), "CHANGE_DATA" VARCHAR(16777215), - "CREATED_AT" TIMESTAMP, - "UPDATED_AT" TIMESTAMP, - "ISSUE_CHANGE_CREATION_DATE" TIMESTAMP, + "CREATED_AT" BIGINT, + "UPDATED_AT" BIGINT, + "ISSUE_CHANGE_CREATION_DATE" BIGINT ); CREATE TABLE "ISSUE_FILTERS" ( diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDaoTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDaoTest.java index 91dcc972914..b6c047e795d 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDaoTest.java @@ -68,7 +68,6 @@ public class IssueChangeDaoTest extends AbstractDaoTestCase { DefaultIssueComment first = comments.get(0); assertThat(first.markdownText()).isEqualTo("old comment"); - DefaultIssueComment second = comments.get(1); assertThat(second.userLogin()).isEqualTo("arthur"); assertThat(second.key()).isEqualTo("FGHIJ"); @@ -81,8 +80,8 @@ public class IssueChangeDaoTest extends AbstractDaoTestCase { DbSession session = getMyBatis().openSession(false); List hugeNbOfIssues = newArrayList(); - for (int i=0; i<4500; i++) { - hugeNbOfIssues.add("ABCD"+i); + for (int i = 0; i < 4500; i++) { + hugeNbOfIssues.add("ABCD" + i); } List comments = dao.selectCommentsByIssues(session, hugeNbOfIssues); MyBatis.closeQuietly(session); @@ -192,9 +191,9 @@ public class IssueChangeDaoTest extends AbstractDaoTestCase { .setChangeData("Some text") .setChangeType("comment") .setIssueKey("ABCDE") - .setCreatedAt(DateUtils.parseDate("2014-09-09")) - .setUpdatedAt(DateUtils.parseDate("2014-09-10")) - .setIssueChangeCreationDate(DateUtils.parseDate("2014-09-11")); + .setCreatedAt(DateUtils.parseDate("2014-09-09").getTime()) + .setUpdatedAt(DateUtils.parseDate("2014-09-10").getTime()) + .setIssueChangeCreationDate(DateUtils.parseDate("2014-09-11").getTime()); dao.insert(session, changeDto); session.commit(); @@ -211,7 +210,7 @@ public class IssueChangeDaoTest extends AbstractDaoTestCase { // Only the following fields can be updated: change.setChangeData("new comment"); - change.setUpdatedAt(DateUtils.parseDate("2013-06-30")); + change.setUpdatedAt(DateUtils.parseDate("2013-06-30").getTime()); assertThat(dao.update(change)).isTrue(); @@ -227,7 +226,7 @@ public class IssueChangeDaoTest extends AbstractDaoTestCase { // Only the following fields can be updated: change.setChangeData("new comment"); - change.setUpdatedAt(DateUtils.parseDate("2013-06-30")); + change.setUpdatedAt(DateUtils.parseDate("2013-06-30").getTime()); assertThat(dao.update(change)).isFalse(); } diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDtoTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDtoTest.java index ae7523836dc..a3602e8f3f2 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDtoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDtoTest.java @@ -23,8 +23,7 @@ import org.junit.Test; import org.sonar.api.issue.internal.DefaultIssueComment; import org.sonar.api.issue.internal.FieldDiffs; import org.sonar.api.utils.DateUtils; - -import java.util.Date; +import org.sonar.api.utils.System2; import static org.assertj.core.api.Assertions.assertThat; @@ -57,7 +56,7 @@ public class IssueChangeDtoTest { assertThat(dto.getChangeType()).isEqualTo("diff"); assertThat(dto.getCreatedAt()).isNotNull(); assertThat(dto.getUpdatedAt()).isNotNull(); - assertThat(dto.getIssueChangeCreationDate()).isEqualTo(DateUtils.parseDate("2014-01-03")); + assertThat(dto.getIssueChangeCreationDate()).isEqualTo(DateUtils.parseDate("2014-01-03").getTime()); assertThat(dto.getIssueKey()).isEqualTo("ABCDE"); assertThat(dto.getUserLogin()).isEqualTo("emmerik"); } @@ -69,8 +68,8 @@ public class IssueChangeDtoTest { .setUserLogin("emmerik") .setChangeData("Some text") .setIssueKey("ABCDE") - .setCreatedAt(new Date()) - .setUpdatedAt(new Date()); + .setCreatedAt(System2.INSTANCE.now()) + .setUpdatedAt(System2.INSTANCE.now()); DefaultIssueComment comment = changeDto.toComment(); assertThat(comment.key()).isEqualTo("EFGH"); @@ -88,7 +87,7 @@ public class IssueChangeDtoTest { .setUserLogin("emmerik") .setChangeData("Some text") .setIssueKey("ABCDE") - .setIssueChangeCreationDate(new Date()); + .setIssueChangeCreationDate(System2.INSTANCE.now()); FieldDiffs diffs = changeDto.toFieldDiffs(); assertThat(diffs.userLogin()).isEqualTo("emmerik"); @@ -103,7 +102,7 @@ public class IssueChangeDtoTest { .setUserLogin("emmerik") .setChangeData("Some text") .setIssueKey("ABCDE") - .setCreatedAt(new Date()); + .setCreatedAt(System2.INSTANCE.now()); FieldDiffs diffs = changeDto.toFieldDiffs(); assertThat(diffs.userLogin()).isEqualTo("emmerik"); diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeMapperTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeMapperTest.java index d1a1c8a709e..6c428e4a901 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeMapperTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeMapperTest.java @@ -27,8 +27,6 @@ import org.sonar.api.utils.DateUtils; import org.sonar.core.persistence.AbstractDaoTestCase; import org.sonar.core.persistence.MyBatis; -import java.util.Date; - public class IssueChangeMapperTest extends AbstractDaoTestCase { SqlSession session; IssueChangeMapper mapper; @@ -52,14 +50,14 @@ public class IssueChangeMapperTest extends AbstractDaoTestCase { dto.setIssueKey("ABCDE"); dto.setChangeType(IssueChangeDto.TYPE_FIELD_CHANGE); dto.setChangeData("severity=INFO|BLOCKER"); - Date d = DateUtils.parseDate("2013-05-18"); + long d = DateUtils.parseDate("2013-05-18").getTime(); dto.setCreatedAt(d); dto.setUpdatedAt(d); dto.setIssueChangeCreationDate(d); mapper.insert(dto); session.commit(); - checkTables("insert_diff", new String[]{"id"}, "issue_changes"); + checkTables("insert_diff", new String[] {"id"}, "issue_changes"); } @Test @@ -70,12 +68,12 @@ public class IssueChangeMapperTest extends AbstractDaoTestCase { dto.setIssueKey("ABCDE"); dto.setChangeType(IssueChangeDto.TYPE_COMMENT); dto.setChangeData("the comment"); - Date d = DateUtils.parseDate("2013-05-18"); + long d = DateUtils.parseDate("2013-05-18").getTime(); dto.setCreatedAt(d); dto.setUpdatedAt(d); mapper.insert(dto); session.commit(); - checkTables("insert_comment", new String[]{"id"}, "issue_changes"); + checkTables("insert_comment", new String[] {"id"}, "issue_changes"); } } diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/delete-result.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/delete-result.xml index 43980b2e35e..be1549d36f1 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/delete-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/delete-result.xml @@ -7,8 +7,8 @@ user_login="arthur" change_type="comment" change_data="old comment" - created_at="2013-01-01" - updated_at="2013-01-01" + created_at="1356994800000" + updated_at="1356994800000" issue_change_creation_date="[null]" /> @@ -19,9 +19,9 @@ user_login="arthur" change_type="diff" change_data="severity=MAJOR|BLOCKER" - created_at="2013-02-02" - updated_at="2013-02-02" - issue_change_creation_date="2013-02-02" + created_at="1359759600000" + updated_at="1359759600000" + issue_change_creation_date="1359759600000" /> diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/delete.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/delete.xml index ffc07f03686..3277acb54ca 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/delete.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/delete.xml @@ -7,8 +7,8 @@ user_login="arthur" change_type="comment" change_data="old comment" - created_at="2013-01-01" - updated_at="2013-01-01" + created_at="1356994800000" + updated_at="1356994800000" issue_change_creation_date="[null]" /> @@ -19,9 +19,9 @@ user_login="arthur" change_type="diff" change_data="severity=MAJOR|BLOCKER" - created_at="2013-02-02" - updated_at="2013-02-02" - issue_change_creation_date="2013-02-02" + created_at="1359759600000" + updated_at="1359759600000" + issue_change_creation_date="1359759600000" /> diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/insert-result.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/insert-result.xml index a91841afa11..6e5a96df545 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/insert-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/insert-result.xml @@ -7,9 +7,9 @@ user_login="emmerik" change_type="comment" change_data="Some text" - created_at="2014-09-09" - updated_at="2014-09-10" - issue_change_creation_date="2014-09-11" + created_at="1410213600000" + updated_at="1410300000000" + issue_change_creation_date="1410386400000" /> diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/select_issue_changelog_by_module.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/select_issue_changelog_by_module.xml index c93aea039d9..cd51c9c7bc0 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/select_issue_changelog_by_module.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/select_issue_changelog_by_module.xml @@ -38,9 +38,9 @@ user_login="arthur" change_type="diff" change_data="severity=MAJOR|BLOCKER" - created_at="2013-04-16" - updated_at="2013-04-16" - issue_change_creation_date="2013-04-16" + created_at="1410213600000" + updated_at="1410213600000" + issue_change_creation_date="1410213600000" /> @@ -100,9 +100,9 @@ user_login="arthur" change_type="diff" change_data="severity=MAJOR|BLOCKER" - created_at="2013-04-16" - updated_at="2013-04-16" - issue_change_creation_date="2013-04-16" + created_at="1410213600000" + updated_at="1410213600000" + issue_change_creation_date="1410213600000" /> @@ -138,9 +138,9 @@ user_login="arthur" change_type="diff" change_data="severity=MAJOR|BLOCKER" - created_at="2013-04-16" - updated_at="2013-04-16" - issue_change_creation_date="2013-04-16" + created_at="1410213600000" + updated_at="1410213600000" + issue_change_creation_date="1410213600000" /> @@ -176,9 +176,9 @@ user_login="arthur" change_type="diff" change_data="severity=MAJOR|BLOCKER" - created_at="2013-04-16" - updated_at="2013-04-16" - issue_change_creation_date="2013-04-16" + created_at="1410213600000" + updated_at="1410213600000" + issue_change_creation_date="1410213600000" /> @@ -214,9 +214,9 @@ user_login="arthur" change_type="diff" change_data="severity=MAJOR|BLOCKER" - created_at="2013-04-16" - updated_at="2013-04-16" - issue_change_creation_date="2013-04-16" + created_at="1410213600000" + updated_at="1410213600000" + issue_change_creation_date="1410213600000" /> diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/select_issue_changelog_by_module_are_sorted_by_creation_date.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/select_issue_changelog_by_module_are_sorted_by_creation_date.xml index f36d8c96a59..29907c71ac0 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/select_issue_changelog_by_module_are_sorted_by_creation_date.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/select_issue_changelog_by_module_are_sorted_by_creation_date.xml @@ -35,9 +35,9 @@ user_login="arthur" change_type="diff" change_data="severity=MAJOR|BLOCKER" - created_at="2013-04-18" - updated_at="2013-04-18" - issue_change_creation_date="2013-04-18" + created_at="1410386400000" + updated_at="1410386400000" + issue_change_creation_date="1410386400000" /> diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/shared.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/shared.xml index 48f09145b63..5367328c57c 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/shared.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/shared.xml @@ -7,8 +7,8 @@ user_login="arthur" change_type="comment" change_data="old comment" - created_at="2013-01-01" - updated_at="2013-01-01" + created_at="1356994800000" + updated_at="1356994800000" issue_change_creation_date="[null]" /> @@ -19,9 +19,9 @@ user_login="arthur" change_type="diff" change_data="severity=MAJOR|BLOCKER" - created_at="2013-02-02" - updated_at="2013-02-02" - issue_change_creation_date="2013-02-02" + created_at="1359759600000" + updated_at="1359759600000" + issue_change_creation_date="1359759600000" /> @@ -43,9 +43,9 @@ user_login="arthur" change_type="diff" change_data="actionPlan=1.0|1.1" - created_at="2013-02-02" - updated_at="2013-02-02" - issue_change_creation_date="2013-02-02" + created_at="1359759600000" + updated_at="1359759600000" + issue_change_creation_date="1359759600000" /> diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/update-result.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/update-result.xml index 31a5056c859..754dfd948f2 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/update-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/update-result.xml @@ -1,38 +1,38 @@ + id="100" + kee="COMMENT-1" + issue_key="ISSUE-1" + user_login="arthur" + change_type="comment" + change_data="old comment" + created_at="1356994800000" + updated_at="1356994800000" + issue_change_creation_date="[null]" + /> + id="101" + kee="[null]" + issue_key="1000" + user_login="arthur" + change_type="diff" + change_data="severity=MAJOR|BLOCKER" + created_at="1359759600000" + updated_at="1359759600000" + issue_change_creation_date="1359759600000" + /> + id="102" + kee="COMMENT-2" + issue_key="ISSUE-1" + user_login="arthur" + change_type="comment" + change_data="new comment" + created_at="1367704800000" + updated_at="1372543200000" + issue_change_creation_date="[null]" + /> diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/update.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/update.xml index 94e2ec53877..641f333faa3 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/update.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/update.xml @@ -7,8 +7,8 @@ user_login="arthur" change_type="comment" change_data="old comment" - created_at="2013-01-01" - updated_at="2013-01-01" + created_at="1356994800000" + updated_at="1356994800000" issue_change_creation_date="[null]" /> @@ -19,9 +19,9 @@ user_login="arthur" change_type="diff" change_data="severity=MAJOR|BLOCKER" - created_at="2013-02-02" - updated_at="2013-02-02" - issue_change_creation_date="2013-02-02" + created_at="1359759600000" + updated_at="1359759600000" + issue_change_creation_date="1359759600000" /> diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeMapperTest/insert_comment-result.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeMapperTest/insert_comment-result.xml index 67122e49373..ad0e38ea83d 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeMapperTest/insert_comment-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeMapperTest/insert_comment-result.xml @@ -6,8 +6,8 @@ user_login="emmerik" change_type="comment" change_data="the comment" - created_at="2013-05-18" - updated_at="2013-05-18" + created_at="1368828000000" + updated_at="1368828000000" issue_change_creation_date="[null]" /> diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeMapperTest/insert_diff-result.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeMapperTest/insert_diff-result.xml index 164a9d22dd4..d4754f60a06 100644 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeMapperTest/insert_diff-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeMapperTest/insert_diff-result.xml @@ -6,8 +6,8 @@ user_login="emmerik" change_type="diff" change_data="severity=INFO|BLOCKER" - created_at="2013-05-18" - updated_at="2013-05-18" - issue_change_creation_date="2013-05-18" + created_at="1368828000000" + updated_at="1368828000000" + issue_change_creation_date="1368828000000" />