public class PostgresConnection extends JdbcConnection
JdbcConnection connection extension used for connecting to Postgres instances.JdbcConnection.BlockingMultiResultSetConsumer, JdbcConnection.BlockingResultSetConsumer, JdbcConnection.CallPreparer, JdbcConnection.ConnectionFactory, JdbcConnection.MultiResultSetConsumer, JdbcConnection.Operations, JdbcConnection.ParameterResultSetConsumer, JdbcConnection.ResultSetConsumer, JdbcConnection.ResultSetExtractor<T>, JdbcConnection.ResultSetMapper<T>, JdbcConnection.StatementFactory, JdbcConnection.StatementPreparer| Modifier and Type | Field and Description |
|---|---|
protected static JdbcConnection.ConnectionFactory |
FACTORY |
private static org.slf4j.Logger |
LOGGER |
private static int |
MAX_ATTEMPTS_FOR_OBTAINING_REPLICATION_SLOT
Obtaining a replication slot may fail if there's a pending transaction.
|
private static Duration |
PAUSE_BETWEEN_REPLICATION_SLOT_RETRIEVAL_ATTEMPTS |
private TypeRegistry |
typeRegistry |
private static String |
URL_PATTERN |
| Constructor and Description |
|---|
PostgresConnection(Configuration config)
Creates a Postgres connection using the supplied configuration.
|
PostgresConnection(Configuration config,
boolean provideTypeRegistry)
Creates a Postgres connection using the supplied configuration.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
String |
connectionString()
Returns a JDBC connection string for the current configuration.
|
Long |
currentTransactionId()
Returns the PG id of the current active transaction
|
long |
currentXLogLocation()
Returns the current position in the server tx log.
|
protected static void |
defaultSettings(Configuration.Builder builder) |
boolean |
dropPublication(String publicationName)
Drops the debezium publication that was created.
|
boolean |
dropReplicationSlot(String slotName)
Drops a replication slot that was created on the DB
|
private ServerInfo.ReplicationSlot |
fetchReplicationSlotInfo(String slotName,
String pluginName)
Fetches the state of a replication stage given a slot name and plugin name
|
Charset |
getDatabaseCharset() |
SlotState |
getReplicationSlotState(String slotName,
String pluginName)
Returns the current state of the replication slot
|
TypeRegistry |
getTypeRegistry() |
private Lsn |
parseConfirmedFlushLsn(String slotName,
String pluginName,
String database,
ResultSet rs)
Obtains the LSN to resume streaming from.
|
private Lsn |
parseRestartLsn(String slotName,
String pluginName,
String database,
ResultSet rs) |
protected ServerInfo.ReplicationSlot |
queryForSlot(String slotName,
String database,
String pluginName,
JdbcConnection.ResultSetMapper<ServerInfo.ReplicationSlot> map) |
ServerInfo.ReplicaIdentity |
readReplicaIdentityInfo(TableId tableId)
Prints out information about the REPLICA IDENTITY status of a table.
|
(package private) ServerInfo.ReplicationSlot |
readReplicationSlotInfo(String slotName,
String pluginName)
Fetches a replication slot, repeating the query until either the slot is created or until
the max number of attempts has been reached
To fetch the slot without the retries, use the
fetchReplicationSlotInfo(java.lang.String, java.lang.String) call |
protected Optional<ColumnEditor> |
readTableColumn(ResultSet columnMetadata,
TableId tableId,
Tables.ColumnNameFilter columnFilter) |
protected int |
resolveJdbcType(int metadataJdbcType,
int nativeType) |
protected int |
resolveNativeType(String typeName) |
ServerInfo |
serverInfo()
Returns information about the PG server to which this instance is connected.
|
private Lsn |
tryParseLsn(String slotName,
String pluginName,
String database,
ResultSet rs,
String column) |
private static void |
validateServerVersion(Statement statement) |
call, commit, config, connect, connection, connection, connectionString, database, execute, execute, executeWithoutCommitting, getDefaultValue, isConnected, isNullable, isTableUniqueIndexIncluded, parseSqlStatementString, patternBasedFactory, patternBasedFactory, prepareQuery, prepareQuery, prepareQuery, prepareQuery, prepareQueryAndMap, prepareQueryWithBlockingConsumer, prepareUpdate, print, print, query, query, queryAndMap, queryAndMap, querySingleValue, queryWithBlockingConsumer, readAllCatalogNames, readAllSchemaNames, readAllTableNames, readPrimaryKeyNames, readPrimaryKeyOrUniqueIndexNames, readSchema, readTableNames, readTableUniqueIndices, rollback, setAutoCommit, singleResultMapper, tableTypes, usernameprivate static org.slf4j.Logger LOGGER
private static final String URL_PATTERN
protected static final JdbcConnection.ConnectionFactory FACTORY
private static final int MAX_ATTEMPTS_FOR_OBTAINING_REPLICATION_SLOT
private static final Duration PAUSE_BETWEEN_REPLICATION_SLOT_RETRIEVAL_ATTEMPTS
private final TypeRegistry typeRegistry
public PostgresConnection(Configuration config, boolean provideTypeRegistry)
config - Configuration instance, may not be null.provideTypeRegistry - true if type registry should be createdpublic PostgresConnection(Configuration config)
config - Configuration instance, may not be null.public String connectionString()
String where the variables in urlPattern are replaced with values from the configurationpublic ServerInfo.ReplicaIdentity readReplicaIdentityInfo(TableId tableId) throws SQLException
tableId - the identifier of the tableSQLException - if there is a problem obtaining the replica identity information for the given tablepublic SlotState getReplicationSlotState(String slotName, String pluginName) throws SQLException
slotName - the name of the slotpluginName - the name of the plugin used for the desired slotSlotState or null, if no slot state is foundSQLExceptionprivate ServerInfo.ReplicationSlot fetchReplicationSlotInfo(String slotName, String pluginName) throws SQLException
slotName - the name of the slotpluginName - the name of the plugin used for the desired slotServerInfo.ReplicationSlot object or a ServerInfo.ReplicationSlot.INVALID if
the slot is not validSQLException - is thrown by the underlying JDBC@VisibleForTesting ServerInfo.ReplicationSlot readReplicationSlotInfo(String slotName, String pluginName) throws SQLException, InterruptedException
fetchReplicationSlotInfo(java.lang.String, java.lang.String) callslotName - the slot namepluginName - the name of the pluginServerInfo.ReplicationSlot object or a ServerInfo.ReplicationSlot.INVALID if
the slot is not validSQLException - is thrown by the underyling jdbc driverInterruptedException - is thrown if we don't return an answer within the set number of retriesprotected ServerInfo.ReplicationSlot queryForSlot(String slotName, String database, String pluginName, JdbcConnection.ResultSetMapper<ServerInfo.ReplicationSlot> map) throws SQLException
SQLExceptionprivate Lsn parseConfirmedFlushLsn(String slotName, String pluginName, String database, ResultSet rs)
private Lsn parseRestartLsn(String slotName, String pluginName, String database, ResultSet rs)
private Lsn tryParseLsn(String slotName, String pluginName, String database, ResultSet rs, String column) throws org.apache.kafka.connect.errors.ConnectException, SQLException
org.apache.kafka.connect.errors.ConnectExceptionSQLExceptionpublic boolean dropReplicationSlot(String slotName)
slotName - the name of the replication slot, may not be nulltrue if the slot was dropped, false otherwisepublic boolean dropPublication(String publicationName)
publicationName - the publication name, may not be nulltrue if the publication was dropped, false otherwisepublic void close()
close in interface AutoCloseableclose in class JdbcConnectionpublic Long currentTransactionId() throws SQLException
SQLException - if anything fails.public long currentXLogLocation()
throws SQLException
SQLException - if anything unexpected fails.public ServerInfo serverInfo() throws SQLException
ServerInfo instance, never nullSQLException - if anything failspublic Charset getDatabaseCharset()
protected static void defaultSettings(Configuration.Builder builder)
private static void validateServerVersion(Statement statement) throws SQLException
SQLExceptionprotected int resolveNativeType(String typeName)
resolveNativeType in class JdbcConnectionprotected int resolveJdbcType(int metadataJdbcType,
int nativeType)
resolveJdbcType in class JdbcConnectionprotected Optional<ColumnEditor> readTableColumn(ResultSet columnMetadata, TableId tableId, Tables.ColumnNameFilter columnFilter) throws SQLException
readTableColumn in class JdbcConnectionSQLExceptionpublic TypeRegistry getTypeRegistry()
Copyright © 2021 JBoss by Red Hat. All rights reserved.