Package io.debezium.antlr
Class AntlrDdlParser<L extends org.antlr.v4.runtime.Lexer,P extends org.antlr.v4.runtime.Parser>
java.lang.Object
io.debezium.relational.ddl.AbstractDdlParser
io.debezium.antlr.AntlrDdlParser<L,P>
- All Implemented Interfaces:
DdlParser
public abstract class AntlrDdlParser<L extends org.antlr.v4.runtime.Lexer,P extends org.antlr.v4.runtime.Parser>
extends AbstractDdlParser
Base implementation of ANTLR based parsers.
This abstract class provides generic initialization of parser and its main sequence of steps that are needed to properly start parsing. It also provides implementation of helper methods for any type of ANTLR listeners.
- Author:
- Roman Kuchár <kucharrom@gmail.com>.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate AntlrDdlParserListenerParser listener for tree walker.protected Tablesprotected DataTypeResolverprivate final booleanFlag to indicate if the errors caught during tree walk will be thrown.Fields inherited from class io.debezium.relational.ddl.AbstractDdlParser
ddlChanges, logger, skipComments, skipViews, systemVariables -
Constructor Summary
ConstructorsConstructorDescriptionAntlrDdlParser(boolean throwErrorsFromTreeWalk) AntlrDdlParser(boolean throwErrorsFromTreeWalk, boolean includeViews, boolean includeComments) -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract LcreateNewLexerInstance(org.antlr.v4.runtime.CharStream charStreams) Creates a new generic type instance of ANTLR Lexer.protected abstract PcreateNewParserInstance(org.antlr.v4.runtime.CommonTokenStream commonTokenStream) Creates a new generic type instance of ANTLR Parser.protected abstract AntlrDdlParserListenerCreates a new instance of parsed tree walker listener.Returns actual tables schema.Returns a data type resolver component.voiddebugParsed(org.antlr.v4.runtime.ParserRuleContext ctx) voiddebugSkipped(org.antlr.v4.runtime.ParserRuleContext ctx) Returns errors catched during tree walk.static StringgetText(org.antlr.v4.runtime.ParserRuleContext ctx) Returns matched part of the getText for the context.static StringgetText(org.antlr.v4.runtime.ParserRuleContext ctx, int start, int stop) Returns matched part of the getText for the context.protected abstract DataTypeResolverInitialize DB to JDBC data types mapping for resolver.protected abstract booleanCheck if the parsed grammar is written in upper case.voidprotected abstract org.antlr.v4.runtime.tree.ParseTreeExamine the supplied string containing DDL statements, and apply those statements to the specified database table definitions.voidsignalAlterDatabase(String databaseName, String previousDatabaseName, org.antlr.v4.runtime.ParserRuleContext ctx) Signal an alter database event to ddl changes listener.voidsignalAlterTable(TableId id, TableId previousId, MySqlParser.RenameTableClauseContext ctx) Signal an alter table event to ddl changes listener.voidsignalAlterTable(TableId id, TableId previousId, org.antlr.v4.runtime.ParserRuleContext ctx) Signal an alter table event to ddl changes listener.voidsignalAlterView(TableId id, TableId previousId, org.antlr.v4.runtime.ParserRuleContext ctx) Signal an alter view event to ddl changes listener.voidsignalCreateDatabase(String databaseName, org.antlr.v4.runtime.ParserRuleContext ctx) Signal a create database event to ddl changes listener.voidsignalCreateIndex(String indexName, TableId id, org.antlr.v4.runtime.ParserRuleContext ctx) Signal a create index event to ddl changes listener.voidsignalCreateTable(TableId id, org.antlr.v4.runtime.ParserRuleContext ctx) Signal a create table event to ddl changes listener.voidsignalCreateView(TableId id, org.antlr.v4.runtime.ParserRuleContext ctx) Signal a create view event to ddl changes listener.voidsignalDropDatabase(String databaseName, org.antlr.v4.runtime.ParserRuleContext ctx) Signal a drop database event to ddl changes listener.voidsignalDropIndex(String indexName, TableId id, org.antlr.v4.runtime.ParserRuleContext ctx) Signal a drop index event to ddl changes listener.voidsignalDropTable(TableId id, String statement) voidsignalDropTable(TableId id, org.antlr.v4.runtime.ParserRuleContext ctx) Signal a drop table event to ddl changes listener.voidsignalDropView(TableId id, org.antlr.v4.runtime.ParserRuleContext ctx) Signal a drop view event to ddl changes listener.voidsignalSetVariable(String variableName, String variableValue, int order, org.antlr.v4.runtime.ParserRuleContext ctx) voidsignalTruncateTable(TableId id, org.antlr.v4.runtime.ParserRuleContext ctx) Signal a truncate table event to ddl changes listener.voidsignalUseDatabase(org.antlr.v4.runtime.ParserRuleContext ctx) booleanbooleanprivate voidwithoutQuotes(org.antlr.v4.runtime.ParserRuleContext ctx) Methods inherited from class io.debezium.relational.ddl.AbstractDdlParser
accumulateParsingFailure, accumulateParsingFailure, commentParsed, createColumnFromConstant, createNewSystemVariablesInstance, currentSchema, debugParsed, debugSkipped, getDdlChanges, isQuote, isQuoted, removeLineFeeds, resolveTableId, setCurrentDatabase, setCurrentSchema, setTypeInfoForConstant, signalAlterDatabase, signalAlterTable, signalAlterView, signalChangeEvent, signalCreateDatabase, signalCreateIndex, signalCreateTable, signalCreateView, signalDropDatabase, signalDropIndex, signalDropView, signalSetVariable, signalTruncateTable, signalUseDatabase, systemVariables, terminator, withoutQuotes
-
Field Details
-
throwErrorsFromTreeWalk
private final boolean throwErrorsFromTreeWalkFlag to indicate if the errors caught during tree walk will be thrown. true = errors will be thrown false = errors will not be thrown. They will be available to get bygetParsingExceptionsFromWalker(). -
antlrDdlParserListener
Parser listener for tree walker. -
databaseTables
-
dataTypeResolver
-
-
Constructor Details
-
AntlrDdlParser
public AntlrDdlParser(boolean throwErrorsFromTreeWalk) -
AntlrDdlParser
public AntlrDdlParser(boolean throwErrorsFromTreeWalk, boolean includeViews, boolean includeComments)
-
-
Method Details
-
parse
-
getParsingExceptionsFromWalker
Returns errors catched during tree walk.- Returns:
- collection of
ParsingExceptions.
-
parseTree
Examine the supplied string containing DDL statements, and apply those statements to the specified database table definitions.- Parameters:
parser- initialized ANTLR parser instance with common token stream from DDL statement; may not be null
-
createParseTreeWalkerListener
Creates a new instance of parsed tree walker listener.- Returns:
- new instance of parser listener.
-
createNewLexerInstance
Creates a new generic type instance of ANTLR Lexer.- Parameters:
charStreams- the char stream from DDL statement, without one line comments and line feeds; may not be null- Returns:
- new instance of generic ANTLR Lexer
-
createNewParserInstance
protected abstract P createNewParserInstance(org.antlr.v4.runtime.CommonTokenStream commonTokenStream) Creates a new generic type instance of ANTLR Parser.- Parameters:
commonTokenStream- the stream of ANTLR tokens created from Lexer instance; may not be null- Returns:
- new instance of generic ANTLR Parser
-
isGrammarInUpperCase
protected abstract boolean isGrammarInUpperCase()Check if the parsed grammar is written in upper case.- Returns:
- true if grammar is written in upper case; false if in lower case
-
initializeDataTypeResolver
Initialize DB to JDBC data types mapping for resolver.- Parameters:
dataTypeResolver- data type resolver
-
databaseTables
Returns actual tables schema.- Returns:
- table schema.
-
dataTypeResolver
Returns a data type resolver component.- Returns:
- data type resolver.
-
getText
Returns matched part of the getText for the context.- Parameters:
ctx- the parser rule context; may not be null- Returns:
- matched part of the getText
-
getText
Returns matched part of the getText for the context.- Parameters:
ctx- the parser rule context; may not be nullstart- the interval start positionstop- the interval stop position- Returns:
- matched part of the getText
-
skipViews
public boolean skipViews() -
skipComments
public boolean skipComments()- Overrides:
skipCommentsin classAbstractDdlParser
-
signalSetVariable
-
signalUseDatabase
public void signalUseDatabase(org.antlr.v4.runtime.ParserRuleContext ctx) -
signalCreateDatabase
Signal a create database event to ddl changes listener.- Parameters:
databaseName- the database name; may not be nullctx- the start of the statement; may not be null
-
signalAlterDatabase
public void signalAlterDatabase(String databaseName, String previousDatabaseName, org.antlr.v4.runtime.ParserRuleContext ctx) Signal an alter database event to ddl changes listener.- Parameters:
databaseName- the database name; may not be nullpreviousDatabaseName- the previous name of the database if it was renamed, or null if it was not renamedctx- the start of the statement; may not be null
-
signalDropDatabase
Signal a drop database event to ddl changes listener.- Parameters:
databaseName- the database name; may not be nullctx- the start of the statement; may not be null
-
signalCreateTable
Signal a create table event to ddl changes listener.- Parameters:
id- the table identifier; may not be nullctx- the start of the statement; may not be null
-
signalAlterTable
public void signalAlterTable(TableId id, TableId previousId, MySqlParser.RenameTableClauseContext ctx) Signal an alter table event to ddl changes listener.- Parameters:
id- the table identifier; may not be nullpreviousId- the previous name of the view if it was renamed, or null if it was not renamedctx- the start of the statement; may not be null
-
signalAlterTable
public void signalAlterTable(TableId id, TableId previousId, org.antlr.v4.runtime.ParserRuleContext ctx) Signal an alter table event to ddl changes listener.- Parameters:
id- the table identifier; may not be nullpreviousId- the previous name of the view if it was renamed, or null if it was not renamedctx- the start of the statement; may not be null
-
signalDropTable
- Overrides:
signalDropTablein classAbstractDdlParser
-
signalDropTable
Signal a drop table event to ddl changes listener.- Parameters:
id- the table identifier; may not be nullctx- the start of the statement; may not be null
-
signalTruncateTable
Signal a truncate table event to ddl changes listener.- Parameters:
id- the table identifier; may not be nullctx- the start of the statement; may not be null
-
signalCreateView
Signal a create view event to ddl changes listener.- Parameters:
id- the table identifier; may not be nullctx- the start of the statement; may not be null
-
signalAlterView
public void signalAlterView(TableId id, TableId previousId, org.antlr.v4.runtime.ParserRuleContext ctx) Signal an alter view event to ddl changes listener.- Parameters:
id- the table identifier; may not be nullpreviousId- the previous name of the view if it was renamed, or null if it was not renamedctx- the start of the statement; may not be null
-
signalDropView
Signal a drop view event to ddl changes listener.- Parameters:
id- the table identifier; may not be nullctx- the start of the statement; may not be null
-
signalCreateIndex
public void signalCreateIndex(String indexName, TableId id, org.antlr.v4.runtime.ParserRuleContext ctx) Signal a create index event to ddl changes listener.- Parameters:
indexName- the name of the index; may not be nullid- the table identifier; may be null if the index does not apply to a single tablectx- the start of the statement; may not be null
-
signalDropIndex
public void signalDropIndex(String indexName, TableId id, org.antlr.v4.runtime.ParserRuleContext ctx) Signal a drop index event to ddl changes listener.- Parameters:
indexName- the name of the index; may not be nullid- the table identifier; may not be nullctx- the start of the statement; may not be null
-
debugParsed
public void debugParsed(org.antlr.v4.runtime.ParserRuleContext ctx) -
debugSkipped
public void debugSkipped(org.antlr.v4.runtime.ParserRuleContext ctx) -
withoutQuotes
-
throwParsingException
-