import org.sonar.server.db.ResultSetIterator;
import org.sonar.server.db.migrations.SqlUtil;
-import java.io.ByteArrayInputStream;
import java.io.IOException;
-import java.io.InputStreamReader;
import java.io.Reader;
-import java.sql.*;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Timestamp;
import java.util.Collection;
import java.util.Date;
import java.util.List;
String projectUuid = rs.getString(1);
String fileUuid = rs.getString(2);
Date updatedAt = SqlUtil.getDate(rs, 4);
- Reader dataStream = new InputStreamReader(new ByteArrayInputStream(rs.getBytes(5)));
+ Reader dataStream = rs.getClob(5).getCharacterStream();
int line = 1;
List<SourceLineDoc> lines = Lists.newArrayList();
public class AnalysisReportDaoTest {
private static final String DEFAULT_PROJECT_KEY = "123456789-987654321";
- private static final String DEFAULT_PROJECT_NAME = "default project name";
private static final long DEFAULT_SNAPSHOT_ID = 123L;
@Rule
}
private AnalysisReportDto newDefaultReport() {
- AnalysisReportDto report = AnalysisReportDto.newForTests(1L)
+ return AnalysisReportDto.newForTests(1L)
.setStatus(PENDING)
.setProjectKey(DEFAULT_PROJECT_KEY)
.setCreatedAt(DateUtils.parseDate("2014-09-30"))
.setFinishedAt(DateUtils.parseDate("2014-09-30"))
.setStartedAt(DateUtils.parseDate("2014-09-30"))
.setUpdatedAt(DateUtils.parseDate("2014-09-30"));
-
- return report;
}
}
db.prepareDbUnit(getClass(), "source-with-scm.xml");
Connection connection = db.openConnection();
PreparedStatement stmt = connection.prepareStatement("UPDATE file_sources SET data = ? WHERE id=1");
- stmt.setBytes(1, ("aef12a,alice,2014-04-25T12:34:56+0100,,class Foo {\r\n" +
+ stmt.setString(1, "aef12a,alice,2014-04-25T12:34:56+0100,,class Foo {\r\n" +
"abe465,bob,2014-07-25T12:34:56+0100,, // Empty\r\n" +
"afb789,carol,2014-03-23T12:34:56+0100,,}\r\n" +
- "afb789,carol,2014-03-23T12:34:56+0100,,\r\n").getBytes(Charsets.UTF_8));
+ "afb789,carol,2014-03-23T12:34:56+0100,,\r\n");
stmt.executeUpdate();
SourceLineResultSetIterator iterator = SourceLineResultSetIterator.create(dbClient, connection, 0L);
String newDataHash = newData != null ? DigestUtils.md5Hex(newData) : "0";
Date now = system2.newDate();
if (previous == null) {
- FileSourceDto newFileSource = new FileSourceDto().setProjectUuid(projectTree.getRootProject().getUuid()).setFileUuid(fileUuid).setStringData(newData)
+ FileSourceDto newFileSource = new FileSourceDto().setProjectUuid(projectTree.getRootProject().getUuid()).setFileUuid(fileUuid).setData(newData)
.setDataHash(newDataHash)
.setCreatedAt(now)
.setUpdatedAt(now);
session.commit();
} else {
if (!newDataHash.equals(previous.getDataHash())) {
- previous.setStringData(newData).setDataHash(newDataHash).setUpdatedAt(now);
+ previous.setData(newData).setDataHash(newDataHash).setUpdatedAt(now);
mapper.update(previous);
session.commit();
}
FileSourceDto fileSourceDto = new FileSourceDao(getMyBatis()).select("uuidsame");
assertThat(fileSourceDto.getCreatedAt()).isEqualTo(DateUtils.parseDateTime("2014-10-10T16:44:02+0200"));
assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(now);
- assertThat(fileSourceDto.getStringData()).isEqualTo(
+ assertThat(fileSourceDto.getData()).isEqualTo(
",,,,changed\r\n,,,,content\r\n");
assertThat(fileSourceDto.getDataHash()).isEqualTo("e41cca9c51ff853c748f708f39dfc035");
}
FileSourceDto fileSourceDto = new FileSourceDao(getMyBatis()).select("uuidnew");
assertThat(fileSourceDto.getCreatedAt()).isEqualTo(now);
assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(now);
- assertThat(fileSourceDto.getStringData()).isEqualTo(
+ assertThat(fileSourceDto.getData()).isEqualTo(
",,,,foo\r\n,,,,bar\r\n,,,,biz\r\n");
assertThat(fileSourceDto.getDataHash()).isEqualTo("0c43ed6418d690ee0ffc3e43e6660967");
FileSourceDto fileSourceDto = new FileSourceDao(getMyBatis()).select("uuidnew");
assertThat(fileSourceDto.getCreatedAt()).isEqualTo(now);
assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(now);
- assertThat(fileSourceDto.getStringData()).isEqualTo(
+ assertThat(fileSourceDto.getData()).isEqualTo(
"123,julien,2014-10-11T16:44:02+0100,\"0,3,a\",foo\r\n"
+ "234,simon,2014-10-12T16:44:02+0100,\"0,1,cd\",bar\r\n"
+ "345,julien,2014-10-13T16:44:02+0100,\"0,9,c\",biz\r\n");
*/
package org.sonar.core.source.db;
-import com.google.common.base.Charsets;
-
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-
import java.util.Date;
public class FileSourceDto {
private String fileUuid;
private Date createdAt;
private Date updatedAt;
- private byte[] data;
+ private String data;
private String dataHash;
public Long getId() {
}
@CheckForNull
- public byte[] getData() {
+ public String getData() {
return data;
}
- @CheckForNull
- public String getStringData() {
- return data != null ? new String(data, Charsets.UTF_8) : null;
- }
-
- public FileSourceDto setData(@Nullable byte[] data) {
+ public FileSourceDto setData(@Nullable String data) {
this.data = data;
return this;
}
- public FileSourceDto setStringData(@Nullable String data) {
- return setData(data != null ? data.getBytes(Charsets.UTF_8) : null);
- }
-
public String getDataHash() {
return dataHash;
}
public void select() throws Exception {
FileSourceDto fileSourceDto = dao.select("ab12");
- assertThat(fileSourceDto.getStringData()).isEqualTo("public class Foo {public Foo(){}}");
+ assertThat(fileSourceDto.getData()).isEqualTo("aef12a,alice,2014-04-25T12:34:56+0100,,class Foo");
assertThat(fileSourceDto.getDataHash()).isEqualTo("hash");
assertThat(fileSourceDto.getProjectUuid()).isEqualTo("abcd");
assertThat(fileSourceDto.getFileUuid()).isEqualTo("ab12");
@Test
public void insert() throws Exception {
- dao.insert(new FileSourceDto().setProjectUuid("prj").setFileUuid("file").setStringData("bla bla").setDataHash("hash2")
+ dao.insert(new FileSourceDto().setProjectUuid("prj").setFileUuid("file").setData("bla bla").setDataHash("hash2")
.setCreatedAt(DateUtils.parseDateTime("2014-10-31T16:44:02+0100"))
.setUpdatedAt(DateUtils.parseDateTime("2014-10-31T16:44:02+0100")));
@Test
public void update() throws Exception {
- dao.update(new FileSourceDto().setId(101L).setProjectUuid("prj").setFileUuid("file").setStringData("bla bla").setDataHash("hash2")
+ dao.update(new FileSourceDto().setId(101L).setProjectUuid("prj").setFileUuid("file").setData("updated data").setDataHash("hash2")
.setUpdatedAt(DateUtils.parseDateTime("2014-10-31T16:44:02+0100")));
checkTable("update", "file_sources");
<dataset>
- <file_sources id="101" project_uuid="abcd" file_uuid="ab12" data="7075626c696320636c61737320466f6f207b7075626c696320466f6f28297b7d7d" data_hash="hash" created_at="2014-10-29 16:44:02.000" updated_at="2014-10-30 16:44:02.000" />
+ <file_sources id="101" project_uuid="abcd" file_uuid="ab12"
+ data="aef12a,alice,2014-04-25T12:34:56+0100,,class Foo" data_hash="hash"
+ created_at="2014-10-29 16:44:02.000" updated_at="2014-10-30 16:44:02.000" />
- <file_sources id="102" project_uuid="prj" file_uuid="file" data="626c6120626c61" data_hash="hash2" created_at="2014-10-31 16:44:02.000" updated_at="2014-10-31 16:44:02.000" />
+
+ <file_sources id="102" project_uuid="prj" file_uuid="file"
+ data="bla bla" data_hash="hash2"
+ created_at="2014-10-31 16:44:02.000" updated_at="2014-10-31 16:44:02.000" />
</dataset>
<dataset>
- <file_sources id="101" project_uuid="abcd" file_uuid="ab12" data="7075626c696320636c61737320466f6f207b7075626c696320466f6f28297b7d7d" data_hash="hash" created_at="2014-10-29 16:44:02.000" updated_at="2014-10-30 16:44:02.000" />
+ <file_sources id="101" project_uuid="abcd" file_uuid="ab12"
+ data="aef12a,alice,2014-04-25T12:34:56+0100,,class Foo" data_hash="hash"
+ created_at="2014-10-29 16:44:02.000" updated_at="2014-10-30 16:44:02.000" />
</dataset>
<dataset>
- <file_sources id="101" project_uuid="abcd" file_uuid="ab12" data="626c6120626c61" data_hash="hash2" created_at="2014-10-29 16:44:02.000" updated_at="2014-10-31 16:44:02.000" />
+ <file_sources id="101" project_uuid="abcd" file_uuid="ab12"
+ data="updated data" data_hash="hash2"
+ created_at="2014-10-29 16:44:02.000" updated_at="2014-10-31 16:44:02.000" />
+
</dataset>