Class LogMinerDmlParser

  • All Implemented Interfaces:
    DmlParser

    public class LogMinerDmlParser
    extends Object
    implements DmlParser
    A simple DML parser implementation specifically for Oracle LogMiner. The syntax of each DML operation is restricted to the format generated by Oracle LogMiner. The following are examples of each expected syntax:
         insert into "schema"."table"("C1","C2") values ('v1','v2');
         update "schema"."table" set "C1" = 'v1a', "C2" = 'v2a' where "C1" = 'v1' and "C2" = 'v2';
         delete from "schema"."table" where "C1" = 'v1' AND "C2" = 'v2';
     
    Certain data types are not emitted as string literals, such as DATE and TIMESTAMP. For these data types, they're emitted as function calls. The parser can detect this use case and will emit the values for such columns as the explicit function call. Lets take the following UPDATE statement:
         update "schema"."table"
            set "C1" = TO_TIMESTAMP('2020-02-02 00:00:00', 'YYYY-MM-DD HH24:MI:SS')
          where "C1" = TO_TIMESTAMP('2020-02-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS');
     
    The new value for C1 would be TO_TIMESTAMP('2020-02-02 00:00:00', 'YYYY-MM-DD HH24:MI:SS'). The old value for C1 would be TO_TIMESTAMP('2020-02-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS').
    Author:
    Chris Cranford
    • Constructor Detail

      • LogMinerDmlParser

        public LogMinerDmlParser()
    • Method Detail

      • parse

        public LogMinerDmlEntry parse​(String sql,
                                      Table table,
                                      String txId)
        Description copied from interface: DmlParser
        Parse a DML SQL string from the LogMiner event stream.
        Specified by:
        parse in interface DmlParser
        Parameters:
        sql - the sql statement
        table - the table the sql statement is for
        txId - the current transaction id the sql is part of.
        Returns:
        the parsed sql as a DML entry or null if the SQL couldn't be parsed.
      • parseInsert

        private LogMinerDmlEntry parseInsert​(String sql,
                                             Table table)
        Parse an INSERT SQL statement.
        Parameters:
        sql - the sql statement
        table - the table
        Returns:
        the parsed DML entry record or null if the SQL was not parsed
      • createMap

        private static <K,​V> Map<K,​V> createMap​(List<K> keys,
                                                            List<V> values)
      • parseUpdate

        private LogMinerDmlEntry parseUpdate​(String sql,
                                             Table table)
        Parse an UPDATE SQL statement.
        Parameters:
        sql - the sql statement
        table - the table
        Returns:
        the parsed DML entry record or null if the SQL was not parsed
      • parseDelete

        private LogMinerDmlEntry parseDelete​(String sql,
                                             Table table)
        Parses a SQL DELETE statement.
        Parameters:
        sql - the sql statement
        table - the table
        Returns:
        the parsed DML entry record or null if the SQL was not parsed
      • parseTableName

        private int parseTableName​(String sql,
                                   int index)
        Parses a table-name in the SQL clause
        Parameters:
        sql - the sql statement
        index - the index into the sql statement to begin parsing
        Returns:
        the index into the sql string where the table name ended
      • parseColumnListClause

        private int parseColumnListClause​(String sql,
                                          int start,
                                          List<String> columnNames)
        Parse an INSERT statement's column-list clause.
        Parameters:
        sql - the sql statement
        start - the index into the sql statement to begin parsing
        columnNames - the list that will be populated with the column names
        Returns:
        the index into the sql string where the column-list clause ended
      • parseColumnValuesClause

        private int parseColumnValuesClause​(String sql,
                                            int start,
                                            List<String> columnValues)
        Parse an INSERT statement's column-values clause.
        Parameters:
        sql - the sql statement
        start - the index into the sql statement to begin parsing
        columnValues - the list of that will populated with the column values
        Returns:
        the index into the sql string where the column-values clause ended
      • parseSetClause

        private int parseSetClause​(String sql,
                                   int start,
                                   List<String> columnNames,
                                   List<String> columnValues)
        Parse an UPDATE statement's SET clause.
        Parameters:
        sql - the sql statement
        start - the index into the sql statement to begin parsing
        columnNames - the list of the changed column names that will be populated
        columnValues - the list of the changed column values that will be populated
        Returns:
        the index into the sql string where the set-clause ended
      • parseWhereClause

        private int parseWhereClause​(String sql,
                                     int start,
                                     List<String> columnNames,
                                     List<String> columnValues)
        Parses a WHERE clause populates the provided column names and values arrays.
        Parameters:
        sql - the sql statement
        start - the index into the sql statement to begin parsing
        columnNames - the column names parsed from the clause
        columnValues - the column values parsed from the clause
        Returns:
        the index into the sql string to continue parsing
      • removeSingleQuotes

        private static String removeSingleQuotes​(String text)
        Remove ' quotes from around the provided text if they exist; otherwise the value is returned as-is.
        Parameters:
        text - the text to remove single quotes
        Returns:
        the text with single quotes removed
      • createColumnValue

        private static LogMinerColumnValue createColumnValue​(String columnName,
                                                             String columnValue)
        Helper method to create a LogMinerColumnValue from a column name/value pair.
        Parameters:
        columnName - the column name
        columnValue - the column value
        Returns:
        the LogMiner column value object