Package io.debezium.connector.oracle
Class OracleConnection
- java.lang.Object
-
- io.debezium.jdbc.JdbcConnection
-
- io.debezium.connector.oracle.OracleConnection
-
- All Implemented Interfaces:
AutoCloseable
public class OracleConnection extends JdbcConnection
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class io.debezium.jdbc.JdbcConnection
JdbcConnection.BlockingMultiResultSetConsumer, JdbcConnection.BlockingResultSetConsumer, JdbcConnection.CallPreparer, JdbcConnection.ConnectionFactory, JdbcConnection.MultiResultSetConsumer, JdbcConnection.Operations, JdbcConnection.ParameterResultSetConsumer, JdbcConnection.ResultSetConsumer, JdbcConnection.ResultSetExtractor<T extends Object>, JdbcConnection.ResultSetMapper<T extends Object>, JdbcConnection.StatementFactory, JdbcConnection.StatementPreparer
-
-
Field Summary
Fields Modifier and Type Field Description private OracleDatabaseVersiondatabaseVersionThe database version.private static org.slf4j.LoggerLOGGERprivate static intORACLE_UNSET_SCALEReturned by column metadata in Oracle if no scale is set;private static StringQUOTED_CHARACTERprivate static PatternSYS_NC_PATTERNPattern to identify system generated indices and column names.private static FieldURLA field for the raw jdbc url.
-
Constructor Summary
Constructors Constructor Description OracleConnection(Configuration config, Supplier<ClassLoader> classLoaderSupplier)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description StringbuildSelectWithRowLimits(TableId tableId, int limit, String projection, Optional<String> condition, String orderBy)static StringconnectionString(Configuration config)protected Set<TableId>getAllTableIds(String catalogName)Retrieves allTableIdin a given database catalog, filtering certain ids that should be omitted from the returned set such as special spatial tables and index-organized tables.ScngetCurrentScn()Get the current, most recent system change number.ScngetMaxArchiveLogScn(String archiveLogDestinationName)Get the maximum system change number in the archive logs.OracleDatabaseVersiongetOracleVersion()longgetRowCount(String tableName)Returns the number of rows in a given table.Optional<OffsetDateTime>getScnToTimestamp(Scn scn)Resolve a system change number to a timestamp, return value is in database timezone.LonggetSessionStatisticByName(String name)Get the current connection's session statistic by name.private ResultSetgetTableColumnsInfo(String schemaNamePattern, String tableName)StringgetTableMetadataDdl(TableId tableId)Generate a given table's DDL metadata.protected booleanisArchiveLogMode()Determine whether the Oracle server has the archive log enabled.booleanisTableEmpty(String tableName)Returns whether the given table is empty or not.booleanisTableExists(String tableName)Returns whether the given table exists or not.protected booleanisTableUniqueIndexIncluded(String indexName, String columnName)protected ColumnEditoroverrideColumn(ColumnEditor column)voidreadSchemaForCapturedTables(Tables tables, String databaseCatalog, String schemaNamePattern, Tables.ColumnNameFilter columnFilter, boolean removeTablesNotFoundInJdbc, Set<TableId> capturedTables)Set<TableId>readTableNames(String databaseCatalog, String schemaNamePattern, String tableNamePattern, String[] tableTypes)List<String>readTableUniqueIndices(DatabaseMetaData metadata, TableId id)voidresetSessionToCdb()protected StringresolveCatalogName(String catalogName)private static JdbcConnection.ConnectionFactoryresolveConnectionFactory(Configuration config)private OracleDatabaseVersionresolveOracleDatabaseVersion()voidsetSessionToPdb(String pdbName)<T> TsingleOptionalValue(String query, JdbcConnection.ResultSetExtractor<T> extractor)-
Methods inherited from class io.debezium.jdbc.JdbcConnection
call, close, commit, config, connect, connection, connection, connectionString, database, execute, execute, executeWithoutCommitting, getColumnValue, isConnected, isNullable, isValid, parseSqlStatementString, patternBasedFactory, patternBasedFactory, prepareQuery, prepareQuery, prepareQuery, prepareQuery, prepareQuery, prepareQueryAndMap, prepareQueryWithBlockingConsumer, prepareUpdate, print, print, query, query, queryAndMap, queryAndMap, querySingleValue, queryWithBlockingConsumer, quotedColumnIdString, quotedTableIdString, readAllCatalogNames, readAllSchemaNames, readAllTableNames, readPrimaryKeyNames, readPrimaryKeyOrUniqueIndexNames, readSchema, readTableColumn, readTablePreparedStatement, readTableStatement, resolveJdbcType, resolveNativeType, rollback, rowToArray, setAutoCommit, singleResultMapper, tableTypes, username
-
-
-
-
Field Detail
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
ORACLE_UNSET_SCALE
private static final int ORACLE_UNSET_SCALE
Returned by column metadata in Oracle if no scale is set;- See Also:
- Constant Field Values
-
SYS_NC_PATTERN
private static final Pattern SYS_NC_PATTERN
Pattern to identify system generated indices and column names.
-
URL
private static final Field URL
A field for the raw jdbc url. This field has no default value.
-
databaseVersion
private final OracleDatabaseVersion databaseVersion
The database version.
-
QUOTED_CHARACTER
private static final String QUOTED_CHARACTER
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
OracleConnection
public OracleConnection(Configuration config, Supplier<ClassLoader> classLoaderSupplier)
-
-
Method Detail
-
setSessionToPdb
public void setSessionToPdb(String pdbName)
-
resetSessionToCdb
public void resetSessionToCdb()
-
getOracleVersion
public OracleDatabaseVersion getOracleVersion()
-
resolveOracleDatabaseVersion
private OracleDatabaseVersion resolveOracleDatabaseVersion()
-
readTableNames
public Set<TableId> readTableNames(String databaseCatalog, String schemaNamePattern, String tableNamePattern, String[] tableTypes) throws SQLException
- Overrides:
readTableNamesin classJdbcConnection- Throws:
SQLException
-
getAllTableIds
protected Set<TableId> getAllTableIds(String catalogName) throws SQLException
Retrieves allTableIdin a given database catalog, filtering certain ids that should be omitted from the returned set such as special spatial tables and index-organized tables.- Parameters:
catalogName- the catalog/database name- Returns:
- set of all table ids for existing table objects
- Throws:
SQLException- if a database exception occurred
-
getTableColumnsInfo
private ResultSet getTableColumnsInfo(String schemaNamePattern, String tableName) throws SQLException
- Throws:
SQLException
-
readSchemaForCapturedTables
public void readSchemaForCapturedTables(Tables tables, String databaseCatalog, String schemaNamePattern, Tables.ColumnNameFilter columnFilter, boolean removeTablesNotFoundInJdbc, Set<TableId> capturedTables) throws SQLException
- Throws:
SQLException
-
resolveCatalogName
protected String resolveCatalogName(String catalogName)
- Overrides:
resolveCatalogNamein classJdbcConnection
-
readTableUniqueIndices
public List<String> readTableUniqueIndices(DatabaseMetaData metadata, TableId id) throws SQLException
- Overrides:
readTableUniqueIndicesin classJdbcConnection- Throws:
SQLException
-
isTableUniqueIndexIncluded
protected boolean isTableUniqueIndexIncluded(String indexName, String columnName)
- Overrides:
isTableUniqueIndexIncludedin classJdbcConnection
-
getCurrentScn
public Scn getCurrentScn() throws SQLException
Get the current, most recent system change number.- Returns:
- the current system change number
- Throws:
SQLException- if an exception occurredIllegalStateException- if the query does not return at least one row
-
getMaxArchiveLogScn
public Scn getMaxArchiveLogScn(String archiveLogDestinationName) throws SQLException
Get the maximum system change number in the archive logs.- Parameters:
archiveLogDestinationName- the archive log destination name to be queried, can benull.- Returns:
- the maximum system change number in the archive logs
- Throws:
SQLException- if a database exception occurredio.debezium.DebeziumException- if the maximum archive log system change number could not be found
-
getTableMetadataDdl
public String getTableMetadataDdl(TableId tableId) throws SQLException
Generate a given table's DDL metadata.- Parameters:
tableId- table identifier, should never benull- Returns:
- generated DDL
- Throws:
SQLException- if an exception occurred obtaining the DDL metadata
-
getSessionStatisticByName
public Long getSessionStatisticByName(String name) throws SQLException
Get the current connection's session statistic by name.- Parameters:
name- the name of the statistic to be fetched, must not benull- Returns:
- the session statistic value, never
null - Throws:
SQLException- if an exception occurred obtaining the session statistic value
-
isTableExists
public boolean isTableExists(String tableName) throws SQLException
Returns whether the given table exists or not.- Parameters:
tableName- table name, should not benull- Returns:
- true if the table exists, false if it does not
- Throws:
SQLException- if a database exception occurred
-
isTableEmpty
public boolean isTableEmpty(String tableName) throws SQLException
Returns whether the given table is empty or not.- Parameters:
tableName- table name, should not benull- Returns:
- true if the table has no records, false otherwise
- Throws:
SQLException- if a database exception occurred
-
getRowCount
public long getRowCount(String tableName) throws SQLException
Returns the number of rows in a given table.- Parameters:
tableName- table name, should not benull- Returns:
- the number of rows
- Throws:
SQLException- if a database exception occurred
-
singleOptionalValue
public <T> T singleOptionalValue(String query, JdbcConnection.ResultSetExtractor<T> extractor) throws SQLException
- Throws:
SQLException
-
buildSelectWithRowLimits
public String buildSelectWithRowLimits(TableId tableId, int limit, String projection, Optional<String> condition, String orderBy)
- Overrides:
buildSelectWithRowLimitsin classJdbcConnection
-
connectionString
public static String connectionString(Configuration config)
-
resolveConnectionFactory
private static JdbcConnection.ConnectionFactory resolveConnectionFactory(Configuration config)
-
isArchiveLogMode
protected boolean isArchiveLogMode()
Determine whether the Oracle server has the archive log enabled.- Returns:
trueif the server'sLOG_MODEis set toARCHIVELOG, orfalseotherwise
-
getScnToTimestamp
public Optional<OffsetDateTime> getScnToTimestamp(Scn scn) throws SQLException
Resolve a system change number to a timestamp, return value is in database timezone. The SCN to TIMESTAMP mapping is only retained for the duration of the flashback query area. This means that eventually the mapping between these values are no longer kept by Oracle and making a call with a SCN value that has aged out will result in an ORA-08181 error. This function explicitly checks for this use case and if a ORA-08181 error is thrown, it is therefore treated as if a value does not exist returning an empty optional value.- Parameters:
scn- the system change number, must not benull- Returns:
- an optional timestamp when the system change number occurred
- Throws:
SQLException- if a database exception occurred
-
overrideColumn
protected ColumnEditor overrideColumn(ColumnEditor column)
- Overrides:
overrideColumnin classJdbcConnection
-
-