update.setString(1, projectUuid)
.setString(2, fileUuid)
- .setDate(3, now)
- .setDate(4, updatedAt == null ? now : updatedAt)
+ .setLong(3, now.getTime())
+ .setLong(4, (updatedAt == null ? now : updatedAt).getTime())
.setString(5, sourceData)
.setString(6, "");
// use cache. Will not work with Tomcat cluster.
result = lastUpdatedAt;
}
+ System.out.println("\n\n"
+ + " Checking for source lines > " + result
+ + "\n\n");
return result;
}
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;
private static final String SQL_ALL = "select " + StringUtils.join(FIELDS, ",") + " from file_sources";
- private static final String SQL_AFTER_DATE = SQL_ALL + " where updated_at>=?";
+ private static final String SQL_AFTER_DATE = SQL_ALL + " where updated_at>?";
static SourceLineResultSetIterator create(DbClient dbClient, Connection connection, long afterDate) {
try {
String sql = afterDate > 0L ? SQL_AFTER_DATE : SQL_ALL;
PreparedStatement stmt = dbClient.newScrollingSelectStatement(connection, sql);
if (afterDate > 0L) {
- stmt.setTimestamp(1, new Timestamp(afterDate));
+ stmt.setLong(1, afterDate);
}
+ System.out.println(sql);
return new SourceLineResultSetIterator(stmt);
} catch (SQLException e) {
throw new IllegalStateException("Fail to prepare SQL request to select all file sources", e);
protected Collection<SourceLineDoc> read(ResultSet rs) throws SQLException {
String projectUuid = rs.getString(1);
String fileUuid = rs.getString(2);
- Date updatedAt = SqlUtil.getDate(rs, 4);
+ Date updatedAt = new Date(SqlUtil.getLong(rs, 4));
int line = 1;
List<SourceLineDoc> lines = Lists.newArrayList();
db.prepareDbUnit(getClass(), "source-with-scm.xml");
SourceLineResultSetIterator iterator = SourceLineResultSetIterator.create(dbClient, db.openConnection(),
- DateUtils.parseDateTime("2014-11-01T16:44:02+0100").getTime());
+ DateUtils.parseDateTime("2014-11-17T16:44:02+0100").getTime());
assertThat(iterator.hasNext()).isFalse();
}
<dataset>
- <file_sources id="1" project_uuid="uuid-MyProject" file_uuid="uuid-MyFile.xoo" created_at="2014-11-17 16:27:00.000" updated_at="2014-10-31 16:44:02.000"
+ <file_sources id="1" project_uuid="uuid-MyProject" file_uuid="uuid-MyFile.xoo" created_at="1416238020000" updated_at="1414770242000"
data="aef12a,alice,2014-04-25T12:34:56+0100,,class Foo { abe465,bob,2014-07-25T12:34:56+0100,, // Empty afb789,carol,2014-03-23T12:34:56+0100,,} afb789,carol,2014-03-23T12:34:56+0100,, " data_hash="" />
</dataset>
<dataset>
- <file_sources id="1" project_uuid="uuid-MyProject" file_uuid="uuid-MyFile.xoo" created_at="2014-11-17 16:27:00.000" updated_at="2014-10-31 16:44:02.000"
+ <file_sources id="1" project_uuid="uuid-MyProject" file_uuid="uuid-MyFile.xoo" created_at="1416238020000" updated_at="1414770242000"
data=",,,,class Foo { ,,,, // Empty ,,,,} ,,,, " data_hash="" />
</dataset>
"FILE_UUID" VARCHAR(50) NOT NULL,
"DATA" CLOB(2147483647),
"DATA_HASH" VARCHAR(50) NOT NULL,
- "CREATED_AT" TIMESTAMP NOT NULL,
- "UPDATED_AT" TIMESTAMP NOT NULL
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL
);
"FILE_UUID" VARCHAR(50) NOT NULL,
"DATA" CLOB(2147483647),
"DATA_HASH" VARCHAR(50) NOT NULL,
- "CREATED_AT" TIMESTAMP NOT NULL,
- "UPDATED_AT" TIMESTAMP NOT NULL
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL
);
<dataset>
- <file_sources id="1" project_uuid="uuid-MyProject" file_uuid="uuid-MyFile.xoo" created_at="2014-11-17 16:27:00.000" updated_at="2014-10-31 16:44:02.000"
+ <file_sources id="1" project_uuid="uuid-MyProject" file_uuid="uuid-MyFile.xoo" created_at="1416238020000" updated_at="1416239042000"
data="" data_hash="" />
</dataset>
t.column :file_uuid, :string, :limit => 50, :null => false
t.column :data, :text, :null => true
t.column :data_hash, :string, :limit => 50, :null => true
- t.column :created_at, :datetime, :null => false
- t.column :updated_at, :datetime, :null => false
+ t.column :created_at, :integer, :limit => 8, :null => false
+ t.column :updated_at, :integer, :limit => 8, :null => false
end
if dialect()=='mysql'
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import static com.google.common.base.Charsets.UTF_8;
if (previous == null) {
FileSourceDto newFileSource = new FileSourceDto().setProjectUuid(projectTree.getRootProject().getUuid()).setFileUuid(fileUuid).setData(newData)
.setDataHash(newDataHash)
- .setCreatedAt(now)
- .setUpdatedAt(now);
+ .setCreatedAt(now.getTime())
+ .setUpdatedAt(now.getTime());
mapper.insert(newFileSource);
session.commit();
} else {
if (!newDataHash.equals(previous.getDataHash())) {
- previous.setData(newData).setDataHash(newDataHash).setUpdatedAt(now);
+ previous.setData(newData).setDataHash(newDataHash).setUpdatedAt(now.getTime());
mapper.update(previous);
session.commit();
}
sourcePersister.persist();
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.getCreatedAt()).isEqualTo(DateUtils.parseDateTime("2014-10-10T16:44:02+0200").getTime());
+ assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(now.getTime());
assertThat(fileSourceDto.getData()).isEqualTo(
",,,,changed\r\n,,,,content\r\n");
assertThat(fileSourceDto.getDataHash()).isEqualTo("e41cca9c51ff853c748f708f39dfc035");
sourcePersister.persist();
FileSourceDto fileSourceDto = new FileSourceDao(getMyBatis()).select("uuidnew");
- assertThat(fileSourceDto.getCreatedAt()).isEqualTo(now);
- assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(now);
+ assertThat(fileSourceDto.getCreatedAt()).isEqualTo(now.getTime());
+ assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(now.getTime());
assertThat(fileSourceDto.getData()).isEqualTo(
",,,,foo\r\n,,,,bar\r\n,,,,biz\r\n");
assertThat(fileSourceDto.getDataHash()).isEqualTo("0c43ed6418d690ee0ffc3e43e6660967");
sourcePersister.persist();
FileSourceDto fileSourceDto = new FileSourceDao(getMyBatis()).select("uuidnew");
- assertThat(fileSourceDto.getCreatedAt()).isEqualTo(now);
- assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(now);
+ assertThat(fileSourceDto.getCreatedAt()).isEqualTo(now.getTime());
+ assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(now.getTime());
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"
<dataset>
- <file_sources id="101" project_uuid="projectUuid" file_uuid="uuidsame" data=",,,,unchanged ,,,,content " data_hash="ee716d4ed9faae16eb9167714442a3bc" created_at="2014-10-10 16:44:02.000" updated_at="2014-10-10 16:44:02.000" />
+ <file_sources id="101" project_uuid="projectUuid" file_uuid="uuidsame" data=",,,,unchanged ,,,,content " data_hash="ee716d4ed9faae16eb9167714442a3bc" created_at="1412952242000" updated_at="1412952242000" />
</dataset>
<dataset>
- <file_sources id="101" project_uuid="projectUuid" file_uuid="uuidsame" data=",,,,unchanged ,,,,content " data_hash="ee716d4ed9faae16eb9167714442a3bc" created_at="2014-10-10 16:44:02.000" updated_at="2014-10-10 16:44:02.000" />
+ <file_sources id="101" project_uuid="projectUuid" file_uuid="uuidsame" data=",,,,unchanged ,,,,content " data_hash="ee716d4ed9faae16eb9167714442a3bc" created_at="1412952242000" updated_at="1412952242000" />
</dataset>
<dataset>
- <file_sources id="101" project_uuid="projectUuid" file_uuid="uuidsame" data=",,,,unchanged ,,,,content " data_hash="ee716d4ed9faae16eb9167714442a3bc" created_at="2014-10-10 16:44:02.000" updated_at="2014-10-10 16:44:02.000" />
- <file_sources id="102" project_uuid="projectUuid" file_uuid="uuidempty" data="[null]" data_hash="0" created_at="2014-10-29 16:44:02.000" updated_at="2014-10-29 16:44:02.000" />
+ <file_sources id="101" project_uuid="projectUuid" file_uuid="uuidsame" data=",,,,unchanged ,,,,content " data_hash="ee716d4ed9faae16eb9167714442a3bc" created_at="1412952242000" updated_at="1412952242000" />
+ <file_sources id="102" project_uuid="projectUuid" file_uuid="uuidempty" data="[null]" data_hash="0" created_at="1414597442000" updated_at="1414597442000" />
</dataset>
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-import java.util.Date;
public class FileSourceDto {
private Long id;
private String projectUuid;
private String fileUuid;
- private Date createdAt;
- private Date updatedAt;
+ private long createdAt;
+ private long updatedAt;
private String data;
private String dataHash;
return this;
}
- public Date getCreatedAt() {
+ public long getCreatedAt() {
return createdAt;
}
- public FileSourceDto setCreatedAt(Date createdAt) {
+ public FileSourceDto setCreatedAt(long createdAt) {
this.createdAt = createdAt;
return this;
}
- public Date getUpdatedAt() {
+ public long getUpdatedAt() {
return updatedAt;
}
- public FileSourceDto setUpdatedAt(Date updatedAt) {
+ public FileSourceDto setUpdatedAt(long updatedAt) {
this.updatedAt = updatedAt;
return this;
}
"FILE_UUID" VARCHAR(50) NOT NULL,
"DATA" CLOB(2147483647),
"DATA_HASH" VARCHAR(50) NOT NULL,
- "CREATED_AT" TIMESTAMP NOT NULL,
- "UPDATED_AT" TIMESTAMP NOT NULL
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL
);
-- ----------------------------------------------
import org.sonar.api.utils.DateUtils;
import org.sonar.core.persistence.AbstractDaoTestCase;
+import java.util.Date;
+
import static org.fest.assertions.Assertions.assertThat;
public class FileSourceDaoTest extends AbstractDaoTestCase {
assertThat(fileSourceDto.getDataHash()).isEqualTo("hash");
assertThat(fileSourceDto.getProjectUuid()).isEqualTo("abcd");
assertThat(fileSourceDto.getFileUuid()).isEqualTo("ab12");
- assertThat(fileSourceDto.getCreatedAt()).isEqualTo(DateUtils.parseDateTime("2014-10-29T16:44:02+0100"));
- assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(DateUtils.parseDateTime("2014-10-30T16:44:02+0100"));
+ assertThat(new Date(fileSourceDto.getCreatedAt())).isEqualTo(DateUtils.parseDateTime("2014-10-29T16:44:02+0100"));
+ assertThat(new Date(fileSourceDto.getUpdatedAt())).isEqualTo(DateUtils.parseDateTime("2014-10-30T16:44:02+0100"));
}
@Test
public void insert() throws Exception {
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")));
+ .setCreatedAt(DateUtils.parseDateTime("2014-10-31T16:44:02+0100").getTime())
+ .setUpdatedAt(DateUtils.parseDateTime("2014-10-31T16:44:02+0100").getTime()));
checkTable("insert", "file_sources");
}
@Test
public void update() throws Exception {
dao.update(new FileSourceDto().setId(101L).setProjectUuid("prj").setFileUuid("file").setData("updated data").setDataHash("hash2")
- .setUpdatedAt(DateUtils.parseDateTime("2014-10-31T16:44:02+0100")));
+ .setUpdatedAt(DateUtils.parseDateTime("2014-10-31T16:44:02+0100").getTime()));
checkTable("update", "file_sources");
}
<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" />
+ created_at="1414597442000" updated_at="1414683842000" />
<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" />
+ created_at="1414770242000" updated_at="1414770242000" />
</dataset>
<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" />
+ created_at="1414597442000" updated_at="1414683842000" />
</dataset>
<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" />
+ created_at="1414597442000" updated_at="1414770242000" />
</dataset>