com.yandex.ydb.jdbc.settings.AbstractYdbProperty Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ydb-sdk-jdbc-uberjar Show documentation
Show all versions of ydb-sdk-jdbc-uberjar Show documentation
JDBC client implementation over Table client, single jar
package com.yandex.ydb.jdbc.settings;
import java.sql.DriverPropertyInfo;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.BiConsumer;
import javax.annotation.Nullable;
public abstract class AbstractYdbProperty implements ToDriverPropertyInfo {
private final String name;
private final String description;
@Nullable
private final String defaultValue;
private final Class type;
private final PropertyConverter converter;
private final BiConsumer setter;
protected AbstractYdbProperty(String name,
String description,
@Nullable String defaultValue,
Class type,
PropertyConverter converter,
BiConsumer setter) {
this.name = Objects.requireNonNull(name);
this.description = Objects.requireNonNull(description);
this.defaultValue = defaultValue;
this.type = Objects.requireNonNull(type);
this.converter = Objects.requireNonNull(converter);
this.setter = Objects.requireNonNull(setter);
}
public String getName() {
return name;
}
@Nullable
public String getDefaultValue() {
return defaultValue;
}
public PropertyConverter getConverter() {
return converter;
}
public Class getType() {
return type;
}
public BiConsumer getSetter() {
return setter;
}
@Override
public DriverPropertyInfo toDriverPropertyInfo(@Nullable String value) {
DriverPropertyInfo info = new DriverPropertyInfo(name,
value != null ? value : defaultValue != null ? defaultValue : "");
info.description = description;
info.required = false;
return info;
}
static class PropertiesCollector> {
private final Map properties = new LinkedHashMap<>();
protected void register(T property) {
if (properties.put(property.getName(), property) != null) {
throw new IllegalStateException("Internal error. Unable to register property with name " +
property.getName() + " twice");
}
}
protected Collection properties() {
return Collections.unmodifiableCollection(properties.values());
}
}
}