mirror of
https://github.com/google/nomulus.git
synced 2025-08-14 13:34:07 +02:00
Add sql schema and entity class for ClaimsList (#227)
This commit is contained in:
parent
87c66495ba
commit
6166555b52
3 changed files with 124 additions and 0 deletions
|
@ -0,0 +1,96 @@
|
||||||
|
// 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.schema.tmch;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
import javax.persistence.CollectionTable;
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.ElementCollection;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.JoinColumn;
|
||||||
|
import javax.persistence.MapKeyColumn;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A list of TMCH claims labels and their associated claims keys.
|
||||||
|
*
|
||||||
|
* <p>Note that the primary key of this entity is {@link #revisionId}, which is auto-generated by
|
||||||
|
* the database. So, if a retry of insertion happens after the previous attempt unexpectedly
|
||||||
|
* succeeds, we will end up with having two exact same claims list with only different {@link
|
||||||
|
* #revisionId}. However, this is not an actual problem because we only use the claims list with
|
||||||
|
* highest {@link #revisionId}.
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Table(name = "ClaimsList")
|
||||||
|
public class ClaimsList {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name = "revision_id")
|
||||||
|
private Long revisionId;
|
||||||
|
|
||||||
|
@Column(name = "creation_timestamp", nullable = false)
|
||||||
|
private ZonedDateTime creationTimestamp;
|
||||||
|
|
||||||
|
@ElementCollection
|
||||||
|
@CollectionTable(
|
||||||
|
name = "ClaimsEntry",
|
||||||
|
joinColumns = @JoinColumn(name = "revision_id", referencedColumnName = "revision_id"))
|
||||||
|
@MapKeyColumn(name = "domain_label", nullable = false)
|
||||||
|
@Column(name = "claim_key", nullable = false)
|
||||||
|
private Map<String, String> labelsToKeys;
|
||||||
|
|
||||||
|
private ClaimsList(ZonedDateTime creationTimestamp, Map<String, String> labelsToKeys) {
|
||||||
|
this.creationTimestamp = creationTimestamp;
|
||||||
|
this.labelsToKeys = labelsToKeys;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hibernate requires this default constructor.
|
||||||
|
private ClaimsList() {}
|
||||||
|
|
||||||
|
/** Constructs a {@link ClaimsList} object. */
|
||||||
|
public static ClaimsList create(
|
||||||
|
ZonedDateTime creationTimestamp, Map<String, String> labelsToKeys) {
|
||||||
|
return new ClaimsList(creationTimestamp, labelsToKeys);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns the revision id of this claims list, or throws exception if it is null. */
|
||||||
|
public Long getRevisionId() {
|
||||||
|
checkState(
|
||||||
|
revisionId != null, "revisionId is null because it is not persisted in the database");
|
||||||
|
return revisionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns the creation time of this claims list. */
|
||||||
|
public ZonedDateTime getCreationTimestamp() {
|
||||||
|
return creationTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns an {@link Map} mapping domain label to its lookup key. */
|
||||||
|
public Map<String, String> getLabelsToKeys() {
|
||||||
|
return labelsToKeys;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns the claim key for a given domain if there is one, empty otherwise. */
|
||||||
|
public Optional<String> getClaimKey(String label) {
|
||||||
|
return Optional.ofNullable(labelsToKeys.get(label));
|
||||||
|
}
|
||||||
|
}
|
27
db/src/main/resources/sql/schema/claims_list.sql
Normal file
27
db/src/main/resources/sql/schema/claims_list.sql
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
-- 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.
|
||||||
|
|
||||||
|
CREATE TABLE `ClaimsList` (
|
||||||
|
revision_id BIGSERIAL NOT NULL,
|
||||||
|
creation_timestamp TIMESTAMPTZ NOT NULL,
|
||||||
|
PRIMARY KEY (revision_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE `ClaimsEntry` (
|
||||||
|
revision_id BIGSERIAL NOT NULL,
|
||||||
|
claim_key TEXT NOT NULL,
|
||||||
|
domain_label TEXT NOT NULL,
|
||||||
|
PRIMARY KEY (revision_id, domain_label),
|
||||||
|
FOREIGN KEY (revision_id) REFERENCES `ClaimsList`(revision_id)
|
||||||
|
);
|
|
@ -28,6 +28,7 @@ if (pluginsUrl) {
|
||||||
rootProject.name = 'nomulus'
|
rootProject.name = 'nomulus'
|
||||||
|
|
||||||
include 'core'
|
include 'core'
|
||||||
|
include 'db'
|
||||||
include 'prober'
|
include 'prober'
|
||||||
include 'proxy'
|
include 'proxy'
|
||||||
include 'third_party'
|
include 'third_party'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue