@NotThreadSafe public class LegacyDdlParser extends AbstractDdlParser implements DdlParser
| Modifier and Type | Class and Description |
|---|---|
protected static interface |
LegacyDdlParser.TokenSet |
| Modifier and Type | Field and Description |
|---|---|
protected Tables |
databaseTables |
protected DataTypeParser |
dataTypeParser |
private Set<String> |
keywords |
private List<DdlParserListener> |
listeners |
protected org.slf4j.Logger |
logger |
private Set<String> |
statementStarts |
protected TokenStream |
tokens |
ddlChanges, skipViews, systemVariables| Constructor and Description |
|---|
LegacyDdlParser(String terminator)
Create a new parser that uses the supplied
DataTypeParser, but that does not include view definitions. |
LegacyDdlParser(String terminator,
boolean includeViews)
Create a new parser that uses the supplied
DataTypeParser. |
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(DdlParserListener listener) |
protected boolean |
canConsumeJoin(TokenStream.Marker start) |
protected boolean |
canConsumeJoinCondition(TokenStream.Marker start) |
protected void |
consumeBeginStatement(TokenStream.Marker start)
Consume the entire
BEGIN...END block that appears next in the token stream. |
protected String |
consumeDoubleQuotedString()
Consume the next token that is a double-quoted string.
|
protected String |
consumeQuotedString()
Consume the next token that is either a single-quoted string or a double-quoted string.
|
protected void |
consumeRemainingStatement(TokenStream.Marker start)
Consume all tokens from the current position until and including either the
end-of-statement
terminator token or one of
the tokens that is registered as the start of a statement. |
protected String |
consumeSingleQuotedString()
Consume the next token that is a single-quoted string.
|
protected void |
consumeStatement()
Consume all tokens from the current position that is a
starting-statement
token until either the
end-of-statement terminator token or before the next
starting-statement token. |
protected SystemVariables |
createNewSystemVariablesInstance() |
protected void |
debugParsed(TokenStream.Marker statementStart) |
protected void |
debugSkipped(TokenStream.Marker statementStart) |
protected int |
determineTokenType(int type,
String token) |
protected String |
determineTypeNameForConstant(BigDecimal value) |
protected String |
determineTypeNameForConstant(double value) |
protected String |
determineTypeNameForConstant(float value) |
protected String |
determineTypeNameForConstant(long value) |
protected void |
initializeDataTypes(DataTypeParser dataTypeParser) |
protected void |
initializeKeywords(LegacyDdlParser.TokenSet keywords) |
protected void |
initializeStatementStarts(LegacyDdlParser.TokenSet statementStartTokens) |
protected boolean |
isNextTokenQuotedIdentifier()
Determine if the next token is a single- or double-quoted string.
|
void |
parse(String ddlContent,
Tables databaseTables)
Examine the supplied string containing DDL statements, and apply those statements to the specified
database table definitions.
|
void |
parse(TokenStream ddlContent,
Tables databaseTables)
Examine the stream starting at its current position for DDL statements, and apply those statements to the specified
database table definitions.
|
private void |
parseAliasedTableInFrom(TokenStream.Marker start,
Map<String,Table> tablesByAlias)
Parse a potentially qualified table name along with an optional alias.
|
protected void |
parseAlter(TokenStream.Marker marker)
Parse the a DDL "ALTER" statement.
|
protected String |
parseBitFieldLiteral(TokenStream.Marker start) |
protected String |
parseCharacterLiteral(TokenStream.Marker start) |
protected String |
parseCharacterSetName(TokenStream.Marker start) |
protected void |
parseColumnName(TokenStream.Marker start,
Map<String,String> tableAliasByColumnAliases,
Map<String,String> columnNameByAliases)
Parse the potentially qualified and aliased column information, and add the information to the supplied maps.
|
protected Map<String,Column> |
parseColumnsInSelectClause(TokenStream.Marker start)
Parse the column information in the SELECT clause.
|
protected void |
parseComment(TokenStream.Marker marker)
Parse the a DDL line comment.
|
protected void |
parseCreate(TokenStream.Marker marker)
Parse the a DDL "CREATE" statement.
|
protected String |
parseDateLiteral(TokenStream.Marker start) |
protected void |
parseDrop(TokenStream.Marker marker)
Parse the a DDL "DROP" statement.
|
protected Object |
parseLiteral(TokenStream.Marker start) |
protected void |
parseNextStatement(TokenStream.Marker marker)
Parse the next DDL statement.
|
protected Object |
parseNumericLiteral(TokenStream.Marker start,
boolean signed) |
protected TableId |
parseQualifiedTableName(TokenStream.Marker start)
Parse the next tokens for a possibly qualified table name.
|
protected List<TableId> |
parseQualifiedTableNames(TokenStream.Marker start)
Parse the next tokens for one or more comma-separated qualified table names.
|
protected String |
parseSchemaQualifiedName(TokenStream.Marker start)
Parse the next tokens for a possibly qualified name.
|
protected Map<String,Table> |
parseSelectFromClause(TokenStream.Marker start)
Returns the tables keyed by their aliases that appear in a SELECT clause's "FROM" list.
|
protected String |
parseTimeLiteral(TokenStream.Marker start) |
protected String |
parseTimestampLiteral(TokenStream.Marker start) |
protected void |
parseUnknownStatement(TokenStream.Marker marker)
Parse a DDL statement that is not known by the
parseNextStatement(io.debezium.text.TokenStream.Marker). |
protected void |
parsingFailed(Position position,
Collection<ParsingException> errors,
String msg)
Generate a
ParsingException or MultipleParsingExceptions with the supplied error or errors and the
supplied message, which is appended by this method with additional information about the position's line and column. |
protected void |
parsingFailed(Position position,
String msg)
Generate a
ParsingException with the supplied message, which is appended by this method with additional
information about the position's line and column. |
protected void |
parsingFailed(Position position,
String msg,
Throwable t)
Generate a
ParsingException with the supplied message, which is appended by this method with additional
information about the position's line and column. |
boolean |
removeListener(DdlParserListener listener) |
void |
removeListeners() |
protected void |
signalAlterDatabase(String databaseName,
String previousDatabaseName,
TokenStream.Marker statementStart)
Signal an alter database event to all listeners.
|
protected void |
signalAlterTable(TableId id,
TableId previousId,
TokenStream.Marker statementStart)
Signal an alter table event to all listeners.
|
protected void |
signalAlterView(TableId id,
TableId previousId,
TokenStream.Marker statementStart)
Signal an alter view event to all listeners.
|
protected void |
signalChangeEvent(DdlParserListener.Event event)
Signal an event to all listeners.
|
protected void |
signalCreateDatabase(String databaseName,
TokenStream.Marker statementStart)
Signal a create database event to all listeners.
|
protected void |
signalCreateIndex(String indexName,
TableId id,
TokenStream.Marker statementStart)
Signal a create index event to all listeners.
|
protected void |
signalCreateTable(TableId id,
TokenStream.Marker statementStart)
Signal a create table event to all listeners.
|
protected void |
signalCreateView(TableId id,
TokenStream.Marker statementStart)
Signal a create view event to all listeners.
|
protected void |
signalDropDatabase(String databaseName,
TokenStream.Marker statementStart)
Signal a drop database event to all listeners.
|
protected void |
signalDropIndex(String indexName,
TableId id,
TokenStream.Marker statementStart)
Signal a drop index event to all listeners.
|
protected void |
signalDropTable(TableId id,
TokenStream.Marker statementStart)
Signal a drop table event to all listeners.
|
protected void |
signalDropView(TableId id,
TokenStream.Marker statementStart)
Signal a drop view event to all listeners.
|
protected String |
statement(TokenStream.Marker statementStart) |
accumulateParsingFailure, accumulateParsingFailure, commentParsed, createColumnFromConstant, currentSchema, debugParsed, debugSkipped, getDdlChanges, removeLineFeeds, resolveTableId, setCurrentDatabase, setCurrentSchema, setTypeInfoForConstant, signalAlterDatabase, signalAlterTable, signalAlterView, signalCreateDatabase, signalCreateIndex, signalCreateTable, signalCreateView, signalDropDatabase, signalDropIndex, signalDropTable, signalDropView, signalSetVariable, signalTruncateTable, signalUseDatabase, skipComments, systemVariables, terminator, withoutQuotesclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetDdlChanges, setCurrentDatabase, setCurrentSchema, systemVariables, terminatorprotected final org.slf4j.Logger logger
protected final DataTypeParser dataTypeParser
protected Tables databaseTables
protected TokenStream tokens
private final List<DdlParserListener> listeners
public LegacyDdlParser(String terminator)
DataTypeParser, but that does not include view definitions.terminator - the terminator character sequence; may be null if the default terminator (;) should be usedpublic LegacyDdlParser(String terminator, boolean includeViews)
DataTypeParser.terminator - the terminator character sequence; may be null if the default terminator (;) should be usedincludeViews - true if view definitions should be included, or false if they should be skippedprotected SystemVariables createNewSystemVariablesInstance()
createNewSystemVariablesInstance in class AbstractDdlParserprotected void initializeDataTypes(DataTypeParser dataTypeParser)
protected void initializeKeywords(LegacyDdlParser.TokenSet keywords)
protected void initializeStatementStarts(LegacyDdlParser.TokenSet statementStartTokens)
public void addListener(DdlParserListener listener)
public boolean removeListener(DdlParserListener listener)
public void removeListeners()
protected boolean isNextTokenQuotedIdentifier()
true if the next token is a single-quoted string or
double-quoted string, or false otherwiseprotected int determineTokenType(int type,
String token)
protected String parseSchemaQualifiedName(TokenStream.Marker start)
current schema), a '.' delimiter, and the object name. If no schema name is
found, just the object name is returned.start - the start of the statementprotected TableId parseQualifiedTableName(TokenStream.Marker start)
AbstractDdlParser.currentSchema(), and then calls AbstractDdlParser.resolveTableId(String, String) with
the values.start - the start of the statementTableIdprotected List<TableId> parseQualifiedTableNames(TokenStream.Marker start)
AbstractDdlParser.currentSchema(), and then calls AbstractDdlParser.resolveTableId(String, String) with
the values.start - the start of the statementTableIdpublic final void parse(String ddlContent, Tables databaseTables)
parse in interface DdlParserddlContent - the stream of tokens containing the DDL statements; may not be nulldatabaseTables - the database's table definitions, which should be used by this method to create, change, or remove
tables as defined in the DDL content; may not be nullParsingException - if there is a problem parsing the supplied contentpublic final void parse(TokenStream ddlContent, Tables databaseTables) throws ParsingException, IllegalStateException
ddlContent - the stream of tokens containing the DDL statements; may not be nulldatabaseTables - the database's table definitions, which should be used by this method to create, change, or remove
tables as defined in the DDL content; may not be nullParsingException - if there is a problem parsing the supplied contentIllegalStateException - if the supplied token stream is in an invalid stateprotected void parseNextStatement(TokenStream.Marker marker)
marker - the start of the statement; never nullParsingException - if there is an error parsing the statementprotected void parseComment(TokenStream.Marker marker)
parseNextStatement(io.debezium.text.TokenStream.Marker) for line comments that appear
between other DDL statements, and is not typically called for comments that appear within DDL statements.marker - the start of the statement; never nullParsingException - if there is an error parsing the statementprotected void parseCreate(TokenStream.Marker marker)
By default this method simply consumes the complete statement.
marker - the start of the statement; never nullParsingException - if there is an error parsing the statementprotected void parseAlter(TokenStream.Marker marker)
By default this method simply consumes the complete statement.
marker - the start of the statement; never nullParsingException - if there is an error parsing the statementprotected void parseDrop(TokenStream.Marker marker)
By default this method simply consumes the complete statement.
marker - the start of the statement; never nullParsingException - if there is an error parsing the statementprotected void parseUnknownStatement(TokenStream.Marker marker)
parseNextStatement(io.debezium.text.TokenStream.Marker). This method can be overridden by subclasses,
although it will be more common for subclasses to override parseNextStatement(io.debezium.text.TokenStream.Marker).
By default this method simply consumes the complete statement.
marker - the start of the statement; never nullParsingException - if there is an error parsing the statementprotected void signalCreateDatabase(String databaseName, TokenStream.Marker statementStart)
databaseName - the database name; may not be nullstatementStart - the start of the statement; may not be nullprotected void signalChangeEvent(DdlParserListener.Event event)
signalChangeEvent in class AbstractDdlParserevent - the event; may not be nullprotected void signalAlterDatabase(String databaseName, String previousDatabaseName, TokenStream.Marker statementStart)
databaseName - the database name; may not be nullpreviousDatabaseName - the previous name of the database if it was renamed, or null if it was not renamedstatementStart - the start of the statement; may not be nullprotected void signalDropDatabase(String databaseName, TokenStream.Marker statementStart)
databaseName - the database name; may not be nullstatementStart - the start of the statement; may not be nullprotected void signalCreateTable(TableId id, TokenStream.Marker statementStart)
id - the table identifier; may not be nullstatementStart - the start of the statement; may not be nullprotected void signalAlterTable(TableId id, TableId previousId, TokenStream.Marker statementStart)
id - the table identifier; may not be nullpreviousId - the previous name of the view if it was renamed, or null if it was not renamedstatementStart - the start of the statement; may not be nullprotected void signalDropTable(TableId id, TokenStream.Marker statementStart)
id - the table identifier; may not be nullstatementStart - the start of the statement; may not be nullprotected void signalCreateView(TableId id, TokenStream.Marker statementStart)
id - the table identifier; may not be nullstatementStart - the start of the statement; may not be nullprotected void signalAlterView(TableId id, TableId previousId, TokenStream.Marker statementStart)
id - the table identifier; may not be nullpreviousId - the previous name of the view if it was renamed, or null if it was not renamedstatementStart - the start of the statement; may not be nullprotected void signalDropView(TableId id, TokenStream.Marker statementStart)
id - the table identifier; may not be nullstatementStart - the start of the statement; may not be nullprotected void signalCreateIndex(String indexName, TableId id, TokenStream.Marker statementStart)
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 tablestatementStart - the start of the statement; may not be nullprotected void signalDropIndex(String indexName, TableId id, TokenStream.Marker statementStart)
indexName - the name of the index; may not be nullid - the table identifier; may not be nullstatementStart - the start of the statement; may not be nullprotected void debugParsed(TokenStream.Marker statementStart)
protected void debugSkipped(TokenStream.Marker statementStart)
protected String statement(TokenStream.Marker statementStart)
protected void consumeStatement()
throws ParsingException
starting-statement
token until either the
end-of-statement terminator token or before the next
starting-statement token.ParsingException - if the next token is not a starting-statement tokenprotected void consumeRemainingStatement(TokenStream.Marker start)
end-of-statement
terminator token or one of
the tokens that is registered as the start of a statement.start - the marker at which the statement was begunprotected void consumeBeginStatement(TokenStream.Marker start)
BEGIN...END block that appears next in the token stream. This method may need to be
specialized for a specific DDL grammar.start - the marker at which the statement was begunprotected String consumeSingleQuotedString()
ParsingException - if there is no single-quoted string at the current positionprotected String consumeDoubleQuotedString()
ParsingException - if there is no double-quoted string at the current positionprotected String consumeQuotedString()
ParsingException - if there is no single- or double-quoted string at the current positionprotected void parsingFailed(Position position, String msg)
ParsingException with the supplied message, which is appended by this method with additional
information about the position's line and column.position - the position at which the error occurred; may not be nullmsg - the leading portion of the message; may not be nullprotected void parsingFailed(Position position, String msg, Throwable t)
ParsingException with the supplied message, which is appended by this method with additional
information about the position's line and column.position - the position at which the error occurredmsg - the leading portion of the message; may not be nullt - the exception that occurred; may be nullprotected void parsingFailed(Position position, Collection<ParsingException> errors, String msg)
ParsingException or MultipleParsingExceptions with the supplied error or errors and the
supplied message, which is appended by this method with additional information about the position's line and column.position - the position at which the error occurred; may not be nullerrors - the multiple parsing exception errors; may not be nullmsg - the leading portion of the message; may not be nullprotected Object parseLiteral(TokenStream.Marker start)
protected Object parseNumericLiteral(TokenStream.Marker start, boolean signed)
protected String parseCharacterLiteral(TokenStream.Marker start)
protected String parseCharacterSetName(TokenStream.Marker start)
protected String parseBitFieldLiteral(TokenStream.Marker start)
protected String parseDateLiteral(TokenStream.Marker start)
protected String parseTimeLiteral(TokenStream.Marker start)
protected String parseTimestampLiteral(TokenStream.Marker start)
protected Map<String,Column> parseColumnsInSelectClause(TokenStream.Marker start)
start - the start of the statementprotected String determineTypeNameForConstant(long value)
protected String determineTypeNameForConstant(float value)
protected String determineTypeNameForConstant(double value)
protected String determineTypeNameForConstant(BigDecimal value)
protected void parseColumnName(TokenStream.Marker start, Map<String,String> tableAliasByColumnAliases, Map<String,String> columnNameByAliases)
start - the start of the statementtableAliasByColumnAliases - the map to which is added the column's alias (or name) keyed by the alias of the table
in which the column should appear; may not be nullcolumnNameByAliases - the map to which is added the column's name keyed by the its alias (or itself if there is no
alias); may not be nullprotected Map<String,Table> parseSelectFromClause(TokenStream.Marker start)
various standard joins.start - the start of the statementprotected boolean canConsumeJoin(TokenStream.Marker start)
protected boolean canConsumeJoinCondition(TokenStream.Marker start)
private void parseAliasedTableInFrom(TokenStream.Marker start, Map<String,Table> tablesByAlias)
start - the start of the statementtablesByAlias - the map to which this method should add the table keyed by its alias (or name if there is no alias);
may not be nullCopyright © 2020 JBoss by Red Hat. All rights reserved.