public abstract class AntlrDdlParser<L extends org.antlr.v4.runtime.Lexer,P extends org.antlr.v4.runtime.Parser> extends AbstractDdlParser
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.
| Modifier and Type | Field and Description |
|---|---|
private AntlrDdlParserListener |
antlrDdlParserListener
Parser listener for tree walker.
|
protected Tables |
databaseTables |
protected DataTypeResolver |
dataTypeResolver |
private boolean |
throwErrorsFromTreeWalk
Flag to indicate if the errors caught during tree walk will be thrown.
|
ddlChanges, logger, skipViews, systemVariables| Constructor and Description |
|---|
AntlrDdlParser(boolean throwErrorsFromTreeWalk) |
AntlrDdlParser(boolean throwErrorsFromTreeWalk,
boolean includeViews) |
| Modifier and Type | Method and Description |
|---|---|
protected abstract L |
createNewLexerInstance(org.antlr.v4.runtime.CharStream charStreams)
Creates a new generic type instance of ANTLR Lexer.
|
protected abstract P |
createNewParserInstance(org.antlr.v4.runtime.CommonTokenStream commonTokenStream)
Creates a new generic type instance of ANTLR Parser.
|
protected abstract AntlrDdlParserListener |
createParseTreeWalkerListener()
Creates a new instance of parsed tree walker listener.
|
Tables |
databaseTables()
Returns actual tables schema.
|
DataTypeResolver |
dataTypeResolver()
Returns a data type resolver component.
|
void |
debugParsed(org.antlr.v4.runtime.ParserRuleContext ctx) |
void |
debugSkipped(org.antlr.v4.runtime.ParserRuleContext ctx) |
Collection<ParsingException> |
getParsingExceptionsFromWalker()
Returns errors catched during tree walk.
|
static String |
getText(org.antlr.v4.runtime.ParserRuleContext ctx)
Returns matched part of the getText for the context.
|
static String |
getText(org.antlr.v4.runtime.ParserRuleContext ctx,
int start,
int stop)
Returns matched part of the getText for the context.
|
protected abstract DataTypeResolver |
initializeDataTypeResolver()
Initialize DB to JDBC data types mapping for resolver.
|
protected abstract boolean |
isGrammarInUpperCase()
Check if the parsed grammar is written in upper case.
|
void |
parse(String ddlContent,
Tables databaseTables) |
protected abstract org.antlr.v4.runtime.tree.ParseTree |
parseTree(P parser)
Examine the supplied string containing DDL statements, and apply those statements to the specified
database table definitions.
|
void |
signalAlterDatabase(String databaseName,
String previousDatabaseName,
org.antlr.v4.runtime.ParserRuleContext ctx)
Signal an alter database event to ddl changes listener.
|
void |
signalAlterTable(TableId id,
TableId previousId,
org.antlr.v4.runtime.ParserRuleContext ctx)
Signal an alter table event to ddl changes listener.
|
void |
signalAlterView(TableId id,
TableId previousId,
org.antlr.v4.runtime.ParserRuleContext ctx)
Signal an alter view event to ddl changes listener.
|
void |
signalCreateDatabase(String databaseName,
org.antlr.v4.runtime.ParserRuleContext ctx)
Signal a create database event to ddl changes listener.
|
void |
signalCreateIndex(String indexName,
TableId id,
org.antlr.v4.runtime.ParserRuleContext ctx)
Signal a create index event to ddl changes listener.
|
void |
signalCreateTable(TableId id,
org.antlr.v4.runtime.ParserRuleContext ctx)
Signal a create table event to ddl changes listener.
|
void |
signalCreateView(TableId id,
org.antlr.v4.runtime.ParserRuleContext ctx)
Signal a create view event to ddl changes listener.
|
void |
signalDropDatabase(String databaseName,
org.antlr.v4.runtime.ParserRuleContext ctx)
Signal a drop database event to ddl changes listener.
|
void |
signalDropIndex(String indexName,
TableId id,
org.antlr.v4.runtime.ParserRuleContext ctx)
Signal a drop index event to ddl changes listener.
|
void |
signalDropTable(TableId id,
org.antlr.v4.runtime.ParserRuleContext ctx)
Signal a drop table event to ddl changes listener.
|
void |
signalDropTable(TableId id,
String statement) |
void |
signalDropView(TableId id,
org.antlr.v4.runtime.ParserRuleContext ctx)
Signal a drop view event to ddl changes listener.
|
void |
signalSetVariable(String variableName,
String variableValue,
org.antlr.v4.runtime.ParserRuleContext ctx) |
void |
signalTruncateTable(TableId id,
org.antlr.v4.runtime.ParserRuleContext ctx)
Signal a truncate table event to ddl changes listener.
|
void |
signalUseDatabase(org.antlr.v4.runtime.ParserRuleContext ctx) |
boolean |
skipViews() |
private void |
throwParsingException(Collection<ParsingException> errors) |
String |
withoutQuotes(org.antlr.v4.runtime.ParserRuleContext ctx) |
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, skipComments, systemVariables, terminator, withoutQuotesprivate final boolean throwErrorsFromTreeWalk
getParsingExceptionsFromWalker().private AntlrDdlParserListener antlrDdlParserListener
protected Tables databaseTables
protected DataTypeResolver dataTypeResolver
public AntlrDdlParser(boolean throwErrorsFromTreeWalk)
public AntlrDdlParser(boolean throwErrorsFromTreeWalk,
boolean includeViews)
public Collection<ParsingException> getParsingExceptionsFromWalker()
ParsingExceptions.protected abstract org.antlr.v4.runtime.tree.ParseTree parseTree(P parser)
parser - initialized ANTLR parser instance with common token stream from DDL statement; may not be nullprotected abstract AntlrDdlParserListener createParseTreeWalkerListener()
protected abstract L createNewLexerInstance(org.antlr.v4.runtime.CharStream charStreams)
charStreams - the char stream from DDL statement, without one line comments and line feeds; may not be nullprotected abstract P createNewParserInstance(org.antlr.v4.runtime.CommonTokenStream commonTokenStream)
commonTokenStream - the stream of ANTLR tokens created from Lexer instance; may not be nullprotected abstract boolean isGrammarInUpperCase()
protected abstract DataTypeResolver initializeDataTypeResolver()
dataTypeResolver - data type resolverpublic Tables databaseTables()
public DataTypeResolver dataTypeResolver()
public static String getText(org.antlr.v4.runtime.ParserRuleContext ctx)
ctx - the parser rule context; may not be nullpublic static String getText(org.antlr.v4.runtime.ParserRuleContext ctx, int start, int stop)
ctx - the parser rule context; may not be nullstart - the interval start positionstop - the interval stop positionpublic boolean skipViews()
public void signalSetVariable(String variableName, String variableValue, org.antlr.v4.runtime.ParserRuleContext ctx)
public void signalUseDatabase(org.antlr.v4.runtime.ParserRuleContext ctx)
public void signalCreateDatabase(String databaseName, org.antlr.v4.runtime.ParserRuleContext ctx)
databaseName - the database name; may not be nullctx - the start of the statement; may not be nullpublic void signalAlterDatabase(String databaseName, String previousDatabaseName, org.antlr.v4.runtime.ParserRuleContext ctx)
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 nullpublic void signalDropDatabase(String databaseName, org.antlr.v4.runtime.ParserRuleContext ctx)
databaseName - the database name; may not be nullctx - the start of the statement; may not be nullpublic void signalCreateTable(TableId id, org.antlr.v4.runtime.ParserRuleContext ctx)
id - the table identifier; may not be nullctx - the start of the statement; may not be nullpublic void signalAlterTable(TableId id, TableId previousId, org.antlr.v4.runtime.ParserRuleContext ctx)
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 nullpublic void signalDropTable(TableId id, String statement)
signalDropTable in class AbstractDdlParserpublic void signalDropTable(TableId id, org.antlr.v4.runtime.ParserRuleContext ctx)
id - the table identifier; may not be nullctx - the start of the statement; may not be nullpublic void signalTruncateTable(TableId id, org.antlr.v4.runtime.ParserRuleContext ctx)
id - the table identifier; may not be nullctx - the start of the statement; may not be nullpublic void signalCreateView(TableId id, org.antlr.v4.runtime.ParserRuleContext ctx)
id - the table identifier; may not be nullctx - the start of the statement; may not be nullpublic void signalAlterView(TableId id, TableId previousId, org.antlr.v4.runtime.ParserRuleContext ctx)
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 nullpublic void signalDropView(TableId id, org.antlr.v4.runtime.ParserRuleContext ctx)
id - the table identifier; may not be nullctx - the start of the statement; may not be nullpublic void signalCreateIndex(String indexName, TableId id, org.antlr.v4.runtime.ParserRuleContext ctx)
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 nullpublic void signalDropIndex(String indexName, TableId id, org.antlr.v4.runtime.ParserRuleContext ctx)
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 nullpublic void debugParsed(org.antlr.v4.runtime.ParserRuleContext ctx)
public void debugSkipped(org.antlr.v4.runtime.ParserRuleContext ctx)
public String withoutQuotes(org.antlr.v4.runtime.ParserRuleContext ctx)
private void throwParsingException(Collection<ParsingException> errors)
Copyright © 2021 JBoss by Red Hat. All rights reserved.