Package io.debezium.relational.ddl
Class AbstractDdlParser
- java.lang.Object
-
- io.debezium.relational.ddl.AbstractDdlParser
-
-
Field Summary
Fields Modifier and Type Field Description private String
currentSchema
protected DdlChanges
ddlChanges
protected org.slf4j.Logger
logger
protected boolean
skipComments
protected boolean
skipViews
protected SystemVariables
systemVariables
private String
terminator
-
Constructor Summary
Constructors Constructor Description AbstractDdlParser(String terminator)
Create a new parser that uses the suppliedDataTypeParser
, but that does not include view definitions.AbstractDdlParser(String terminator, boolean includeViews, boolean includeComments)
Create a new parser that uses the suppliedDataTypeParser
.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected Collection<ParsingException>
accumulateParsingFailure(MultipleParsingExceptions e, Collection<ParsingException> list)
Utility method to accumulate a parsing exception.static Collection<ParsingException>
accumulateParsingFailure(ParsingException e, Collection<ParsingException> list)
Utility method to accumulate a parsing exception.protected void
commentParsed(String comment)
protected Column
createColumnFromConstant(String columnName, String constantValue)
protected abstract SystemVariables
createNewSystemVariablesInstance()
String
currentSchema()
Get the name of the current schema.protected void
debugParsed(String statement)
protected void
debugSkipped(String statement)
DdlChanges
getDdlChanges()
static boolean
isQuote(char c)
Check if the char is quote.static boolean
isQuoted(String possiblyQuoted)
Check if the string is enclosed in quotes.protected String
removeLineFeeds(String input)
Removes line feeds from input string.TableId
resolveTableId(String schemaName, String tableName)
Create aTableId
from the supplied schema and table names.void
setCurrentDatabase(String databaseName)
void
setCurrentSchema(String schemaName)
Set the name of the current schema.protected void
setTypeInfoForConstant(String constantValue, ColumnEditor column)
protected void
signalAlterDatabase(String databaseName, String previousDatabaseName, String statement)
Signal an alter database event to ddl changes listener.protected void
signalAlterTable(TableId id, TableId previousId, String statement)
Signal an alter table event to ddl changes listener.protected void
signalAlterView(TableId id, TableId previousId, String statement)
Signal an alter view event to ddl changes listener.protected void
signalChangeEvent(DdlParserListener.Event event)
Signal an event to ddl changes listener.protected void
signalCreateDatabase(String databaseName, String statement)
Signal a create database event to ddl changes listener.protected void
signalCreateIndex(String indexName, TableId id, String statement)
Signal a create index event to ddl changes listener.protected void
signalCreateTable(TableId id, String statement)
Signal a create table event to ddl changes listener.protected void
signalCreateView(TableId id, String statement)
Signal a create view event to ddl changes listener.protected void
signalDropDatabase(String databaseName, String statement)
Signal a drop database event to ddl changes listener.protected void
signalDropIndex(String indexName, TableId id, String statement)
Signal a drop index event to ddl changes listener.protected void
signalDropTable(TableId id, String statement)
Signal a drop table event to ddl changes listener.protected void
signalDropView(TableId id, String statement)
Signal a drop view event to ddl changes listener.protected void
signalSetVariable(String variableName, String variableValue, int order, String statement)
protected void
signalTruncateTable(TableId id, String statement)
Signal a truncate table event to ddl changes listener.protected void
signalUseDatabase(String statement)
protected boolean
skipComments()
Determine whether parsing should exclude comments from the token stream.SystemVariables
systemVariables()
String
terminator()
The token used to terminate a DDL statement.static String
withoutQuotes(String possiblyQuoted)
Cut out the string surrounded with single, double and reversed quotes.
-
-
-
Field Detail
-
terminator
private final String terminator
-
skipViews
protected final boolean skipViews
-
skipComments
protected final boolean skipComments
-
ddlChanges
protected DdlChanges ddlChanges
-
systemVariables
protected SystemVariables systemVariables
-
logger
protected final org.slf4j.Logger logger
-
currentSchema
private String currentSchema
-
-
Constructor Detail
-
AbstractDdlParser
public AbstractDdlParser(String terminator)
Create a new parser that uses the suppliedDataTypeParser
, but that does not include view definitions.- Parameters:
terminator
- the terminator character sequence; may be null if the default terminator (;
) should be used
-
AbstractDdlParser
public AbstractDdlParser(String terminator, boolean includeViews, boolean includeComments)
Create a new parser that uses the suppliedDataTypeParser
.- Parameters:
terminator
- the terminator character sequence; may be null if the default terminator (;
) should be usedincludeViews
-true
if view definitions should be included, orfalse
if they should be skippedincludeComments
-true
if table and column's comment definitions should be included, orfalse
if they should be skipped
-
-
Method Detail
-
setCurrentSchema
public void setCurrentSchema(String schemaName)
Description copied from interface:DdlParser
Set the name of the current schema.- Specified by:
setCurrentSchema
in interfaceDdlParser
- Parameters:
schemaName
- the name of the current schema; may be null
-
setCurrentDatabase
public void setCurrentDatabase(String databaseName)
- Specified by:
setCurrentDatabase
in interfaceDdlParser
-
terminator
public final String terminator()
Description copied from interface:DdlParser
The token used to terminate a DDL statement.- Specified by:
terminator
in interfaceDdlParser
- Returns:
- the terminating token; never null
-
getDdlChanges
public DdlChanges getDdlChanges()
- Specified by:
getDdlChanges
in interfaceDdlParser
-
systemVariables
public SystemVariables systemVariables()
- Specified by:
systemVariables
in interfaceDdlParser
-
createNewSystemVariablesInstance
protected abstract SystemVariables createNewSystemVariablesInstance()
-
currentSchema
public String currentSchema()
Get the name of the current schema.- Returns:
- the current schema name, or null if the current schema name has not been
set
-
resolveTableId
public TableId resolveTableId(String schemaName, String tableName)
Create aTableId
from the supplied schema and table names. By default, this method uses the supplied schema name as the TableId's catalog, which often matches the catalog name in JDBC database metadata.- Parameters:
schemaName
- the name of the schema; may be null if not specifiedtableName
- the name of the table; should not be null- Returns:
- the table identifier; never null
-
skipComments
protected boolean skipComments()
Determine whether parsing should exclude comments from the token stream. By default, this method returnstrue
.- Returns:
true
if comments should be skipped/excluded, orfalse
if they should not be skipped
-
signalChangeEvent
protected void signalChangeEvent(DdlParserListener.Event event)
Signal an event to ddl changes listener.- Parameters:
event
- the event; may not be null
-
signalSetVariable
protected void signalSetVariable(String variableName, String variableValue, int order, String statement)
-
signalUseDatabase
protected void signalUseDatabase(String statement)
-
signalCreateDatabase
protected void signalCreateDatabase(String databaseName, String statement)
Signal a create database event to ddl changes listener.- Parameters:
databaseName
- the database name; may not be nullstatement
- the DDL statement; may not be null
-
signalAlterDatabase
protected void signalAlterDatabase(String databaseName, String previousDatabaseName, String statement)
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 renamedstatement
- the DDL statement; may not be null
-
signalDropDatabase
protected void signalDropDatabase(String databaseName, String statement)
Signal a drop database event to ddl changes listener.- Parameters:
databaseName
- the database name; may not be nullstatement
- the DDL statement; may not be null
-
signalCreateTable
protected void signalCreateTable(TableId id, String statement)
Signal a create table event to ddl changes listener.- Parameters:
id
- the table identifier; may not be nullstatement
- the DDL statement; may not be null
-
signalAlterTable
protected void signalAlterTable(TableId id, TableId previousId, String statement)
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 renamedstatement
- the DDL statement; may not be null
-
signalDropTable
protected void signalDropTable(TableId id, String statement)
Signal a drop table event to ddl changes listener.- Parameters:
id
- the table identifier; may not be nullstatement
- the statement; may not be null
-
signalTruncateTable
protected void signalTruncateTable(TableId id, String statement)
Signal a truncate table event to ddl changes listener.- Parameters:
id
- the table identifier; may not be nullstatement
- the statement; may not be null
-
signalCreateView
protected void signalCreateView(TableId id, String statement)
Signal a create view event to ddl changes listener.- Parameters:
id
- the table identifier; may not be nullstatement
- the DDL statement; may not be null
-
signalAlterView
protected void signalAlterView(TableId id, TableId previousId, String statement)
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 renamedstatement
- the DDL statement; may not be null
-
signalDropView
protected void signalDropView(TableId id, String statement)
Signal a drop view event to ddl changes listener.- Parameters:
id
- the table identifier; may not be nullstatement
- the statement; may not be null
-
signalCreateIndex
protected void signalCreateIndex(String indexName, TableId id, String statement)
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 tablestatement
- the DDL statement; may not be null
-
signalDropIndex
protected void signalDropIndex(String indexName, TableId id, String statement)
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 nullstatement
- the DDL statement; may not be null
-
removeLineFeeds
protected String removeLineFeeds(String input)
Removes line feeds from input string.- Parameters:
input
- input with possible line feeds- Returns:
- input string without line feeds
-
withoutQuotes
public static String withoutQuotes(String possiblyQuoted)
Cut out the string surrounded with single, double and reversed quotes.- Parameters:
possiblyQuoted
- string with possible quotes- Returns:
- string without quotes
-
isQuoted
public static boolean isQuoted(String possiblyQuoted)
Check if the string is enclosed in quotes.- Parameters:
possiblyQuoted
- string with possible quotes- Returns:
- true if the string is quoted, false otherwise
-
isQuote
public static boolean isQuote(char c)
Check if the char is quote.- Parameters:
c
- possible quote char- Returns:
- true if the char is quote false otherwise
-
accumulateParsingFailure
public static Collection<ParsingException> accumulateParsingFailure(ParsingException e, Collection<ParsingException> list)
Utility method to accumulate a parsing exception.- Parameters:
e
- the parsing exceptionlist
- the list of previous parsing exceptions; may be null- Returns:
- the list of previous and current parsing exceptions; if
e
is null then alwayslist
, but otherwise non-null list
-
accumulateParsingFailure
protected Collection<ParsingException> accumulateParsingFailure(MultipleParsingExceptions e, Collection<ParsingException> list)
Utility method to accumulate a parsing exception.- Parameters:
e
- the multiple parsing exceptionslist
- the list of previous parsing exceptions; may be null- Returns:
- the list of previous and current parsing exceptions; if
e
is null then alwayslist
, but otherwise non-null list
-
createColumnFromConstant
protected Column createColumnFromConstant(String columnName, String constantValue)
-
setTypeInfoForConstant
protected void setTypeInfoForConstant(String constantValue, ColumnEditor column)
-
debugParsed
protected void debugParsed(String statement)
-
debugSkipped
protected void debugSkipped(String statement)
-
commentParsed
protected void commentParsed(String comment)
-
-