Package org.hibernate.hql.ast
Class HqlSqlWalker
java.lang.Object
antlr.TreeParser
org.hibernate.hql.antlr.HqlSqlBaseWalker
org.hibernate.hql.ast.HqlSqlWalker
- All Implemented Interfaces:
ParameterBinder.NamedParameterSource,HqlSqlTokenTypes,ErrorReporter
public class HqlSqlWalker
extends HqlSqlBaseWalker
implements ErrorReporter, ParameterBinder.NamedParameterSource
Implements methods used by the HQL->SQL tree transform grammar (a.k.a. the second phase).
- Isolates the Hibernate API-specific code from the ANTLR generated code.
- Handles the SQL fragments generated by the persisters in order to create the SELECT and FROM clauses, taking into account the joins and projections that are implied by the mappings (persister/queryable).
- Uses SqlASTFactory to create customized AST nodes.
- See Also:
-
Field Summary
Fields inherited from class org.hibernate.hql.antlr.HqlSqlBaseWalker
_tokenNames, _tokenSet_0, _tokenSet_1Fields inherited from class antlr.TreeParser
_retTree, astFactory, ASTNULL, inputState, returnAST, tokenNamesFields inherited from interface org.hibernate.hql.antlr.HqlSqlTokenTypes
AGGREGATE, ALIAS, ALIAS_REF, ALL, AND, ANY, AS, ASCENDING, AVG, BETWEEN, BOGUS, BOTH, CASE, CASE2, CLASS, CLOSE, CLOSE_BRACKET, COLON, COMMA, CONCAT, CONSTANT, CONSTRUCTOR, COUNT, DELETE, DESCENDING, DISTINCT, DIV, DOT, ELEMENTS, ELSE, EMPTY, END, ENTRY, EOF, EQ, ESCAPE, ESCqs, EXISTS, EXPONENT, EXPR_LIST, FALSE, FETCH, FILTER_ENTITY, FILTERS, FLOAT_SUFFIX, FROM, FROM_FRAGMENT, FULL, GE, GROUP, GT, HAVING, HEX_DIGIT, ID_LETTER, ID_START_LETTER, IDENT, IMPLIED_FROM, IN, IN_LIST, INDEX_OP, INDICES, INNER, INSERT, INTO, IS, IS_NOT_NULL, IS_NULL, JAVA_CONSTANT, JOIN, JOIN_FRAGMENT, KEY, LE, LEADING, LEFT, LEFT_OUTER, LIKE, LITERAL_ascending, LITERAL_by, LITERAL_descending, LT, MAX, MEMBER, METHOD_CALL, METHOD_NAME, MIN, MINUS, MOD, NAMED_PARAM, NE, NEW, NOT, NOT_BETWEEN, NOT_IN, NOT_LIKE, NULL, NULL_TREE_LOOKAHEAD, NUM_BIG_DECIMAL, NUM_BIG_INTEGER, NUM_DOUBLE, NUM_FLOAT, NUM_INT, NUM_LONG, OBJECT, OF, ON, OPEN, OPEN_BRACKET, OR, ORDER, ORDER_ELEMENT, OUTER, PARAM, PLUS, PROPERTIES, PROPERTY_REF, QUERY, QUOTED_STRING, RANGE, RESULT_VARIABLE_REF, RIGHT, RIGHT_OUTER, ROW_STAR, SELECT, SELECT_CLAUSE, SELECT_COLUMNS, SELECT_EXPR, SELECT_FROM, SET, SOME, SQL_NE, SQL_TOKEN, STAR, SUM, THEN, THETA_JOINS, TRAILING, TRUE, UNARY_MINUS, UNARY_PLUS, UNION, UPDATE, VALUE, VECTOR_EXPR, VERSIONED, WEIRD_IDENT, WHEN, WHERE, WITH, WS -
Constructor Summary
ConstructorsConstructorDescriptionHqlSqlWalker(QueryTranslatorImpl qti, SessionFactoryImplementor sfi, HqlParser parser, Map tokenReplacements, String collectionRole) Create a new tree transformer. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddQuerySpaces(Serializable[] spaces) protected voidprotected antlr.collections.ASTcreateFromElement(String path, antlr.collections.AST alias, antlr.collections.AST propertyFetch) protected antlr.collections.ASTcreateFromFilterElement(antlr.collections.AST filterEntity, antlr.collections.AST alias) protected voidcreateFromJoinElement(antlr.collections.AST path, antlr.collections.AST alias, int joinType, antlr.collections.AST fetchNode, antlr.collections.AST propertyFetch, antlr.collections.AST with) protected antlr.collections.ASTcreateIntoClause(String path, antlr.collections.AST propertySpec) protected voidprotected antlr.collections.ASTgenerateNamedParameter(antlr.collections.AST delimiterNode, antlr.collections.AST nameNode) protected antlr.collections.ASTgeneratePositionalParameter(antlr.collections.AST inputNode) intint[]Returns the locations of all occurrences of the named parameter.intReturns the set of unique query spaces (a.k.a.String[]Type[]protected voidhandleResultVariableRef(antlr.collections.AST resultVariableRef) booleanisFilter()protected booleanprotected booleanisOrderExpressionResultVariableRef(antlr.collections.AST orderExpressionNode) booleanprotected voidlookupAlias(antlr.collections.AST aliasRef) protected antlr.collections.ASTprotected antlr.collections.ASTlookupProperty(antlr.collections.AST dot, boolean root, boolean inSelect) static voidpanic()protected voidprotected voidpostProcessDML(RestrictableStatement statement) protected voidprotected voidprotected voidprotected voidprepareFromClauseInputTree(antlr.collections.AST fromClauseInput) Pre-process the from clause input tree.protected voidprepareLogicOperator(antlr.collections.AST operator) protected voidprepareVersioned(antlr.collections.AST updateNode, antlr.collections.AST versioned) protected voidprocessAggregation(antlr.collections.AST node, boolean inSelect) protected voidprocessBoolean(antlr.collections.AST constant) protected voidprocessConstant(antlr.collections.AST constant) protected voidprocessConstructor(antlr.collections.AST constructor) protected voidprocessFunction(antlr.collections.AST functionCall, boolean inSelect) protected voidprocessIndex(antlr.collections.AST indexOp) protected voidprotected voidprocessQuery(antlr.collections.AST select, antlr.collections.AST query) protected voidpushFromClause(antlr.collections.AST fromNode, antlr.collections.AST inputFromNode) Sets the current 'FROM' context.voidvoidvoidprotected voidresolve(antlr.collections.AST node) protected voidprotected voidsetAlias(antlr.collections.AST selectExpr, antlr.collections.AST ident) protected voidsetImpliedJoinType(int joinType) static booleanvoidtraceIn(String ruleName, antlr.collections.AST tree) voidtraceOut(String ruleName, antlr.collections.AST tree) protected voidMethods inherited from class org.hibernate.hql.antlr.HqlSqlBaseWalker
addrExpr, addrExprLhs, aggregateExpr, aliasedSelectExpr, aliasRef, arithmeticExpr, assignment, caseExpr, collectionFunction, collectionFunctionOrSubselect, comparisonExpr, constant, constructor, count, deleteStatement, expr, exprOrSubquery, fromClause, fromElement, fromElementList, functionCall, getCurrentClauseType, getCurrentStatementType, getCurrentTopLevelClauseType, getStatementType, groupClause, identifier, inRhs, insertablePropertySpec, insertStatement, intoClause, isComparativeExpressionClause, isInCase, isInFrom, isInFunctionCall, isInSelect, isSelectStatement, isSubQuery, joinElement, joinType, literal, logicalExpr, mapComponentReference, mapPropertyExpression, newValue, numericInteger, orderClause, orderExpr, orderExprs, parameter, path, pathAsIdent, processMapComponentReference, propertyName, propertyRef, propertyRefLhs, query, resultVariableRef, selectClause, selectExpr, selectExprList, selectStatement, setClause, statement, updateStatement, whereClause, withClauseMethods inherited from class antlr.TreeParser
getAST, getASTFactory, getTokenName, getTokenNames, match, match, matchNot, setASTFactory, setASTNodeClass, setASTNodeType, traceIndent
-
Constructor Details
-
HqlSqlWalker
public HqlSqlWalker(QueryTranslatorImpl qti, SessionFactoryImplementor sfi, HqlParser parser, Map tokenReplacements, String collectionRole) Create a new tree transformer.- Parameters:
qti- Back pointer to the query translator implementation that is using this tree transform.sfi- The session factory implementor where the Hibernate mappings can be found.parser- A reference to the phase-1 parsertokenReplacements- Registers the token replacement map with the walker. This map will be used to substitute function names and constants.collectionRole- The collection role name of the collection used as the basis for the filter, NULL if this is not a collection filter compilation.
-
-
Method Details
-
traceIn
- Overrides:
traceInin classantlr.TreeParser
-
traceOut
- Overrides:
traceOutin classantlr.TreeParser
-
prepareFromClauseInputTree
Description copied from class:HqlSqlBaseWalkerPre-process the from clause input tree.- Overrides:
prepareFromClauseInputTreein classHqlSqlBaseWalker
-
isFilter
public boolean isFilter() -
getCollectionFilterRole
-
getSessionFactoryHelper
-
getTokenReplacements
-
getAliasGenerator
-
getCurrentFromClause
-
getParseErrorHandler
-
reportError
- Specified by:
reportErrorin interfaceErrorReporter- Overrides:
reportErrorin classantlr.TreeParser
-
reportError
- Specified by:
reportErrorin interfaceErrorReporter- Overrides:
reportErrorin classantlr.TreeParser
-
reportWarning
- Specified by:
reportWarningin interfaceErrorReporter- Overrides:
reportWarningin classantlr.TreeParser
-
getQuerySpaces
Returns the set of unique query spaces (a.k.a. table names) that occurred in the query.- Returns:
- A set of table names (Strings).
-
createFromElement
protected antlr.collections.AST createFromElement(String path, antlr.collections.AST alias, antlr.collections.AST propertyFetch) throws antlr.SemanticException - Overrides:
createFromElementin classHqlSqlBaseWalker- Throws:
antlr.SemanticException
-
createFromFilterElement
protected antlr.collections.AST createFromFilterElement(antlr.collections.AST filterEntity, antlr.collections.AST alias) throws antlr.SemanticException - Overrides:
createFromFilterElementin classHqlSqlBaseWalker- Throws:
antlr.SemanticException
-
createFromJoinElement
protected void createFromJoinElement(antlr.collections.AST path, antlr.collections.AST alias, int joinType, antlr.collections.AST fetchNode, antlr.collections.AST propertyFetch, antlr.collections.AST with) throws antlr.SemanticException - Overrides:
createFromJoinElementin classHqlSqlBaseWalker- Throws:
antlr.SemanticException
-
pushFromClause
Sets the current 'FROM' context.- Overrides:
pushFromClausein classHqlSqlBaseWalker- Parameters:
fromNode- The new 'FROM' context.inputFromNode- The from node from the input AST.
-
lookupAlias
- Overrides:
lookupAliasin classHqlSqlBaseWalker- Throws:
antlr.SemanticException
-
setImpliedJoinType
protected void setImpliedJoinType(int joinType) - Overrides:
setImpliedJoinTypein classHqlSqlBaseWalker
-
getImpliedJoinType
public int getImpliedJoinType() -
lookupProperty
protected antlr.collections.AST lookupProperty(antlr.collections.AST dot, boolean root, boolean inSelect) throws antlr.SemanticException - Overrides:
lookupPropertyin classHqlSqlBaseWalker- Throws:
antlr.SemanticException
-
isNonQualifiedPropertyRef
- Overrides:
isNonQualifiedPropertyRefin classHqlSqlBaseWalker
-
lookupNonQualifiedProperty
protected antlr.collections.AST lookupNonQualifiedProperty(antlr.collections.AST property) throws antlr.SemanticException - Overrides:
lookupNonQualifiedPropertyin classHqlSqlBaseWalker- Throws:
antlr.SemanticException
-
processQuery
protected void processQuery(antlr.collections.AST select, antlr.collections.AST query) throws antlr.SemanticException - Overrides:
processQueryin classHqlSqlBaseWalker- Throws:
antlr.SemanticException
-
postProcessDML
- Throws:
antlr.SemanticException
-
postProcessUpdate
- Overrides:
postProcessUpdatein classHqlSqlBaseWalker- Throws:
antlr.SemanticException
-
postProcessDelete
- Overrides:
postProcessDeletein classHqlSqlBaseWalker- Throws:
antlr.SemanticException
-
supportsIdGenWithBulkInsertion
-
postProcessInsert
protected void postProcessInsert(antlr.collections.AST insert) throws antlr.SemanticException, QueryException - Overrides:
postProcessInsertin classHqlSqlBaseWalker- Throws:
antlr.SemanticExceptionQueryException
-
resolve
- Overrides:
resolvein classHqlSqlBaseWalker- Throws:
antlr.SemanticException
-
resolveSelectExpression
- Overrides:
resolveSelectExpressionin classHqlSqlBaseWalker- Throws:
antlr.SemanticException
-
beforeSelectClause
- Overrides:
beforeSelectClausein classHqlSqlBaseWalker- Throws:
antlr.SemanticException
-
generatePositionalParameter
protected antlr.collections.AST generatePositionalParameter(antlr.collections.AST inputNode) throws antlr.SemanticException - Overrides:
generatePositionalParameterin classHqlSqlBaseWalker- Throws:
antlr.SemanticException
-
generateNamedParameter
protected antlr.collections.AST generateNamedParameter(antlr.collections.AST delimiterNode, antlr.collections.AST nameNode) throws antlr.SemanticException - Overrides:
generateNamedParameterin classHqlSqlBaseWalker- Throws:
antlr.SemanticException
-
processConstant
- Overrides:
processConstantin classHqlSqlBaseWalker- Throws:
antlr.SemanticException
-
processBoolean
- Overrides:
processBooleanin classHqlSqlBaseWalker- Throws:
antlr.SemanticException
-
processNumericLiteral
- Overrides:
processNumericLiteralin classHqlSqlBaseWalker
-
processIndex
- Overrides:
processIndexin classHqlSqlBaseWalker- Throws:
antlr.SemanticException
-
processFunction
protected void processFunction(antlr.collections.AST functionCall, boolean inSelect) throws antlr.SemanticException - Overrides:
processFunctionin classHqlSqlBaseWalker- Throws:
antlr.SemanticException
-
processAggregation
protected void processAggregation(antlr.collections.AST node, boolean inSelect) throws antlr.SemanticException - Overrides:
processAggregationin classHqlSqlBaseWalker- Throws:
antlr.SemanticException
-
processConstructor
- Overrides:
processConstructorin classHqlSqlBaseWalker- Throws:
antlr.SemanticException
-
setAlias
- Overrides:
setAliasin classHqlSqlBaseWalker
-
isOrderExpressionResultVariableRef
protected boolean isOrderExpressionResultVariableRef(antlr.collections.AST orderExpressionNode) throws antlr.SemanticException - Overrides:
isOrderExpressionResultVariableRefin classHqlSqlBaseWalker- Throws:
antlr.SemanticException
-
handleResultVariableRef
protected void handleResultVariableRef(antlr.collections.AST resultVariableRef) throws antlr.SemanticException - Overrides:
handleResultVariableRefin classHqlSqlBaseWalker- Throws:
antlr.SemanticException
-
getNamedParameterLocations
Returns the locations of all occurrences of the named parameter.- Specified by:
getNamedParameterLocationsin interfaceParameterBinder.NamedParameterSource- Throws:
QueryException
-
addQuerySpaces
-
getReturnTypes
-
getReturnAliases
-
getSelectClause
-
getFinalFromClause
-
isShallowQuery
public boolean isShallowQuery() -
getEnabledFilters
-
getLiteralProcessor
-
getASTPrinter
-
getParameters
-
getNumberOfParametersInSetClause
public int getNumberOfParametersInSetClause() -
evaluateAssignment
- Overrides:
evaluateAssignmentin classHqlSqlBaseWalker- Throws:
antlr.SemanticException
-
getAssignmentSpecifications
-
createIntoClause
protected antlr.collections.AST createIntoClause(String path, antlr.collections.AST propertySpec) throws antlr.SemanticException - Overrides:
createIntoClausein classHqlSqlBaseWalker- Throws:
antlr.SemanticException
-
prepareVersioned
protected void prepareVersioned(antlr.collections.AST updateNode, antlr.collections.AST versioned) throws antlr.SemanticException - Overrides:
prepareVersionedin classHqlSqlBaseWalker- Throws:
antlr.SemanticException
-
prepareLogicOperator
- Overrides:
prepareLogicOperatorin classHqlSqlBaseWalker- Throws:
antlr.SemanticException
-
prepareArithmeticOperator
protected void prepareArithmeticOperator(antlr.collections.AST operator) throws antlr.SemanticException - Overrides:
prepareArithmeticOperatorin classHqlSqlBaseWalker- Throws:
antlr.SemanticException
-
validateMapPropertyExpression
protected void validateMapPropertyExpression(antlr.collections.AST node) throws antlr.SemanticException - Overrides:
validateMapPropertyExpressionin classHqlSqlBaseWalker- Throws:
antlr.SemanticException
-
panic
public static void panic()
-