diff --git a/common/src/main/java/google/registry/util/DateTimeUtils.java b/common/src/main/java/google/registry/util/DateTimeUtils.java
index 362e8118e..ca18dfece 100644
--- a/common/src/main/java/google/registry/util/DateTimeUtils.java
+++ b/common/src/main/java/google/registry/util/DateTimeUtils.java
@@ -24,6 +24,7 @@ import java.time.ZonedDateTime;
import java.util.TimeZone;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
+import org.joda.time.LocalDate;
/** Utilities methods and constants related to Joda {@link DateTime} objects. */
public class DateTimeUtils {
@@ -108,4 +109,12 @@ public class DateTimeUtils {
zonedDateTime.toInstant().toEpochMilli(),
DateTimeZone.forTimeZone(TimeZone.getTimeZone(zonedDateTime.getZone())));
}
+
+ public static java.sql.Date toSqlDate(LocalDate localDate) {
+ return new java.sql.Date(localDate.toDateTimeAtStartOfDay().getMillis());
+ }
+
+ public static LocalDate toLocalDate(java.sql.Date date) {
+ return new LocalDate(date.getTime(), DateTimeZone.UTC);
+ }
}
diff --git a/core/src/main/java/google/registry/model/reporting/Spec11ThreatMatch.java b/core/src/main/java/google/registry/model/reporting/Spec11ThreatMatch.java
index 592823325..1e1027fc0 100644
--- a/core/src/main/java/google/registry/model/reporting/Spec11ThreatMatch.java
+++ b/core/src/main/java/google/registry/model/reporting/Spec11ThreatMatch.java
@@ -75,7 +75,7 @@ public class Spec11ThreatMatch extends ImmutableObject implements Buildable, Sql
String registrarId;
/** Date on which the check was run, on which the domain was flagged as abusive. */
- @Column(nullable = false)
+ @Column(nullable = false, columnDefinition = "date")
LocalDate checkDate;
/** The domain's top-level domain. */
diff --git a/core/src/main/java/google/registry/model/reporting/Spec11ThreatMatchDao.java b/core/src/main/java/google/registry/model/reporting/Spec11ThreatMatchDao.java
index 92531a8a1..29f2c2498 100644
--- a/core/src/main/java/google/registry/model/reporting/Spec11ThreatMatchDao.java
+++ b/core/src/main/java/google/registry/model/reporting/Spec11ThreatMatchDao.java
@@ -16,23 +16,25 @@ package google.registry.model.reporting;
import com.google.common.collect.ImmutableList;
import google.registry.persistence.transaction.JpaTransactionManager;
+import google.registry.util.DateTimeUtils;
+import javax.persistence.TemporalType;
import org.joda.time.LocalDate;
/**
* Data access object for {@link google.registry.model.reporting.Spec11ThreatMatch}.
*
*
A JpaTransactionManager is passed into each static method because they are called from a BEAM
- * pipeline and we don't know where it's coming from.
+ * pipeline and we don't know where it's coming from.
*/
public class Spec11ThreatMatchDao {
-
+
/** Delete all entries with the specified date from the database. */
public static void deleteEntriesByDate(JpaTransactionManager jpaTm, LocalDate date) {
jpaTm.assertInTransaction();
jpaTm
.getEntityManager()
.createQuery("DELETE FROM Spec11ThreatMatch WHERE check_date = :date")
- .setParameter("date", date.toString())
+ .setParameter("date", DateTimeUtils.toSqlDate(date), TemporalType.DATE)
.executeUpdate();
}
diff --git a/core/src/main/java/google/registry/persistence/converter/LocalDateConverter.java b/core/src/main/java/google/registry/persistence/converter/LocalDateConverter.java
index 1721733c0..2ed7e6a40 100644
--- a/core/src/main/java/google/registry/persistence/converter/LocalDateConverter.java
+++ b/core/src/main/java/google/registry/persistence/converter/LocalDateConverter.java
@@ -14,17 +14,23 @@
package google.registry.persistence.converter;
+import google.registry.util.DateTimeUtils;
+import java.sql.Date;
+import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
import org.joda.time.LocalDate;
-import org.joda.time.format.ISODateTimeFormat;
-/** JPA converter for {@link LocalDate}. */
+/** JPA converter for {@link LocalDate}, to/from {@link Date}. */
@Converter(autoApply = true)
-public class LocalDateConverter extends ToStringConverterBase {
+public class LocalDateConverter implements AttributeConverter {
- /** Converts the string (a date in ISO-8601 format) into a LocalDate. */
@Override
- public LocalDate convertToEntityAttribute(String columnValue) {
- return (columnValue == null) ? null : LocalDate.parse(columnValue, ISODateTimeFormat.date());
+ public Date convertToDatabaseColumn(LocalDate attribute) {
+ return attribute == null ? null : DateTimeUtils.toSqlDate(attribute);
+ }
+
+ @Override
+ public LocalDate convertToEntityAttribute(Date dbData) {
+ return dbData == null ? null : DateTimeUtils.toLocalDate(dbData);
}
}
diff --git a/core/src/test/java/google/registry/model/reporting/Spec11ThreatMatchDaoTest.java b/core/src/test/java/google/registry/model/reporting/Spec11ThreatMatchDaoTest.java
index 7ff9387b2..57710a1bc 100644
--- a/core/src/test/java/google/registry/model/reporting/Spec11ThreatMatchDaoTest.java
+++ b/core/src/test/java/google/registry/model/reporting/Spec11ThreatMatchDaoTest.java
@@ -92,15 +92,13 @@ public class Spec11ThreatMatchDaoTest extends EntityTestCase {
}
private Spec11ThreatMatch createThreatMatch(String domainName, LocalDate date) {
- Spec11ThreatMatch threatMatch =
- new Spec11ThreatMatch()
- .asBuilder()
- .setThreatTypes(ImmutableSet.of(ThreatType.MALWARE))
- .setCheckDate(date)
- .setDomainName(domainName)
- .setRegistrarId("Example Registrar")
- .setDomainRepoId("1-COM")
- .build();
- return threatMatch;
+ return new Spec11ThreatMatch()
+ .asBuilder()
+ .setThreatTypes(ImmutableSet.of(ThreatType.MALWARE))
+ .setCheckDate(date)
+ .setDomainName(domainName)
+ .setRegistrarId("Example Registrar")
+ .setDomainRepoId("1-COM")
+ .build();
}
}
diff --git a/db/src/main/resources/sql/er_diagram/brief_er_diagram.html b/db/src/main/resources/sql/er_diagram/brief_er_diagram.html
index 00a74c346..fc9083f0f 100644
--- a/db/src/main/resources/sql/er_diagram/brief_er_diagram.html
+++ b/db/src/main/resources/sql/er_diagram/brief_er_diagram.html
@@ -261,2222 +261,2222 @@ td.section {
generated on |
- 2020-10-15 19:26:20.831826 |
+ 2020-10-19 18:49:22.440463 |
last flyway file |
- V64__transfer_history_columns.sql |
+ V65__local_date_date_type.sql |
-