package com.datastax.oss.driver.internal.core.config.typesafe;
import com.datastax.oss.driver.api.core.config.DriverConfigLoader;
import com.datastax.oss.protocol.internal.util.collection.NullAllowingImmutableMap;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import com.typesafe.config.ConfigValueFactory;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import java.util.Map;
import net.jcip.annotations.NotThreadSafe;
@NotThreadSafe
@Deprecated
public class DefaultDriverConfigLoaderBuilder
implements com.datastax.oss.driver.internal.core.config.DriverOptionConfigBuilder<
DefaultDriverConfigLoaderBuilder> {
private NullAllowingImmutableMap.Builder<String, Object> values =
NullAllowingImmutableMap.builder();
@NonNull
public static ProfileBuilder profileBuilder() {
return new ProfileBuilder();
}
@NonNull
public DefaultDriverConfigLoaderBuilder withProfile(
@NonNull String profileName, @NonNull Profile profile) {
String prefix = "profiles." + profileName + ".";
for (Map.Entry<String, Object> entry : profile.values.entrySet()) {
this.with(prefix + entry.getKey(), entry.getValue());
}
return this;
}
@NonNull
public DriverConfigLoader build() {
return new DefaultDriverConfigLoader(
() -> buildConfig().withFallback(DefaultDriverConfigLoader.DEFAULT_CONFIG_SUPPLIER.get()));
}
protected Config buildConfig() {
Config config = ConfigFactory.empty();
for (Map.Entry<String, Object> entry : values.build().entrySet()) {
config = config.withValue(entry.getKey(), ConfigValueFactory.fromAnyRef(entry.getValue()));
}
return config;
}
@NonNull
@Override
public DefaultDriverConfigLoaderBuilder with(@NonNull String path, @Nullable Object value) {
values.put(path, value);
return this;
}
@Deprecated
public static final class ProfileBuilder
implements com.datastax.oss.driver.internal.core.config.DriverOptionConfigBuilder<
ProfileBuilder> {
final NullAllowingImmutableMap.Builder<String, Object> values =
NullAllowingImmutableMap.builder();
private ProfileBuilder() {}
@NonNull
@Override
public ProfileBuilder with(@NonNull String path, @Nullable Object value) {
values.put(path, value);
return this;
}
@NonNull
public Profile build() {
return new Profile(values.build());
}
}
public static final class Profile {
final Map<String, Object> values;
private Profile(Map<String, Object> values) {
this.values = values;
}
}
}