Package org.teiid.query.parser
Class QueryParser
- java.lang.Object
-
- org.teiid.query.parser.QueryParser
-
- All Implemented Interfaces:
Parser
public class QueryParser extends Object implements Parser
Converts a SQL-string to an object version of a query. This QueryParser can be reused but is NOT thread-safe as the parser uses an input stream. Putting multiple queries into the same stream will result in unpredictable and most likely incorrect behavior.
-
-
Constructor Summary
Constructors Constructor Description QueryParser()
Construct a QueryParser - this may be reused.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
add_escapes(String str, StringBuilder retval)
Used to convert raw characters to their escaped version when these raw version cannot be used as part of an ASCII string literal.String
getMessage(ParseException pe, int maxExpansions)
The default JavaCC message is not very good.static QueryParser
getQueryParser()
CacheHint
parseCacheHint(String sql)
Command
parseCommand(String sql)
Takes a SQL string representing a Command and returns the object representation.Command
parseCommand(String sql, ParseInfo parseInfo)
Takes a SQL string representing a Command and returns the object representation.Criteria
parseCriteria(String sql)
Takes a SQL string representing an SQL criteria (i.e.void
parseDDL(MetadataFactory factory, Reader ddl)
Parses the givenReader
into theMetadataFactory
.void
parseDDL(MetadataFactory factory, String ddl)
void
parseDDL(DatabaseStore repository, Reader ddl)
Expression
parseExpression(String sql)
Takes a SQL string representing an SQL expression and returns the object representation.Command
parseProcedure(String sql, boolean update)
Expression
parseSelectExpression(String sql)
-
-
-
Method Detail
-
getQueryParser
public static QueryParser getQueryParser()
-
parseCommand
public Command parseCommand(String sql) throws QueryParserException
Takes a SQL string representing a Command and returns the object representation.- Parameters:
sql
- SQL string instead of string litral- Returns:
- SQL object representation
- Throws:
QueryParserException
- if parsing failsIllegalArgumentException
- if sql is null
-
parseProcedure
public Command parseProcedure(String sql, boolean update) throws QueryParserException
- Throws:
QueryParserException
-
parseCommand
public Command parseCommand(String sql, ParseInfo parseInfo) throws QueryParserException
Takes a SQL string representing a Command and returns the object representation.- Parameters:
sql
- SQL stringparseInfo
- - instructions to parse- Returns:
- SQL object representation
- Throws:
QueryParserException
- if parsing failsIllegalArgumentException
- if sql is null
-
parseCriteria
public Criteria parseCriteria(String sql) throws QueryParserException
Takes a SQL string representing an SQL criteria (i.e. just the WHERE clause) and returns the object representation.- Parameters:
sql
- SQL criteria (WHERE clause) string- Returns:
- Criteria SQL object representation
- Throws:
QueryParserException
- if parsing failsIllegalArgumentException
- if sql is null
-
getMessage
public String getMessage(ParseException pe, int maxExpansions)
The default JavaCC message is not very good. This method produces a much more readable result.- Parameters:
pe
-maxExpansions
-- Returns:
-
add_escapes
protected void add_escapes(String str, StringBuilder retval)
Used to convert raw characters to their escaped version when these raw version cannot be used as part of an ASCII string literal. Also escapes double quotes.
-
parseExpression
public Expression parseExpression(String sql) throws QueryParserException
Takes a SQL string representing an SQL expression and returns the object representation.- Parameters:
sql
- SQL expression string- Returns:
- SQL expression object
- Throws:
QueryParserException
- if parsing failsIllegalArgumentException
- if sql is null
-
parseSelectExpression
public Expression parseSelectExpression(String sql) throws QueryParserException
- Throws:
QueryParserException
-
parseDDL
public void parseDDL(MetadataFactory factory, String ddl)
-
parseDDL
public void parseDDL(MetadataFactory factory, Reader ddl)
Description copied from interface:Parser
-
parseDDL
public void parseDDL(DatabaseStore repository, Reader ddl) throws MetadataException
- Throws:
MetadataException
-
-