Fix date issue.

This commit is contained in:
Christian P. MOMON 2013-09-11 01:06:59 +02:00
parent 2863aee6fa
commit 1a25aab328

View file

@ -186,6 +186,7 @@ public class SQLSikevaDB implements SikevaDB {
*/ */
@Override @Override
public void clearArchive(final Date beforeDate) throws SQLException { public void clearArchive(final Date beforeDate) throws SQLException {
//
if (beforeDate == null) { if (beforeDate == null) {
throw new NullPointerException("beforeDate is null."); throw new NullPointerException("beforeDate is null.");
} else { } else {
@ -197,9 +198,9 @@ public class SQLSikevaDB implements SikevaDB {
// //
connection = getConnection(); connection = getConnection();
connection.setAutoCommit(true); connection.setAutoCommit(true);
statement = connection.prepareStatement("DELETE FROM elements WHERE ARCHIVE_DATE<?"); statement = connection.prepareStatement("DELETE FROM elements WHERE ARCHIVE_DATE IS NOT NULL AND TO_SECONDS(ARCHIVE_DATE)<?");
statement.setTimestamp(1, dateToTimestamp(beforeDate)); statement.setLong(1, beforeDate.getTime() / 1000);
statement.executeUpdate(); statement.executeUpdate();
@ -214,6 +215,10 @@ public class SQLSikevaDB implements SikevaDB {
*/ */
@Override @Override
public void clearArchive(final int maxDays) throws SQLException { public void clearArchive(final int maxDays) throws SQLException {
//
logger.debug("maxDays={}", maxDays);
//
if (maxDays < 0) { if (maxDays < 0) {
throw new IndexOutOfBoundsException("maxDays is negative."); throw new IndexOutOfBoundsException("maxDays is negative.");
} else { } else {