com.scalar.db.transaction.consensuscommit.TransactionTableMetadata 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
package com.scalar.db.transaction.consensuscommit;
import com.google.common.collect.Streams;
import com.scalar.db.api.Scan;
import com.scalar.db.api.Scan.Ordering.Order;
import com.scalar.db.api.TableMetadata;
import com.scalar.db.io.DataType;
import com.scalar.db.util.ImmutableLinkedHashSet;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.concurrent.Immutable;
@Immutable
public class TransactionTableMetadata {
private final TableMetadata tableMetadata;
private final ImmutableLinkedHashSet primaryKeyColumnNames;
private final ImmutableLinkedHashSet transactionMetaColumnNames;
private final ImmutableLinkedHashSet beforeImageColumnNames;
private final ImmutableLinkedHashSet afterImageColumnNames;
public TransactionTableMetadata(TableMetadata tableMetadata) {
this.tableMetadata = tableMetadata;
primaryKeyColumnNames =
new ImmutableLinkedHashSet<>(
Streams.concat(
tableMetadata.getPartitionKeyNames().stream(),
tableMetadata.getClusteringKeyNames().stream())
.collect(Collectors.toCollection(LinkedHashSet::new)));
transactionMetaColumnNames =
new ImmutableLinkedHashSet<>(
tableMetadata.getColumnNames().stream()
.filter(c -> ConsensusCommitUtils.isTransactionMetaColumn(c, tableMetadata))
.collect(Collectors.toList()));
beforeImageColumnNames =
new ImmutableLinkedHashSet<>(
tableMetadata.getColumnNames().stream()
.filter(c -> ConsensusCommitUtils.isBeforeImageColumn(c, tableMetadata))
.collect(Collectors.toList()));
afterImageColumnNames =
new ImmutableLinkedHashSet<>(
tableMetadata.getColumnNames().stream()
.filter(c -> ConsensusCommitUtils.isAfterImageColumn(c, tableMetadata))
.collect(Collectors.toList()));
}
public TableMetadata getTableMetadata() {
return tableMetadata;
}
public LinkedHashSet getColumnNames() {
return tableMetadata.getColumnNames();
}
public DataType getColumnDataType(String columnName) {
return tableMetadata.getColumnDataType(columnName);
}
public LinkedHashSet getPartitionKeyNames() {
return tableMetadata.getPartitionKeyNames();
}
public LinkedHashSet getClusteringKeyNames() {
return tableMetadata.getClusteringKeyNames();
}
public Scan.Ordering.Order getClusteringOrder(String clusteringKeyName) {
return tableMetadata.getClusteringOrder(clusteringKeyName);
}
public Map getClusteringOrders() {
return tableMetadata.getClusteringOrders();
}
public Set getSecondaryIndexNames() {
return tableMetadata.getSecondaryIndexNames();
}
public LinkedHashSet getPrimaryKeyColumnNames() {
return primaryKeyColumnNames;
}
public LinkedHashSet getTransactionMetaColumnNames() {
return transactionMetaColumnNames;
}
public LinkedHashSet getBeforeImageColumnNames() {
return beforeImageColumnNames;
}
public LinkedHashSet getAfterImageColumnNames() {
return afterImageColumnNames;
}
}