com.scalar.db.storage.cosmos.CosmosTableMetadata Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scalardb Show documentation
Show all versions of scalardb Show documentation
A universal transaction manager that achieves database-agnostic transactions and distributed transactions that span multiple databases
The newest version!
package com.scalar.db.storage.cosmos;
import com.google.common.base.MoreObjects;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
/**
* A metadata class for a table of ScalarDB to know the type of each column
*
* @author Yuji Ito
*/
@SuppressFBWarnings({"EI_EXPOSE_REP", "EI_EXPOSE_REP2"})
@Immutable
public class CosmosTableMetadata {
private final String id;
private final LinkedHashSet partitionKeyNames;
private final LinkedHashSet clusteringKeyNames;
private final Map clusteringOrders;
private final Set secondaryIndexNames;
private final Map columns;
// The default constructor is required by the Cosmos SDK which uses Jackson to deserialize JSON
// object
public CosmosTableMetadata() {
this(null, null, null, null, null, null);
}
public CosmosTableMetadata(
@Nullable String id,
@Nullable LinkedHashSet partitionKeyNames,
@Nullable LinkedHashSet clusteringKeyNames,
@Nullable Map clusteringOrders,
@Nullable Set secondaryIndexNames,
@Nullable Map columns) {
this.id = id != null ? id : "";
this.partitionKeyNames = partitionKeyNames != null ? partitionKeyNames : new LinkedHashSet<>();
this.clusteringKeyNames =
clusteringKeyNames != null ? clusteringKeyNames : new LinkedHashSet<>();
this.clusteringOrders = clusteringOrders != null ? clusteringOrders : Collections.emptyMap();
this.secondaryIndexNames =
secondaryIndexNames != null ? secondaryIndexNames : Collections.emptySet();
this.columns = columns != null ? columns : Collections.emptyMap();
}
private CosmosTableMetadata(Builder builder) {
this(
builder.id,
builder.partitionKeyNames,
builder.clusteringKeyNames,
builder.clusteringOrders,
builder.secondaryIndexNames,
builder.columns);
}
public String getId() {
return id;
}
public LinkedHashSet getPartitionKeyNames() {
return partitionKeyNames;
}
public LinkedHashSet getClusteringKeyNames() {
return clusteringKeyNames;
}
public Map getClusteringOrders() {
return clusteringOrders;
}
public Set getSecondaryIndexNames() {
return secondaryIndexNames;
}
public Map getColumns() {
return columns;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof CosmosTableMetadata)) {
return false;
}
CosmosTableMetadata that = (CosmosTableMetadata) o;
return Objects.equals(id, that.id)
&& Objects.equals(partitionKeyNames, that.partitionKeyNames)
&& Objects.equals(clusteringKeyNames, that.clusteringKeyNames)
&& Objects.equals(clusteringOrders, that.clusteringOrders)
&& Objects.equals(secondaryIndexNames, that.secondaryIndexNames)
&& Objects.equals(columns, that.columns);
}
@Override
public int hashCode() {
return Objects.hash(
id, partitionKeyNames, clusteringKeyNames, clusteringOrders, secondaryIndexNames, columns);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("id", id)
.add("partitionKeyNames", partitionKeyNames)
.add("clusteringKeyNames", clusteringKeyNames)
.add("clusteringOrders", clusteringOrders)
.add("secondaryIndexNames", secondaryIndexNames)
.add("columns", columns)
.toString();
}
public static Builder newBuilder() {
return new Builder();
}
public static final class Builder {
private String id;
private LinkedHashSet partitionKeyNames;
private LinkedHashSet clusteringKeyNames;
private Map clusteringOrders;
private Set secondaryIndexNames;
private Map columns;
private Builder() {}
public Builder id(String val) {
id = val;
return this;
}
public Builder partitionKeyNames(LinkedHashSet val) {
partitionKeyNames = val;
return this;
}
public Builder clusteringKeyNames(LinkedHashSet val) {
clusteringKeyNames = val;
return this;
}
public Builder clusteringOrders(Map val) {
clusteringOrders = val;
return this;
}
public Builder secondaryIndexNames(Set val) {
secondaryIndexNames = val;
return this;
}
public Builder columns(Map val) {
columns = val;
return this;
}
public CosmosTableMetadata build() {
return new CosmosTableMetadata(this);
}
}
}