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:
parent
0b95df28d5
commit
ebe5169a66
@ -23,6 +23,7 @@
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import io.debezium.DebeziumException;
|
||||||
import io.debezium.annotation.VisibleForTesting;
|
import io.debezium.annotation.VisibleForTesting;
|
||||||
import io.debezium.config.Configuration;
|
import io.debezium.config.Configuration;
|
||||||
import io.debezium.connector.postgresql.PostgresType;
|
import io.debezium.connector.postgresql.PostgresType;
|
||||||
@ -61,8 +62,6 @@ public class PostgresConnection extends JdbcConnection {
|
|||||||
|
|
||||||
private final TypeRegistry typeRegistry;
|
private final TypeRegistry typeRegistry;
|
||||||
|
|
||||||
private final Charset databaseCharset;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a Postgres connection using the supplied configuration.
|
* Creates a Postgres connection using the supplied configuration.
|
||||||
* If necessary this connection is able to resolve data type mappings.
|
* 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) {
|
public PostgresConnection(Configuration config, boolean provideTypeRegistry) {
|
||||||
super(config, FACTORY, PostgresConnection::validateServerVersion, PostgresConnection::defaultSettings);
|
super(config, FACTORY, PostgresConnection::validateServerVersion, PostgresConnection::defaultSettings);
|
||||||
this.typeRegistry = provideTypeRegistry ? new TypeRegistry(this) : null;
|
this.typeRegistry = provideTypeRegistry ? new TypeRegistry(this) : null;
|
||||||
databaseCharset = determineDatabaseCharset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -423,15 +421,11 @@ public ServerInfo serverInfo() throws SQLException {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Charset getDatabaseCharset() {
|
public Charset getDatabaseCharset() {
|
||||||
return databaseCharset;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Charset determineDatabaseCharset() {
|
|
||||||
try {
|
try {
|
||||||
return Charset.forName(((BaseConnection) connection()).getEncoding().name());
|
return Charset.forName(((BaseConnection) connection()).getEncoding().name());
|
||||||
}
|
}
|
||||||
catch (SQLException e) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user