From 52fb67b35cfa29db1cc69624d57e10eed359bbbf Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Mon, 19 Oct 2020 17:14:37 +0100 Subject: [PATCH] use Timestamp intead of java.sql.Date --- .../com/muwire/core/hostcache/H2HostCache.groovy | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/core/src/main/groovy/com/muwire/core/hostcache/H2HostCache.groovy b/core/src/main/groovy/com/muwire/core/hostcache/H2HostCache.groovy index 2afb74e9..dea1f270 100644 --- a/core/src/main/groovy/com/muwire/core/hostcache/H2HostCache.groovy +++ b/core/src/main/groovy/com/muwire/core/hostcache/H2HostCache.groovy @@ -3,6 +3,8 @@ package com.muwire.core.hostcache import java.util.function.Predicate import java.util.function.Supplier +import java.text.SimpleDateFormat + import com.muwire.core.MuWireSettings import com.muwire.core.connection.ConnectionAttemptStatus import com.muwire.core.trust.TrustService @@ -14,6 +16,7 @@ import groovy.util.logging.Log @Log class H2HostCache extends HostCache { + private static final SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS") private Sql sql private final File h2Home private final File home @@ -28,7 +31,7 @@ class H2HostCache extends HostCache { private final Timer timer - private Collection toVerify = new HashSet<>() + private Collection toVerify = new LinkedHashSet<>() public H2HostCache(File home, TrustService trustService, MuWireSettings settings, Destination myself) { super(trustService, settings, myself) @@ -54,7 +57,8 @@ class H2HostCache extends HostCache { hosts.remove(d) // record into db - def timestamp = new java.sql.Date(System.currentTimeMillis()) + def timestamp = new Date(System.currentTimeMillis()) + timestamp = SDF.format(timestamp) sql.execute("insert into HOST_ATTEMPTS values ('${d.toBase64()}', '$timestamp', '${status.name()}');") // and re-rank @@ -137,7 +141,8 @@ class H2HostCache extends HostCache { long timestamp = System.currentTimeMillis() if (entry.lastSuccessfulAttempt != null) timestamp = entry.lastSuccessfulAttempt - def tstamp = new java.sql.Date(timestamp) + def tstamp = Date(timestamp) + tstamp = SDF.format(tstamp) sql.execute("insert into HOST_ATTEMPTS VALUES ('${dest.toBase64()}', '$tstamp', 'SUCCESSFUL')") } hostsJson.renameTo(new File(home, "hosts.json.bak"))