tech.ydb.jdbc.settings.PropertyConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ydb-jdbc-driver Show documentation
Show all versions of ydb-jdbc-driver Show documentation
JDBC Driver over YDB Java SDK
package tech.ydb.jdbc.settings;
import java.sql.SQLException;
import java.time.Duration;
import java.time.format.DateTimeParseException;
import java.util.Locale;
import tech.ydb.jdbc.exception.YdbConfigurationException;
interface PropertyConverter {
T convert(String value) throws SQLException;
static PropertyConverter stringValue() {
return value -> value;
}
static PropertyConverter durationValue() {
return value -> {
String targetValue = "PT" + value.replace(" ", "").toUpperCase(Locale.ROOT);
try {
return Duration.parse(targetValue);
} catch (DateTimeParseException e) {
throw new YdbConfigurationException("Unable to parse value [" + value + "] -> [" +
targetValue + "] as Duration: " + e.getMessage(), e);
}
};
}
static PropertyConverter integerValue() {
return value -> {
try {
return Integer.valueOf(value);
} catch (NumberFormatException e) {
throw new YdbConfigurationException("Unable to parse value [" + value + "] as Integer: " +
e.getMessage(), e);
}
};
}
static PropertyConverter booleanValue() {
return Boolean::valueOf;
}
static PropertyConverter stringFileReference() {
return YdbLookup::stringFileReference;
}
static PropertyConverter byteFileReference() {
return YdbLookup::byteFileReference;
}
}