Class BaseParser

java.lang.Object
migratedb.v1.core.internal.parser.BaseParser
All Implemented Interfaces:
Parser
Direct Known Subclasses:
BigQueryParser, CockroachDBParser, DB2Parser, DerbyParser, FirebirdParser, H2Parser, HSQLDBParser, IgniteThinParser, InformixParser, MySQLParser, OracleParser, PostgreSQLParser, RedshiftParser, SAPHANAParser, SnowflakeParser, SpannerParser, SQLiteParser, SQLServerParser, SybaseASEParser

public abstract class BaseParser extends Object implements Parser
The main parser all database-specific parsers derive from.
  • Field Details

    • LOG

      protected static final Log LOG
  • Constructor Details

  • Method Details

    • getConfiguration

      public Configuration getConfiguration()
      Specified by:
      getConfiguration in interface Parser
    • getParsingContext

      public ParsingContext getParsingContext()
      Specified by:
      getParsingContext in interface Parser
    • getDefaultDelimiter

      protected Delimiter getDefaultDelimiter()
    • getIdentifierQuote

      protected char getIdentifierQuote()
    • getAlternativeIdentifierQuote

      protected char getAlternativeIdentifierQuote()
    • getAlternativeStringLiteralQuote

      protected char getAlternativeStringLiteralQuote()
    • getOpeningIdentifierSymbol

      protected char getOpeningIdentifierSymbol()
    • getClosingIdentifierSymbol

      protected char getClosingIdentifierSymbol()
    • getValidKeywords

      protected Set<String> getValidKeywords()
    • supportsPeekingMultipleLines

      protected boolean supportsPeekingMultipleLines()
    • parse

      public final SqlStatementIterator parse(Resource resource, SqlScriptMetadata metadata)
      Description copied from interface: Parser
      Parses this resource into a stream of statements.
      Specified by:
      parse in interface Parser
      Parameters:
      resource - The resource to parse.
      metadata - The resource's metadata
      Returns:
      The statements.
    • parse

      public final SqlStatementIterator parse(Resource resource)
    • replacePlaceholders

      protected Reader replacePlaceholders(Reader reader, SqlScriptMetadata metadata)
      Configures this reader for placeholder replacement.
      Parameters:
      reader - The original reader.
      metadata - The resource's metadata.
      Returns:
      The new reader with placeholder replacement.
    • getNextStatement

      protected SqlStatement getNextStatement(Resource resource, PeekingReader reader, Recorder recorder, PositionTracker tracker, ParserContext context)
    • shouldAdjustBlockDepth

      protected boolean shouldAdjustBlockDepth(ParserContext context, List<Token> tokens, Token token)
    • shouldDiscard

      protected boolean shouldDiscard(Token token, boolean nonCommentPartSeen)
      Whether the current set of tokens should be discarded.
      Parameters:
      token - The latest token.
      nonCommentPartSeen - Whether a non-comment part has already been seen.
      Returns:
      true if it should, false if not.
    • resetDelimiter

      protected void resetDelimiter(ParserContext context)
      Resets the delimiter to its default value before parsing a new statement.
    • adjustDelimiter

      protected void adjustDelimiter(ParserContext context, StatementType statementType)
      Adjusts the delimiter if necessary for this statement type.
      Parameters:
      statementType - The statement type.
    • getTransactionalDetectionCutoff

      protected int getTransactionalDetectionCutoff()
      Returns:
      The cutoff point in terms of number of tokens after which a statement can no longer be non-transactional.
    • adjustBlockDepth

      protected void adjustBlockDepth(ParserContext context, List<Token> tokens, Token keyword, PeekingReader reader) throws IOException
      Throws:
      IOException
    • getLastKeywordIndex

      protected int getLastKeywordIndex(List<Token> tokens)
    • getLastKeywordIndex

      protected int getLastKeywordIndex(List<Token> tokens, int endIndex)
    • getPreviousToken

      protected static Token getPreviousToken(List<Token> tokens, int parensDepth)
    • lastTokenIs

      protected static boolean lastTokenIs(List<Token> tokens, int parensDepth, String tokenText)
    • lastTokenIsOnLine

      protected static boolean lastTokenIsOnLine(List<Token> tokens, int parensDepth, int line)
    • tokenAtIndexIs

      protected static boolean tokenAtIndexIs(List<Token> tokens, int index, String tokenText)
    • doTokensMatchPattern

      protected boolean doTokensMatchPattern(List<Token> previousTokens, Token current, Pattern regex)
    • createStatement

      protected ParsedSqlStatement createStatement(PeekingReader reader, Recorder recorder, int statementPos, int statementLine, int statementCol, int nonCommentPartPos, int nonCommentPartLine, int nonCommentPartCol, StatementType statementType, boolean canExecuteInTransaction, Delimiter delimiter, String sql) throws IOException
      Throws:
      IOException
    • detectStatementType

      protected StatementType detectStatementType(String simplifiedStatement, ParserContext context, PeekingReader reader)
    • detectCanExecuteInTransaction

      protected Boolean detectCanExecuteInTransaction(String simplifiedStatement, List<Token> keywords)
    • readKeyword

      protected String readKeyword(PeekingReader reader, Delimiter delimiter, ParserContext context) throws IOException
      Throws:
      IOException
    • readIdentifier

      protected String readIdentifier(PeekingReader reader) throws IOException
      Throws:
      IOException
    • handleDelimiter

      protected Token handleDelimiter(PeekingReader reader, ParserContext context, int pos, int line, int col) throws IOException
      Throws:
      IOException
    • isAlternativeStringLiteral

      protected boolean isAlternativeStringLiteral(String peek)
    • isDelimiter

      protected boolean isDelimiter(String peek, ParserContext context, int col, int colIgnoringWhitespace)
    • isLetter

      protected boolean isLetter(char c, ParserContext context)
    • isSingleLineComment

      protected boolean isSingleLineComment(String peek, ParserContext context, int col)
    • isKeyword

      protected boolean isKeyword(String text)
    • isCommentDirective

      protected boolean isCommentDirective(String peek)
    • handleCommentDirective

      protected Token handleCommentDirective(PeekingReader reader, ParserContext context, int pos, int line, int col) throws IOException
      Throws:
      IOException
    • handleStringLiteral

      protected Token handleStringLiteral(PeekingReader reader, ParserContext context, int pos, int line, int col) throws IOException
      Throws:
      IOException
    • handleAlternativeStringLiteral

      protected Token handleAlternativeStringLiteral(PeekingReader reader, ParserContext context, int pos, int line, int col) throws IOException
      Throws:
      IOException
    • handleKeyword

      protected Token handleKeyword(PeekingReader reader, ParserContext context, int pos, int line, int col, String keyword) throws IOException
      Throws:
      IOException