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();
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));
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);
}
}
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;
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;
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();