Fix date issue (time lost).

This commit is contained in:
Christian P. MOMON 2013-09-06 01:14:28 +02:00
parent a84a4ca321
commit 38c415f670
3 changed files with 39 additions and 36 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
/bin
/build
/dist

View file

@ -108,7 +108,7 @@ public class SQLSikevaDB implements SikevaDB {
connection.setAutoCommit(true);
statement = connection.prepareStatement("UPDATE elements SET ARCHIVE_DATE=? WHERE TOPKEY=? AND SUBKEY IS NULL");
statement.setDate(1, dateToDate(element.getArchiveDate()));
statement.setTimestamp(1, dateToTimestamp(element.getArchiveDate()));
statement.setString(2, element.getKey());
statement.executeUpdate();
@ -147,7 +147,7 @@ public class SQLSikevaDB implements SikevaDB {
connection.setAutoCommit(true);
statement = connection.prepareStatement("UPDATE elements SET ARCHIVE_DATE=? WHERE TOPKEY=? AND SUBKEY=?");
statement.setDate(1, dateToDate(element.getArchiveDate()));
statement.setTimestamp(1, dateToTimestamp(element.getArchiveDate()));
statement.setString(2, element.getKey());
statement.setString(3, element.getSubkey());
@ -200,7 +200,7 @@ public class SQLSikevaDB implements SikevaDB {
connection.setAutoCommit(true);
statement = connection.prepareStatement("DELETE FROM elements WHERE ARCHIVE_DATE<?");
statement.setDate(1, dateToDate(beforeDate));
statement.setTimestamp(1, dateToTimestamp(beforeDate));
statement.executeUpdate();
@ -599,9 +599,9 @@ public class SQLSikevaDB implements SikevaDB {
element.setValue(resultSet.getString(3));
element.setSize(resultSet.getLong(4));
element.setDigest(resultSet.getString(5));
element.setCreationDate(dateToDate(resultSet.getDate(6)));
element.setEditionDate(dateToDate(resultSet.getDate(7)));
element.setArchiveDate(dateToDate(resultSet.getDate(8)));
element.setCreationDate(timestampToDate(resultSet.getTimestamp(6)));
element.setEditionDate(timestampToDate(resultSet.getTimestamp(7)));
element.setArchiveDate(timestampToDate(resultSet.getTimestamp(8)));
//
result.add(element);
@ -650,9 +650,9 @@ public class SQLSikevaDB implements SikevaDB {
element.setValue(resultSet.getString(3));
element.setSize(resultSet.getLong(4));
element.setDigest(resultSet.getString(5));
element.setCreationDate(dateToDate(resultSet.getDate(6)));
element.setEditionDate(dateToDate(resultSet.getDate(7)));
element.setArchiveDate(dateToDate(resultSet.getDate(8)));
element.setCreationDate(timestampToDate(resultSet.getTimestamp(6)));
element.setEditionDate(timestampToDate(resultSet.getTimestamp(7)));
element.setArchiveDate(timestampToDate(resultSet.getTimestamp(8)));
//
result.add(element);
@ -940,9 +940,9 @@ public class SQLSikevaDB implements SikevaDB {
result.setValue(resultSet.getString(3));
result.setSize(resultSet.getLong(4));
result.setDigest(resultSet.getString(5));
result.setCreationDate(dateToDate(resultSet.getDate(6)));
result.setEditionDate(dateToDate(resultSet.getDate(7)));
result.setArchiveDate(dateToDate(resultSet.getDate(8)));
result.setCreationDate(timestampToDate(resultSet.getTimestamp(6)));
result.setEditionDate(timestampToDate(resultSet.getTimestamp(7)));
result.setArchiveDate(timestampToDate(resultSet.getTimestamp(8)));
} else {
result = null;
@ -995,9 +995,9 @@ public class SQLSikevaDB implements SikevaDB {
result.setValue(resultSet.getString(3));
result.setSize(resultSet.getLong(4));
result.setDigest(resultSet.getString(5));
result.setCreationDate(dateToDate(resultSet.getDate(6)));
result.setEditionDate(dateToDate(resultSet.getDate(7)));
result.setArchiveDate(dateToDate(resultSet.getDate(8)));
result.setCreationDate(timestampToDate(resultSet.getTimestamp(6)));
result.setEditionDate(timestampToDate(resultSet.getTimestamp(7)));
result.setArchiveDate(timestampToDate(resultSet.getTimestamp(8)));
} else {
result = null;
}
@ -1046,9 +1046,9 @@ public class SQLSikevaDB implements SikevaDB {
element.setValue(resultSet.getString(3));
element.setSize(resultSet.getLong(4));
element.setDigest(resultSet.getString(5));
element.setCreationDate(dateToDate(resultSet.getDate(6)));
element.setEditionDate(dateToDate(resultSet.getDate(7)));
element.setArchiveDate(dateToDate(resultSet.getDate(8)));
element.setCreationDate(timestampToDate(resultSet.getTimestamp(6)));
element.setEditionDate(timestampToDate(resultSet.getTimestamp(7)));
element.setArchiveDate(timestampToDate(resultSet.getTimestamp(8)));
//
result.add(element);
@ -1097,9 +1097,9 @@ public class SQLSikevaDB implements SikevaDB {
element.setValue(resultSet.getString(3));
element.setSize(resultSet.getLong(4));
element.setDigest(resultSet.getString(5));
element.setCreationDate(dateToDate(resultSet.getDate(6)));
element.setEditionDate(dateToDate(resultSet.getDate(7)));
element.setArchiveDate(dateToDate(resultSet.getDate(8)));
element.setCreationDate(timestampToDate(resultSet.getTimestamp(6)));
element.setEditionDate(timestampToDate(resultSet.getTimestamp(7)));
element.setArchiveDate(timestampToDate(resultSet.getTimestamp(8)));
//
result.add(element);
@ -1585,9 +1585,9 @@ public class SQLSikevaDB implements SikevaDB {
statement.setString(3, element.getValue());
statement.setLong(4, element.getSize());
statement.setString(5, element.getDigest());
statement.setDate(6, dateToDate(element.getCreationDate()));
statement.setDate(7, dateToDate(element.getEditionDate()));
statement.setDate(8, dateToDate(element.getArchiveDate()));
statement.setTimestamp(6, new java.sql.Timestamp(element.getCreationDate().getTime()));
statement.setTimestamp(7, dateToTimestamp(element.getEditionDate()));
statement.setTimestamp(8, dateToTimestamp(element.getArchiveDate()));
statement.executeUpdate();
@ -1629,7 +1629,7 @@ public class SQLSikevaDB implements SikevaDB {
// Archive existing element.
statement = connection.prepareStatement("UPDATE elements SET ARCHIVE_DATE=? WHERE TOPKEY=? AND SUBKEY IS NULL");
statement.setDate(1, dateToDate(element.getEditionDate()));
statement.setTimestamp(1, dateToTimestamp(element.getEditionDate()));
statement.setString(2, element.getKey());
statement.executeUpdate();
@ -1645,9 +1645,9 @@ public class SQLSikevaDB implements SikevaDB {
statement.setString(3, element.getValue());
statement.setLong(4, element.getSize());
statement.setString(5, element.getDigest());
statement.setDate(6, dateToDate(element.getCreationDate()));
statement.setDate(7, dateToDate(element.getEditionDate()));
statement.setDate(8, dateToDate(element.getArchiveDate()));
statement.setTimestamp(6, dateToTimestamp(element.getCreationDate()));
statement.setTimestamp(7, dateToTimestamp(element.getEditionDate()));
statement.setTimestamp(8, dateToTimestamp(element.getArchiveDate()));
statement.executeUpdate();
@ -1698,7 +1698,7 @@ public class SQLSikevaDB implements SikevaDB {
// Archive existing element.
statement = connection.prepareStatement("UPDATE elements SET ARCHIVE_DATE=? WHERE TOPKEY=? AND SUBKEY=?");
statement.setDate(1, dateToDate(element.getEditionDate()));
statement.setTimestamp(1, dateToTimestamp(element.getEditionDate()));
statement.setString(2, element.getKey());
statement.setString(3, element.getSubkey());
@ -1715,9 +1715,9 @@ public class SQLSikevaDB implements SikevaDB {
statement.setString(3, element.getValue());
statement.setLong(4, element.getSize());
statement.setString(5, element.getDigest());
statement.setDate(6, dateToDate(element.getCreationDate()));
statement.setDate(7, dateToDate(element.getEditionDate()));
statement.setDate(8, dateToDate(element.getArchiveDate()));
statement.setTimestamp(6, dateToTimestamp(element.getCreationDate()));
statement.setTimestamp(7, dateToTimestamp(element.getEditionDate()));
statement.setTimestamp(8, dateToTimestamp(element.getArchiveDate()));
statement.executeUpdate();
@ -1854,13 +1854,13 @@ public class SQLSikevaDB implements SikevaDB {
* @param source
* @return
*/
public static java.sql.Date dateToDate(final Date source) {
java.sql.Date result;
public static java.sql.Timestamp dateToTimestamp(final Date source) {
java.sql.Timestamp result;
if (source == null) {
result = null;
} else {
result = new java.sql.Date(source.getTime());
result = new java.sql.Timestamp(source.getTime());
}
//
@ -1872,7 +1872,7 @@ public class SQLSikevaDB implements SikevaDB {
* @param source
* @return
*/
public static Date dateToDate(final java.sql.Date source) {
public static Date timestampToDate(final java.sql.Timestamp source) {
Date result;
if (source == null) {