DBZ-2418 Delaying retrieval of DB charset;

This is called only once anyways, so there's no need for storing the info
in a field in PostgresConnection. This allows PostgresConnector#validate()
bring up a more meaningful error message in case of incorrect credentials
and other incorrect connection configuration.
This commit is contained in:
Gunnar Morling 2020-08-11 12:59:40 +02:00
parent 0b95df28d5
commit ebe5169a66

View File

@ -23,6 +23,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.debezium.DebeziumException;
import io.debezium.annotation.VisibleForTesting;
import io.debezium.config.Configuration;
import io.debezium.connector.postgresql.PostgresType;
@ -61,8 +62,6 @@ public class PostgresConnection extends JdbcConnection {
private final TypeRegistry typeRegistry;
private final Charset databaseCharset;
/**
* Creates a Postgres connection using the supplied configuration.
* If necessary this connection is able to resolve data type mappings.
@ -74,7 +73,6 @@ public class PostgresConnection extends JdbcConnection {
public PostgresConnection(Configuration config, boolean provideTypeRegistry) {
super(config, FACTORY, PostgresConnection::validateServerVersion, PostgresConnection::defaultSettings);
this.typeRegistry = provideTypeRegistry ? new TypeRegistry(this) : null;
databaseCharset = determineDatabaseCharset();
}
/**
@ -423,15 +421,11 @@ public ServerInfo serverInfo() throws SQLException {
}
public Charset getDatabaseCharset() {
return databaseCharset;
}
private Charset determineDatabaseCharset() {
try {
return Charset.forName(((BaseConnection) connection()).getEncoding().name());
}
catch (SQLException e) {
throw new RuntimeException("Couldn't obtain encoding for database " + database(), e);
throw new DebeziumException("Couldn't obtain encoding for database " + database(), e);
}
}