All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.bazaarvoice.emodb.sor.db.astyanax.DeltaPlacement Maven / Gradle / Ivy

There is a newer version: 6.5.190
Show newest version
package com.bazaarvoice.emodb.sor.db.astyanax;

import com.bazaarvoice.emodb.common.cassandra.CassandraKeyspace;
import com.bazaarvoice.emodb.table.db.astyanax.Placement;
import com.datastax.driver.core.TableMetadata;
import com.netflix.astyanax.model.ColumnFamily;

import java.nio.ByteBuffer;
import java.util.UUID;

import static java.util.Objects.requireNonNull;

/**
 * A Cassandra keyspace and the DataStore-related column families.
 */
class DeltaPlacement implements Placement {
    private final String _name;
    private final CassandraKeyspace _keyspace;
    private final ColumnFamily _blockedDeltaColumnFamily;
    private final ColumnFamily _deltaHistoryColumnFamily;
    private final BlockedDeltaTableDDL _blockedDeltaTableDDL;
    private final TableDDL _deltaHistoryTableDDL;

    DeltaPlacement(String name,
                   CassandraKeyspace keyspace,
                   ColumnFamily blockedDeltaColumnFamily,
                   ColumnFamily deltaHistoryColumnFamily) {
        _name = requireNonNull(name, "name");
        _keyspace = requireNonNull(keyspace, "keyspace");
        _blockedDeltaColumnFamily = requireNonNull(blockedDeltaColumnFamily, "blockedDeltaColumnFamily");
        _deltaHistoryColumnFamily = requireNonNull(deltaHistoryColumnFamily, "deltaHistoryColumnFamily");

        _blockedDeltaTableDDL = createBlockedDeltaTableDDL(blockedDeltaColumnFamily.getName());
        _deltaHistoryTableDDL = creatHistoryTableDDL(_deltaHistoryColumnFamily.getName());
    }

    private TableDDL creatHistoryTableDDL(String tableName) {
        TableMetadata tableMetadata = _keyspace.getKeyspaceMetadata().getTable(tableName);
        String rowKeyColumnName = tableMetadata.getPrimaryKey().get(0).getName();
        String timeSeriesColumnName = tableMetadata.getPrimaryKey().get(1).getName();
        String valueColumnName = tableMetadata.getColumns().get(2).getName();

        return new TableDDL(tableMetadata, rowKeyColumnName, timeSeriesColumnName, valueColumnName);
    }

    private BlockedDeltaTableDDL createBlockedDeltaTableDDL(String tableName) {
        TableMetadata tableMetadata = _keyspace.getKeyspaceMetadata().getTable(tableName);
        String rowKeyColumnName = tableMetadata.getPrimaryKey().get(0).getName();
        String timeSeriesColumnName = tableMetadata.getPrimaryKey().get(1).getName();
        String blockColumnName = tableMetadata.getPrimaryKey().get(2).getName();
        String valueColumnName = tableMetadata.getColumns().get(3).getName();

        return new BlockedDeltaTableDDL(tableMetadata, rowKeyColumnName, timeSeriesColumnName, valueColumnName, blockColumnName);
    }

    @Override
    public String getName() {
        return _name;
    }

    @Override
    public CassandraKeyspace getKeyspace() {
        return _keyspace;
    }

    ColumnFamily getDeltaHistoryColumnFamily() {
        return _deltaHistoryColumnFamily;
    }

    ColumnFamily getBlockedDeltaColumnFamily() {
        return _blockedDeltaColumnFamily;
    }

    TableDDL getDeltaHistoryTableDDL() {
        return _deltaHistoryTableDDL;
    }

    BlockedDeltaTableDDL getBlockedDeltaTableDDL() {
        return _blockedDeltaTableDDL;
    }

    // for debugging
    @Override
    public String toString() {
        return _name;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy