]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5826 Revert to (get|set)Bytes to please Oracle, refactor migration test to...
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Wed, 19 Nov 2014 10:49:51 +0000 (11:49 +0100)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Wed, 19 Nov 2014 10:49:57 +0000 (11:49 +0100)
server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedFileSources.java
server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FileSourceDto.java
server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FeedFileSourcesMigrationTest.java

index 16bd1b02fffba8c214dc5c5ac765808de90c5e96..515a6fde99e440c44a7ab959632e6bf6b33a8843 100644 (file)
@@ -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();
 
index a1f6bfad21c62fb807cca9682fdccda6a4aba86f..893e1fc8c6b4f9b4a50432caf8b4bb781d776931 100644 (file)
@@ -42,8 +42,8 @@ class FileSourceDto {
 
   private Map<Integer, String> 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);
   }
 }
index 0289197a55ed3eb0df50d11c1962ea06d8c8f645..82e9c3fa742e49a5892039938ce0a919557af6b3 100644 (file)
@@ -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();