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

com.scalar.db.storage.cosmos.CosmosConfig Maven / Gradle / Ivy

Go to download

A universal transaction manager that achieves database-agnostic transactions and distributed transactions that span multiple databases

There is a newer version: 3.14.0
Show newest version
package com.scalar.db.storage.cosmos;

import static com.scalar.db.config.ConfigUtils.getString;

import com.scalar.db.config.DatabaseConfig;
import java.util.Optional;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;

@Immutable
public class CosmosConfig {

  public static final String PREFIX = DatabaseConfig.PREFIX + "cosmos.";
  public static final String TABLE_METADATA_DATABASE = PREFIX + "table_metadata.database";

  private final String endpoint;
  private final String key;
  @Nullable private final String tableMetadataDatabase;

  public CosmosConfig(DatabaseConfig databaseConfig) {
    String storage = databaseConfig.getStorage();
    if (!"cosmos".equals(storage)) {
      throw new IllegalArgumentException(DatabaseConfig.STORAGE + " should be 'cosmos'");
    }

    if (databaseConfig.getContactPoints().isEmpty()) {
      throw new IllegalArgumentException(DatabaseConfig.CONTACT_POINTS + " is empty");
    }
    endpoint = databaseConfig.getContactPoints().get(0);
    key = databaseConfig.getPassword().orElse(null);
    tableMetadataDatabase =
        getString(databaseConfig.getProperties(), TABLE_METADATA_DATABASE, null);
  }

  public String getEndpoint() {
    return endpoint;
  }

  public String getKey() {
    return key;
  }

  public Optional getTableMetadataDatabase() {
    return Optional.ofNullable(tableMetadataDatabase);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy