From: Jean-Baptiste Lievremont Date: Wed, 19 Nov 2014 10:49:51 +0000 (+0100) Subject: SONAR-5826 Revert to (get|set)Bytes to please Oracle, refactor migration test to... X-Git-Tag: 5.0-RC1~295 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3fdf1891ac8bac6c21035746ac870dfed298c936;p=sonarqube.git SONAR-5826 Revert to (get|set)Bytes to please Oracle, refactor migration test to please H2 --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedFileSources.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedFileSources.java index 16bd1b02fff..515a6fde99e 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedFileSources.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedFileSources.java @@ -49,12 +49,12 @@ public class FeedFileSources extends BaseDataChange { String fileUuid = row.getString(2); String source = row.getString(3); Date updatedAt = row.getDate(4); - String shortRevisions = row.getString(5); - String longRevisions = row.getString(6); - String shortAuthors = row.getString(7); - String longAuthors = row.getString(8); - String shortDates = row.getString(9); - String longDates = row.getString(10); + byte[] shortRevisions = row.getBytes(5); + byte[] longRevisions = row.getBytes(6); + byte[] shortAuthors = row.getBytes(7); + byte[] longAuthors = row.getBytes(8); + byte[] shortDates = row.getBytes(9); + byte[] longDates = row.getBytes(10); String sourceData = new FileSourceDto(source, shortRevisions, longRevisions, shortAuthors, longAuthors, shortDates, longDates).getSourceData(); diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FileSourceDto.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FileSourceDto.java index a1f6bfad21c..893e1fc8c6b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FileSourceDto.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FileSourceDto.java @@ -42,8 +42,8 @@ class FileSourceDto { private Map dates; - FileSourceDto(String source, @Nullable String shortRevisions, @Nullable String longRevisions, @Nullable String shortAuthors, @Nullable String longAuthors, - @Nullable String shortDates, @Nullable String longDates) { + FileSourceDto(String source, @Nullable byte[] shortRevisions, @Nullable byte[] longRevisions, @Nullable byte[] shortAuthors, @Nullable byte[] longAuthors, + @Nullable byte[] shortDates, @Nullable byte[] longDates) { sourceSplitter = Splitter.onPattern("\r?\n|\r").split(source).iterator(); revisions = KeyValueFormat.parseIntString(ofNullableBytes(shortRevisions, longRevisions)); authors = KeyValueFormat.parseIntString(ofNullableBytes(shortAuthors, longAuthors)); @@ -65,17 +65,17 @@ class FileSourceDto { return new String(output.toByteArray(), UTF_8); } - private static String ofNullableBytes(@Nullable String shortBytes, @Nullable String longBytes) { - String result; + private static String ofNullableBytes(@Nullable byte[] shortBytes, @Nullable byte[] longBytes) { + byte[] result; if (shortBytes == null) { if (longBytes == null) { - result = ""; + return ""; } else { result = longBytes; } } else { result = shortBytes; } - return result; + return new String(result, UTF_8); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FeedFileSourcesMigrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FeedFileSourcesMigrationTest.java index 0289197a55e..82e9c3fa742 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FeedFileSourcesMigrationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FeedFileSourcesMigrationTest.java @@ -20,6 +20,8 @@ package org.sonar.server.db.migrations.v50; +import org.apache.commons.dbutils.DbUtils; +import org.apache.commons.io.Charsets; import org.junit.Before; import org.junit.ClassRule; import org.junit.Test; @@ -28,6 +30,8 @@ import org.sonar.api.utils.System2; import org.sonar.core.persistence.TestDatabase; import org.sonar.server.db.migrations.DatabaseMigration; +import java.sql.Connection; +import java.sql.PreparedStatement; import java.util.Date; import static org.mockito.Mockito.mock; @@ -80,25 +84,40 @@ public class FeedFileSourcesMigrationTest { public void migrate_sources_with_scm() throws Exception { db.prepareDbUnit(getClass(), "before.xml"); - db.executeUpdateSql("insert into snapshot_sources " + - "(snapshot_id, data, updated_at) " + - "values " + - "(6, 'class Foo {\r\n // Empty\r\n}\r\n', '2014-10-31 16:44:02.000')"); + Connection connection = null; + try { + connection = db.openConnection(); + + connection.prepareStatement("insert into snapshot_sources " + + "(snapshot_id, data, updated_at) " + + "values " + + "(6, 'class Foo {\r\n // Empty\r\n}\r\n', '2014-10-31 16:44:02.000')") + .executeUpdate(); + + PreparedStatement revisionStmt = connection.prepareStatement("insert into project_measures " + + "(metric_id, snapshot_id, text_value) " + + "values " + + "(1, 6, ?)"); + revisionStmt.setBytes(1, "1=aef12a;2=abe465;3=afb789;4=afb789".getBytes(Charsets.UTF_8)); + revisionStmt.executeUpdate(); + + PreparedStatement authorStmt = connection.prepareStatement("insert into project_measures " + + "(metric_id, snapshot_id, text_value) " + + "values " + + "(2, 6, ?)"); + authorStmt.setBytes(1, "1=alice;2=bob;3=carol;4=carol".getBytes(Charsets.UTF_8)); + authorStmt.executeUpdate(); + + PreparedStatement dateStmt = connection.prepareStatement("insert into project_measures " + + "(metric_id, snapshot_id, text_value) " + + "values " + + "(3, 6, ?)"); + dateStmt.setBytes(1, "1=2014-04-25T12:34:56+0100;2=2014-07-25T12:34:56+0100;3=2014-03-23T12:34:56+0100;4=2014-03-23T12:34:56+0100".getBytes(Charsets.UTF_8)); + dateStmt.executeUpdate(); + } finally { + DbUtils.commitAndCloseQuietly(connection); + } - db.executeUpdateSql("insert into project_measures " + - "(metric_id, snapshot_id, text_value) " + - "values " + - "(1, 6, $$1=aef12a;2=abe465;3=afb789;4=afb789$$)"); - - db.executeUpdateSql("insert into project_measures " + - "(metric_id, snapshot_id, text_value) " + - "values " + - "(2, 6, $$1=alice;2=bob;3=carol;4=carol$$)"); - - db.executeUpdateSql("insert into project_measures " + - "(metric_id, snapshot_id, text_value) " + - "values " + - "(3, 6, $$1=2014-04-25T12:34:56+0100;2=2014-07-25T12:34:56+0100;3=2014-03-23T12:34:56+0100;4=2014-03-23T12:34:56+0100$$)"); migration.execute();