com.scalar.db.sql.SqlConfig Maven / Gradle / Ivy
package com.scalar.db.sql;
import static com.scalar.db.config.ConfigUtils.getBoolean;
import static com.scalar.db.config.ConfigUtils.getString;
import com.scalar.db.config.DatabaseConfig;
import java.util.Locale;
import java.util.Optional;
import java.util.Properties;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
@Immutable
public class SqlConfig {
public static final String PREFIX = DatabaseConfig.PREFIX + "sql.";
public static final String CONNECTION_MODE = PREFIX + "connection_mode";
public static final String DEFAULT_TRANSACTION_MODE = PREFIX + "default_transaction_mode";
public static final String DEFAULT_NAMESPACE_NAME = PREFIX + "default_namespace_name";
// This is an undocumented property for now as creating a new namespace without existence check is
// a rare case.
public static final String DEFAULT_NAMESPACE_NAME_EXISTENCE_CHECK_ENABLED =
PREFIX + "default_namespace_name.existence_check.enabled";
@Nullable private final String connectionMode;
private final TransactionMode defaultTransactionMode;
@Nullable private final String defaultNamespaceName;
private final boolean defaultNamespaceNameExistenceCheckEnabled;
SqlConfig(Properties properties) {
connectionMode = getString(properties, CONNECTION_MODE, null);
defaultTransactionMode =
TransactionMode.valueOf(
getString(properties, DEFAULT_TRANSACTION_MODE, TransactionMode.TRANSACTION.toString())
.toUpperCase(Locale.ROOT));
defaultNamespaceName = getString(properties, DEFAULT_NAMESPACE_NAME, null);
defaultNamespaceNameExistenceCheckEnabled =
getBoolean(properties, DEFAULT_NAMESPACE_NAME_EXISTENCE_CHECK_ENABLED, true);
}
public Optional getConnectionMode() {
return Optional.ofNullable(connectionMode);
}
public TransactionMode getDefaultTransactionMode() {
return defaultTransactionMode;
}
public Optional getDefaultNamespaceName() {
return Optional.ofNullable(defaultNamespaceName);
}
public boolean isDefaultNamespaceNameExistenceCheckEnabled() {
return defaultNamespaceNameExistenceCheckEnabled;
}
}