diff --git a/core/src/main/java/google/registry/model/CreateAutoTimestamp.java b/core/src/main/java/google/registry/model/CreateAutoTimestamp.java index 606e3a13e..9aece0d27 100644 --- a/core/src/main/java/google/registry/model/CreateAutoTimestamp.java +++ b/core/src/main/java/google/registry/model/CreateAutoTimestamp.java @@ -14,8 +14,20 @@ package google.registry.model; +import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; + +import com.googlecode.objectify.annotation.Ignore; +import com.googlecode.objectify.annotation.OnLoad; import google.registry.model.translators.CreateAutoTimestampTranslatorFactory; +import google.registry.util.DateTimeUtils; +import java.time.ZonedDateTime; import javax.annotation.Nullable; +import javax.persistence.Column; +import javax.persistence.Embeddable; +import javax.persistence.PostLoad; +import javax.persistence.PrePersist; +import javax.persistence.PreUpdate; +import javax.persistence.Transient; import org.joda.time.DateTime; /** @@ -23,9 +35,37 @@ import org.joda.time.DateTime; * * @see CreateAutoTimestampTranslatorFactory */ +@Embeddable public class CreateAutoTimestamp extends ImmutableObject implements UnsafeSerializable { - DateTime timestamp; + @Transient DateTime timestamp; + + @Column(nullable = false) + @Ignore + ZonedDateTime creationTime; + + @PrePersist + @PreUpdate + void setTimestamp() { + if (creationTime == null) { + timestamp = jpaTm().getTransactionTime(); + creationTime = DateTimeUtils.toZonedDateTime(timestamp); + } + } + + @OnLoad + void onLoad() { + if (timestamp != null) { + creationTime = DateTimeUtils.toZonedDateTime(timestamp); + } + } + + @PostLoad + void postLoad() { + if (creationTime != null) { + timestamp = DateTimeUtils.toJodaDateTime(creationTime); + } + } /** Returns the timestamp. */ @Nullable @@ -36,6 +76,7 @@ public class CreateAutoTimestamp extends ImmutableObject implements UnsafeSerial public static CreateAutoTimestamp create(@Nullable DateTime timestamp) { CreateAutoTimestamp instance = new CreateAutoTimestamp(); instance.timestamp = timestamp; + instance.creationTime = (timestamp == null) ? null : DateTimeUtils.toZonedDateTime(timestamp); return instance; } } diff --git a/core/src/main/java/google/registry/model/EppResource.java b/core/src/main/java/google/registry/model/EppResource.java index 79967a220..a084ad497 100644 --- a/core/src/main/java/google/registry/model/EppResource.java +++ b/core/src/main/java/google/registry/model/EppResource.java @@ -50,6 +50,8 @@ import java.util.Set; import java.util.concurrent.ExecutionException; import javax.persistence.Access; import javax.persistence.AccessType; +import javax.persistence.AttributeOverride; +import javax.persistence.AttributeOverrides; import javax.persistence.Column; import javax.persistence.MappedSuperclass; import javax.persistence.Transient; @@ -112,7 +114,9 @@ public abstract class EppResource extends BackupGroupRoot implements Buildable { *
This can be null in the case of pre-Registry-3.0-migration history objects with null
* resource fields.
*/
- @Index CreateAutoTimestamp creationTime = CreateAutoTimestamp.create(null);
+ @AttributeOverrides({@AttributeOverride(name = "creationTime", column = @Column())})
+ @Index
+ CreateAutoTimestamp creationTime = CreateAutoTimestamp.create(null);
/**
* The time when this resource was or will be deleted.
diff --git a/core/src/main/java/google/registry/model/domain/RegistryLock.java b/core/src/main/java/google/registry/model/domain/RegistryLock.java
index 43856c304..cf1adb511 100644
--- a/core/src/main/java/google/registry/model/domain/RegistryLock.java
+++ b/core/src/main/java/google/registry/model/domain/RegistryLock.java
@@ -28,6 +28,8 @@ import google.registry.util.DateTimeUtils;
import java.time.ZonedDateTime;
import java.util.Optional;
import javax.annotation.Nullable;
+import javax.persistence.AttributeOverride;
+import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
@@ -100,7 +102,11 @@ public final class RegistryLock extends ImmutableObject implements Buildable, Sq
private String registrarPocId;
/** When the lock is first requested. */
- @Column(nullable = false)
+ @AttributeOverrides({
+ @AttributeOverride(
+ name = "creationTime",
+ column = @Column(name = "lockRequestTime", nullable = false))
+ })
private CreateAutoTimestamp lockRequestTime = CreateAutoTimestamp.create(null);
/** When the unlock is first requested. */
diff --git a/core/src/main/java/google/registry/model/domain/token/AllocationToken.java b/core/src/main/java/google/registry/model/domain/token/AllocationToken.java
index e3f20b028..09fe23746 100644
--- a/core/src/main/java/google/registry/model/domain/token/AllocationToken.java
+++ b/core/src/main/java/google/registry/model/domain/token/AllocationToken.java
@@ -122,7 +122,6 @@ public class AllocationToken extends BackupGroupRoot implements Buildable, Datas
@Nullable @Index String domainName;
/** When this token was created. */
- @Column(nullable = false)
CreateAutoTimestamp creationTime = CreateAutoTimestamp.create(null);
/** Allowed registrar client IDs for this token, or null if all registrars are allowed. */
diff --git a/core/src/main/java/google/registry/model/tmch/ClaimsList.java b/core/src/main/java/google/registry/model/tmch/ClaimsList.java
index 644c0298b..37210eb4e 100644
--- a/core/src/main/java/google/registry/model/tmch/ClaimsList.java
+++ b/core/src/main/java/google/registry/model/tmch/ClaimsList.java
@@ -27,6 +27,8 @@ import google.registry.model.replay.SqlOnlyEntity;
import google.registry.model.tld.label.ReservedList.ReservedListEntry;
import java.util.Map;
import java.util.Optional;
+import javax.persistence.AttributeOverride;
+import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
@@ -56,7 +58,11 @@ public class ClaimsList extends ImmutableObject implements SqlOnlyEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long revisionId;
- @Column(nullable = false)
+ @AttributeOverrides({
+ @AttributeOverride(
+ name = "creationTime",
+ column = @Column(name = "creationTimestamp", nullable = false))
+ })
CreateAutoTimestamp creationTimestamp = CreateAutoTimestamp.create(null);
/**
diff --git a/core/src/main/java/google/registry/persistence/converter/CreateAutoTimestampConverter.java b/core/src/main/java/google/registry/persistence/converter/CreateAutoTimestampConverter.java
deleted file mode 100644
index b70605c27..000000000
--- a/core/src/main/java/google/registry/persistence/converter/CreateAutoTimestampConverter.java
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright 2019 The Nomulus Authors. All Rights Reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-package google.registry.persistence.converter;
-
-import static com.google.common.base.MoreObjects.firstNonNull;
-import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
-
-import google.registry.model.CreateAutoTimestamp;
-import google.registry.util.DateTimeUtils;
-import java.sql.Timestamp;
-import java.time.ZoneOffset;
-import java.time.ZonedDateTime;
-import javax.annotation.Nullable;
-import javax.persistence.AttributeConverter;
-import javax.persistence.Converter;
-import org.joda.time.DateTime;
-
-/** JPA converter to for storing/retrieving CreateAutoTimestamp objects. */
-@Converter(autoApply = true)
-public class CreateAutoTimestampConverter
- implements AttributeConverter
generated on
- 2021-09-14 16:11:21.688911
+ 2021-11-19 21:30:39.304221
@@ -284,7 +284,7 @@ td.section {
generated on
last flyway file
- V102__add_indexes_to_domain_history_sub_tables.sql
+ V103__creation_time_not_null.sql
generated on
- 2021-09-14 16:11:19.580097
+ 2021-11-19 21:30:37.273092
@@ -284,7 +284,7 @@ td.section {
generated on
last flyway file
- V102__add_indexes_to_domain_history_sub_tables.sql
+ V103__creation_time_not_null.sql
creation_time
- timestamptz
+ timestamptz not null
diff --git a/db/src/main/resources/sql/flyway.txt b/db/src/main/resources/sql/flyway.txt
index 9ea9f5196..fa4c4669b 100644
--- a/db/src/main/resources/sql/flyway.txt
+++ b/db/src/main/resources/sql/flyway.txt
@@ -100,3 +100,4 @@ V99__drop_kms_secret_table.sql
V100__database_migration_schedule.sql
V101__domain_add_dns_refresh_request_time.sql
V102__add_indexes_to_domain_history_sub_tables.sql
+V103__creation_time_not_null.sql
diff --git a/db/src/main/resources/sql/flyway/V103__creation_time_not_null.sql b/db/src/main/resources/sql/flyway/V103__creation_time_not_null.sql
new file mode 100644
index 000000000..d520b687f
--- /dev/null
+++ b/db/src/main/resources/sql/flyway/V103__creation_time_not_null.sql
@@ -0,0 +1,15 @@
+-- Copyright 2021 The Nomulus Authors. All Rights Reserved.
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+
+ALTER TABLE "Registrar" ALTER COLUMN creation_time SET NOT NULL;
diff --git a/db/src/main/resources/sql/schema/db-schema.sql.generated b/db/src/main/resources/sql/schema/db-schema.sql.generated
index 90a0b9db9..8d22e2874 100644
--- a/db/src/main/resources/sql/schema/db-schema.sql.generated
+++ b/db/src/main/resources/sql/schema/db-schema.sql.generated
@@ -572,7 +572,7 @@
client_certificate text,
client_certificate_hash text,
contacts_require_syncing boolean not null,
- creation_time timestamptz,
+ creation_time timestamptz not null,
drive_folder_id text,
email_address text,
failover_client_certificate text,
diff --git a/db/src/main/resources/sql/schema/nomulus.golden.sql b/db/src/main/resources/sql/schema/nomulus.golden.sql
index d11e46c77..b1a986aa0 100644
--- a/db/src/main/resources/sql/schema/nomulus.golden.sql
+++ b/db/src/main/resources/sql/schema/nomulus.golden.sql
@@ -763,7 +763,7 @@ CREATE TABLE public."Registrar" (
client_certificate text,
client_certificate_hash text,
contacts_require_syncing boolean NOT NULL,
- creation_time timestamp with time zone,
+ creation_time timestamp with time zone NOT NULL,
drive_folder_id text,
email_address text,
failover_client_certificate text,