Class OracleConnection

java.lang.Object
io.debezium.jdbc.JdbcConnection
io.debezium.connector.oracle.OracleConnection
All Implemented Interfaces:
AutoCloseable

public class OracleConnection extends JdbcConnection
  • Field Details

    • 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:
    • SYS_NC_PATTERN

      private static final Pattern SYS_NC_PATTERN
      Pattern to identify system generated indices and column names.
    • ADT_INDEX_NAMES_PATTERN

      private static final Pattern ADT_INDEX_NAMES_PATTERN
      Pattern to identify abstract data type indices and column names.
    • MROW_PATTERN

      private static final Pattern MROW_PATTERN
      Pattern to identify a hidden column based on redefining a table with the ROWID option.
    • 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:
  • Constructor Details

  • Method Details

    • 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:
      readTableNames in class JdbcConnection
      Throws:
      SQLException
    • getAllTableIds

      protected Set<TableId> getAllTableIds(String catalogName) throws SQLException
      Retrieves all TableId in 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
    • resolveCatalogName

      protected String resolveCatalogName(String catalogName)
      Overrides:
      resolveCatalogName in class JdbcConnection
    • readTableUniqueIndices

      public List<String> readTableUniqueIndices(DatabaseMetaData metadata, TableId id) throws SQLException
      Overrides:
      readTableUniqueIndices in class JdbcConnection
      Throws:
      SQLException
    • isTableUniqueIndexIncluded

      protected boolean isTableUniqueIndexIncluded(String indexName, String columnName)
      Overrides:
      isTableUniqueIndexIncluded in class JdbcConnection
    • 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 occurred
      IllegalStateException - if the query does not return at least one row
    • getTableMetadataDdl

      public String getTableMetadataDdl(TableId tableId) throws SQLException
      Generate a given table's DDL metadata.
      Parameters:
      tableId - table identifier, should never be null
      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 be null
      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 be null
      Returns:
      true if the table exists, false if it does not
      Throws:
      SQLException - if a database exception occurred
    • isTableExists

      public boolean isTableExists(TableId tableId) throws SQLException
      Throws:
      SQLException
    • isTableEmpty

      public boolean isTableEmpty(String tableName) throws SQLException
      Returns whether the given table is empty or not.
      Parameters:
      tableName - table name, should not be null
      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 be null
      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:
      buildSelectWithRowLimits in class JdbcConnection
    • connectionString

      public static String connectionString(JdbcConfiguration config)
    • resolveConnectionFactory

      private static JdbcConnection.ConnectionFactory resolveConnectionFactory(JdbcConfiguration config)
    • isArchiveLogMode

      protected boolean isArchiveLogMode()
      Determine whether the Oracle server has the archive log enabled.
      Returns:
      true if the server's LOG_MODE is set to ARCHIVELOG, or false otherwise
    • 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 be null
      Returns:
      an optional timestamp when the system change number occurred
      Throws:
      SQLException - if a database exception occurred
    • overrideColumn

      protected ColumnEditor overrideColumn(ColumnEditor column)
      Overrides:
      overrideColumn in class JdbcConnection
    • getColumnsDetails

      protected Map<TableId,List<Column>> getColumnsDetails(String databaseCatalog, String schemaNamePattern, String tableName, Tables.TableFilter tableFilter, Tables.ColumnNameFilter columnFilter, DatabaseMetaData metadata, Set<TableId> viewIds) throws SQLException
      Overrides:
      getColumnsDetails in class JdbcConnection
      Throws:
      SQLException