mirror of
https://github.com/google/nomulus.git
synced 2025-04-30 03:57:51 +02:00
Clean up some SqlEntity classes (#1158)
* Clean up some SqlEntity classes This started as having a better check for when to run the ReplayCommitLogsToSqlAction but that'll require a bit more thought, and this is a fairly simple PR that can be split out.
This commit is contained in:
parent
2e51a21472
commit
6b6544adc8
8 changed files with 39 additions and 64 deletions
|
@ -16,9 +16,7 @@ package google.registry.model.domain.secdns;
|
||||||
|
|
||||||
import google.registry.model.domain.DomainHistory;
|
import google.registry.model.domain.DomainHistory;
|
||||||
import google.registry.model.ofy.ObjectifyService;
|
import google.registry.model.ofy.ObjectifyService;
|
||||||
import google.registry.schema.replay.DatastoreEntity;
|
import google.registry.schema.replay.SqlOnlyEntity;
|
||||||
import google.registry.schema.replay.SqlEntity;
|
|
||||||
import java.util.Optional;
|
|
||||||
import javax.persistence.Access;
|
import javax.persistence.Access;
|
||||||
import javax.persistence.AccessType;
|
import javax.persistence.AccessType;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
|
@ -27,7 +25,7 @@ import javax.persistence.Id;
|
||||||
|
|
||||||
/** Entity class to represent a historic {@link DelegationSignerData}. */
|
/** Entity class to represent a historic {@link DelegationSignerData}. */
|
||||||
@Entity
|
@Entity
|
||||||
public class DomainDsDataHistory extends DomainDsDataBase implements SqlEntity {
|
public class DomainDsDataHistory extends DomainDsDataBase implements SqlOnlyEntity {
|
||||||
|
|
||||||
@Id Long dsDataHistoryRevisionId;
|
@Id Long dsDataHistoryRevisionId;
|
||||||
|
|
||||||
|
@ -84,9 +82,4 @@ public class DomainDsDataHistory extends DomainDsDataBase implements SqlEntity {
|
||||||
public byte[] getDigest() {
|
public byte[] getDigest() {
|
||||||
return super.getDigest();
|
return super.getDigest();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<DatastoreEntity> toDatastoreEntity() {
|
|
||||||
return Optional.empty(); // Not persisted in Datastore
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,10 +21,8 @@ import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import google.registry.model.Buildable;
|
import google.registry.model.Buildable;
|
||||||
import google.registry.model.ImmutableObject;
|
import google.registry.model.ImmutableObject;
|
||||||
import google.registry.schema.replay.DatastoreEntity;
|
import google.registry.schema.replay.SqlOnlyEntity;
|
||||||
import google.registry.schema.replay.SqlEntity;
|
|
||||||
import google.registry.util.DomainNameUtils;
|
import google.registry.util.DomainNameUtils;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
@ -42,7 +40,7 @@ import org.joda.time.LocalDate;
|
||||||
@Index(name = "spec11threatmatch_tld_idx", columnList = "tld"),
|
@Index(name = "spec11threatmatch_tld_idx", columnList = "tld"),
|
||||||
@Index(name = "spec11threatmatch_check_date_idx", columnList = "checkDate")
|
@Index(name = "spec11threatmatch_check_date_idx", columnList = "checkDate")
|
||||||
})
|
})
|
||||||
public class Spec11ThreatMatch extends ImmutableObject implements Buildable, SqlEntity {
|
public class Spec11ThreatMatch extends ImmutableObject implements Buildable, SqlOnlyEntity {
|
||||||
|
|
||||||
/** The type of threat detected. */
|
/** The type of threat detected. */
|
||||||
public enum ThreatType {
|
public enum ThreatType {
|
||||||
|
@ -110,11 +108,6 @@ public class Spec11ThreatMatch extends ImmutableObject implements Buildable, Sql
|
||||||
return tld;
|
return tld;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<DatastoreEntity> toDatastoreEntity() {
|
|
||||||
return Optional.empty(); // Not persisted in Datastore
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Builder asBuilder() {
|
public Builder asBuilder() {
|
||||||
return new Builder(clone(this));
|
return new Builder(clone(this));
|
||||||
|
|
|
@ -21,10 +21,8 @@ import static google.registry.util.DateTimeUtils.isBeforeOrAt;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import google.registry.model.ImmutableObject;
|
import google.registry.model.ImmutableObject;
|
||||||
import google.registry.schema.replay.DatastoreEntity;
|
import google.registry.schema.replay.SqlOnlyEntity;
|
||||||
import google.registry.schema.replay.SqlEntity;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
|
||||||
import javax.persistence.CollectionTable;
|
import javax.persistence.CollectionTable;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.ElementCollection;
|
import javax.persistence.ElementCollection;
|
||||||
|
@ -48,7 +46,7 @@ import org.joda.time.DateTime;
|
||||||
* functional specifications - SMD Revocation List</a>
|
* functional specifications - SMD Revocation List</a>
|
||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
public class SignedMarkRevocationList extends ImmutableObject implements SqlEntity {
|
public class SignedMarkRevocationList extends ImmutableObject implements SqlOnlyEntity {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@ -104,9 +102,4 @@ public class SignedMarkRevocationList extends ImmutableObject implements SqlEnti
|
||||||
SignedMarkRevocationListDao.save(this);
|
SignedMarkRevocationListDao.save(this);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<DatastoreEntity> toDatastoreEntity() {
|
|
||||||
return Optional.empty(); // Not persisted in Datastore
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,7 @@
|
||||||
|
|
||||||
package google.registry.persistence.transaction;
|
package google.registry.persistence.transaction;
|
||||||
|
|
||||||
import google.registry.schema.replay.DatastoreEntity;
|
import google.registry.schema.replay.SqlOnlyEntity;
|
||||||
import google.registry.schema.replay.SqlEntity;
|
|
||||||
import java.util.Optional;
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import javax.persistence.GeneratedValue;
|
||||||
import javax.persistence.GenerationType;
|
import javax.persistence.GenerationType;
|
||||||
|
@ -30,7 +28,7 @@ import javax.persistence.Table;
|
||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "Transaction")
|
@Table(name = "Transaction")
|
||||||
public class TransactionEntity implements SqlEntity {
|
public class TransactionEntity implements SqlOnlyEntity {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@ -44,11 +42,6 @@ public class TransactionEntity implements SqlEntity {
|
||||||
this.contents = contents;
|
this.contents = contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<DatastoreEntity> toDatastoreEntity() {
|
|
||||||
return Optional.empty(); // Not persisted in Datastore per se
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getId() {
|
public long getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,7 @@ import google.registry.model.Buildable;
|
||||||
import google.registry.model.CreateAutoTimestamp;
|
import google.registry.model.CreateAutoTimestamp;
|
||||||
import google.registry.model.ImmutableObject;
|
import google.registry.model.ImmutableObject;
|
||||||
import google.registry.model.UpdateAutoTimestamp;
|
import google.registry.model.UpdateAutoTimestamp;
|
||||||
import google.registry.schema.replay.DatastoreEntity;
|
import google.registry.schema.replay.SqlOnlyEntity;
|
||||||
import google.registry.schema.replay.SqlEntity;
|
|
||||||
import google.registry.util.DateTimeUtils;
|
import google.registry.util.DateTimeUtils;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
@ -75,7 +74,7 @@ import org.joda.time.Duration;
|
||||||
@Index(name = "idx_registry_lock_verification_code", columnList = "verificationCode"),
|
@Index(name = "idx_registry_lock_verification_code", columnList = "verificationCode"),
|
||||||
@Index(name = "idx_registry_lock_registrar_id", columnList = "registrarId")
|
@Index(name = "idx_registry_lock_registrar_id", columnList = "registrarId")
|
||||||
})
|
})
|
||||||
public final class RegistryLock extends ImmutableObject implements Buildable, SqlEntity {
|
public final class RegistryLock extends ImmutableObject implements Buildable, SqlOnlyEntity {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@ -233,11 +232,6 @@ public final class RegistryLock extends ImmutableObject implements Buildable, Sq
|
||||||
return new Builder(clone(this));
|
return new Builder(clone(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<DatastoreEntity> toDatastoreEntity() {
|
|
||||||
return Optional.empty(); // Not persisted in Datastore
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Builder for {@link google.registry.schema.domain.RegistryLock}. */
|
/** Builder for {@link google.registry.schema.domain.RegistryLock}. */
|
||||||
public static class Builder extends Buildable.Builder<RegistryLock> {
|
public static class Builder extends Buildable.Builder<RegistryLock> {
|
||||||
public Builder() {}
|
public Builder() {}
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
package google.registry.schema.replay;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/** An entity that is only stored in SQL, that should not be replayed to Datastore. */
|
||||||
|
public interface SqlOnlyEntity extends SqlEntity {
|
||||||
|
@Override
|
||||||
|
default Optional<DatastoreEntity> toDatastoreEntity() {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,30 +18,21 @@ import static google.registry.model.common.CrossTldSingleton.SINGLETON_ID;
|
||||||
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
|
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
|
||||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class SqlReplayCheckpoint implements SqlEntity {
|
public class SqlReplayCheckpoint implements SqlOnlyEntity {
|
||||||
|
|
||||||
// Hibernate doesn't allow us to have a converted DateTime as our primary key so we need this
|
// Hibernate doesn't allow us to have a converted DateTime as our primary key so we need this
|
||||||
@Id private long revisionId = SINGLETON_ID;
|
@Id private long revisionId = SINGLETON_ID;
|
||||||
|
|
||||||
private DateTime lastReplayTime;
|
private DateTime lastReplayTime;
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<DatastoreEntity> toDatastoreEntity() {
|
|
||||||
return Optional.empty(); // Not necessary to persist in Datastore
|
|
||||||
}
|
|
||||||
|
|
||||||
public static DateTime get() {
|
public static DateTime get() {
|
||||||
jpaTm().assertInTransaction();
|
jpaTm().assertInTransaction();
|
||||||
return jpaTm()
|
return jpaTm().loadAllOf(SqlReplayCheckpoint.class).stream()
|
||||||
.query("FROM SqlReplayCheckpoint", SqlReplayCheckpoint.class)
|
|
||||||
.setMaxResults(1)
|
|
||||||
.getResultStream()
|
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.map(checkpoint -> checkpoint.lastReplayTime)
|
.map(checkpoint -> checkpoint.lastReplayTime)
|
||||||
.orElse(START_OF_TIME);
|
.orElse(START_OF_TIME);
|
||||||
|
|
|
@ -16,11 +16,9 @@ package google.registry.schema.tld;
|
||||||
|
|
||||||
import google.registry.model.ImmutableObject;
|
import google.registry.model.ImmutableObject;
|
||||||
import google.registry.model.registry.label.PremiumList;
|
import google.registry.model.registry.label.PremiumList;
|
||||||
import google.registry.schema.replay.DatastoreEntity;
|
import google.registry.schema.replay.SqlOnlyEntity;
|
||||||
import google.registry.schema.replay.SqlEntity;
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Optional;
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
|
@ -31,7 +29,7 @@ import javax.persistence.Id;
|
||||||
* <p>These are not persisted directly, but rather, using {@link PremiumList#getLabelsToPrices()}.
|
* <p>These are not persisted directly, but rather, using {@link PremiumList#getLabelsToPrices()}.
|
||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
public class PremiumEntry extends ImmutableObject implements Serializable, SqlEntity {
|
public class PremiumEntry extends ImmutableObject implements Serializable, SqlOnlyEntity {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
|
@ -46,11 +44,6 @@ public class PremiumEntry extends ImmutableObject implements Serializable, SqlEn
|
||||||
|
|
||||||
private PremiumEntry() {}
|
private PremiumEntry() {}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<DatastoreEntity> toDatastoreEntity() {
|
|
||||||
return Optional.empty(); // PremiumList is dually-written
|
|
||||||
}
|
|
||||||
|
|
||||||
public BigDecimal getPrice() {
|
public BigDecimal getPrice() {
|
||||||
return price;
|
return price;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue