com.metamatrix.query.parser
Class QueryParser

java.lang.Object
  extended by com.metamatrix.query.parser.QueryParser

public class QueryParser
extends java.lang.Object

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.

In the future this class may hide a single- or multi-thread cache of parsed queries.


Constructor Summary
QueryParser()
          Construct a QueryParser - this may be reused.
 
Method Summary
static int getCommandType(java.lang.String sql)
          Takes a SQL string and determines the command type, as defined in the constants of Command.
static QueryParser getQueryParser()
           
 Command parseCommand(java.lang.String sql)
          Takes a SQL string representing a Command and returns the object representation.
 Command parseCommand(java.lang.String sql, ParseInfo parseInfo)
          Takes a SQL string representing a Command and returns the object representation.
 Criteria parseCriteria(java.lang.String sql)
          Takes a SQL string representing an SQL criteria (i.e.
 Expression parseExpression(java.lang.String sql)
          Takes a SQL string representing an SQL expression and returns the object representation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QueryParser

public QueryParser()
Construct a QueryParser - this may be reused.

Method Detail

getQueryParser

public static QueryParser getQueryParser()

parseCommand

public Command parseCommand(java.lang.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 fails
java.lang.IllegalArgumentException - if sql is null

parseCommand

public Command parseCommand(java.lang.String sql,
                            ParseInfo parseInfo)
                     throws QueryParserException
Takes a SQL string representing a Command and returns the object representation.

Parameters:
sql - SQL string
parseInfo - - instructions to parse
Returns:
SQL object representation
Throws:
QueryParserException - if parsing fails
java.lang.IllegalArgumentException - if sql is null

parseCriteria

public Criteria parseCriteria(java.lang.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 fails
java.lang.IllegalArgumentException - if sql is null

parseExpression

public Expression parseExpression(java.lang.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 fails
java.lang.IllegalArgumentException - if sql is null

getCommandType

public static int getCommandType(java.lang.String sql)
Takes a SQL string and determines the command type, as defined in the constants of Command.

Parameters:
sql - SQL string
Returns:
Command type code, as defined in Command. Note: not all XQuery queries will necessarily be detected - if type UNKNOWN is indicated it's possible it is an XQuery.
Throws:
java.lang.IllegalArgumentException - if sql is null


Copyright © 2009. All Rights Reserved.