@ThreadSafe public class DataTypeParser extends Object
parse streams of tokens looking for matches.
This is typically used within a LegacyDdlParser implementation to parse and identify data types appearing within a stream
of DDL content.
LegacyDdlParser| Modifier and Type | Class and Description |
|---|---|
protected static class |
DataTypeParser.ErrorCollector |
| Modifier and Type | Field and Description |
|---|---|
private DataTypeGrammarParser |
parser |
private Map<String,Collection<DataTypeGrammarParser.DataTypePattern>> |
patterns |
| Constructor and Description |
|---|
DataTypeParser()
Create an empty data type parser with no data types registered.
|
| Modifier and Type | Method and Description |
|---|---|
DataType |
parse(TokenStream stream,
Consumer<Collection<ParsingException>> errorHandler)
Examine the stream starting at its current position for a matching data type.
|
DataTypeParser |
register(int jdbcType,
String grammar)
Register data type that may not contain a length/precision or scale.
|
private final Map<String,Collection<DataTypeGrammarParser.DataTypePattern>> patterns
private final DataTypeGrammarParser parser
public DataTypeParser()
public DataTypeParser register(int jdbcType, String grammar)
The order that grammars are registered is the same order that they are evaluated by the resulting parser. However, when multiple grammars match the same input tokens, the grammar that successfully consumes the most input tokens will be selected.
jdbcType - the best JDBC type for the data typegrammar - the grammar the defines the data type format; may not be nullpublic DataType parse(TokenStream stream, Consumer<Collection<ParsingException>> errorHandler)
This method looks for data types that match those registered patterns.
This method also looks for multi-dimensional arrays, where any registered data type pattern is followed by one or more
array dimensions of the form [n], where n is the integer dimension.
Sometimes, a data type matches one of the registered patterns but it contains a malformed length/precision, scale, and/or
array dimensions. These parsing exceptions can be reported back to the caller via the supplied errorHandler,
although these errors are only reported when no data type is found. This is often useful when the caller expects
to find a data type, but no such data type can be found due to one or more parsing exceptions. When this happens,
the method calls errorHandler with all of the ParsingExceptions and then returns null.
stream - the stream of tokens; may not be nullerrorHandler - a function that should be called when no data type was found because at least one
ParsingException
occurred with the length/precision, scale, and/or array dimensions; may be nullCopyright © 2020 JBoss by Red Hat. All rights reserved.