Class LogMinerQueryBuilder


  • public class LogMinerQueryBuilder
    extends Object
    A builder that is responsible for producing the query to be executed against the LogMiner view.
    Author:
    Chris Cranford
    • Constructor Detail

      • LogMinerQueryBuilder

        public LogMinerQueryBuilder()
    • Method Detail

      • build

        public static String build​(OracleConnectorConfig connectorConfig,
                                   OracleDatabaseSchema schema)
        Builds the LogMiner contents view query. The returned query will contain 2 bind parameters that the caller is responsible for binding before executing the query. The first bind parameter is the lower-bounds of the SCN mining window that is not-inclusive while the second is the upper-bounds of the SCN mining window that is inclusive. The built query relies on the following columns from V$LOGMNR_CONTENTS:
             SCN - the system change number at which the change was made
             SQL_REDO - the reconstructed SQL statement that initiated the change
             OPERATION - the database operation type name
             OPERATION_CODE - the database operation numeric code
             TIMESTAMP - the time when the change event occurred
             XID - the transaction identifier the change participated in
             CSF - the continuation flag, identifies rows that should be processed together as single row, 0=no, 1=yes
             TABLE_NAME - the name of the table for which the change is for
             SEG_OWNER - the name of the schema for which the change is for
             USERNAME - the name of the database user that caused the change
             ROW_ID - the unique identifier of the row that the change is for, may not always be set with valid value
             ROLLBACK - the rollback flag, value of 0 or 1.  1 implies the row was rolled back
             RS_ID - the rollback segment idenifier where the change record was record from
         
        Parameters:
        connectorConfig - connector configuration, should not be null
        schema - database schema, should not be null
        Returns:
        the SQL string to be used to fetch changes from Oracle LogMiner
      • buildDdlPredicate

        private static String buildDdlPredicate​(String pdbPredicate)
        Builds a common SQL fragment used to obtain DDL operations via LogMiner.
        Parameters:
        pdbPredicate - pluggable database predicate, maybe null
        Returns:
        predicate that can be used to obtain DDL operations via LogMiner
      • buildSchemaPredicate

        private static String buildSchemaPredicate​(OracleConnectorConfig connectorConfig)
        Builds a SQL predicate of what schemas to include/exclude based on the connector configuration.
        Parameters:
        connectorConfig - connector configuration, should not be null
        Returns:
        SQL predicate to filter results based on schema include/exclude configurations
      • buildTablePredicate

        private static String buildTablePredicate​(OracleConnectorConfig connectorConfig)
        Builds a SQL predicate of what tables to include/exclude based on the connector configuration.
        Parameters:
        connectorConfig - connector configuration, should not be null
        Returns:
        SQL predicate to filter results based on table include/exclude configuration
      • listOfPatternsToSql

        private static String listOfPatternsToSql​(List<Pattern> patterns,
                                                  String columnName,
                                                  boolean inclusion)
        Takes a list of reg-ex patterns and builds an Oracle-specific predicate using REGEXP_LIKE in order to take the connector configuration include/exclude lists and assemble them as SQL predicates.
        Parameters:
        patterns - list of each individual include/exclude reg-ex patterns from connector configuration
        columnName - the column in which the reg-ex patterns are to be applied against
        inclusion - should be true when passing inclusion patterns, false otherwise
        Returns:
      • resolveRegExpLikePattern

        private static String resolveRegExpLikePattern​(Pattern pattern)
        The REGEXP_LIKE Oracle operator acts identical to the LIKE operator. Internally, it prepends and appends a "%" qualifier. The include/exclude lists are meant to be explicit in that they have an implied "^" and "$" qualifier for start/end so that the LIKE operation does not mistakently filter "DEBEZIUM2" when using the reg-ex of "DEBEZIUM".
        Parameters:
        pattern - the pattern to be analyzed, should not be null
        Returns:
        the adjusted predicate, if necessary and doesn't already explicitly specify "^" or "$"
      • resolveExcludedSchemaPredicate

        private static String resolveExcludedSchemaPredicate​(String fieldName)
        Resolve the built-in excluded schemas predicate.
        Parameters:
        fieldName - the query field name the predicate applies to, should never be null
        Returns:
        the predicate