minor cleanups to the grammar

- simplify two rules that were unnecessarily flexible
- remove useless parens
- rename some rules for readability
- clean up some warnings in SemanticQueryBuilder
This commit is contained in:
Gavin King 2022-01-01 21:00:57 +01:00
parent 7599d3b2dd
commit f9afab5492
2 changed files with 63 additions and 73 deletions

View File

@ -31,20 +31,20 @@ selectStatement
: queryExpression : queryExpression
; ;
subQuery subquery
: queryExpression : queryExpression
; ;
dmlTarget targetEntity
: entityName identificationVariableDef? : entityName identificationVariableDef?
; ;
deleteStatement deleteStatement
: DELETE FROM? dmlTarget whereClause? : DELETE FROM? targetEntity whereClause?
; ;
updateStatement updateStatement
: UPDATE VERSIONED? dmlTarget setClause whereClause? : UPDATE VERSIONED? targetEntity setClause whereClause?
; ;
setClause setClause
@ -56,10 +56,10 @@ assignment
; ;
insertStatement insertStatement
: INSERT INTO? dmlTarget targetFieldsSpec (queryExpression | valuesList) : INSERT INTO? targetEntity targetFields (queryExpression | valuesList)
; ;
targetFieldsSpec targetFields
: LEFT_PAREN dotIdentifierSequence (COMMA dotIdentifierSequence)* RIGHT_PAREN : LEFT_PAREN dotIdentifierSequence (COMMA dotIdentifierSequence)* RIGHT_PAREN
; ;
@ -75,12 +75,12 @@ values
// QUERY SPEC - general structure of root sqm or sub sqm // QUERY SPEC - general structure of root sqm or sub sqm
queryExpression queryExpression
: simpleQueryExpression # SimpleQueryGroup : orderedQuery # SimpleQueryGroup
| queryExpression (setOperator simpleQueryExpression)+ # SetQueryGroup | orderedQuery (setOperator orderedQuery)+ # SetQueryGroup
; ;
simpleQueryExpression orderedQuery
: querySpec queryOrder? # QuerySpecExpression : query queryOrder? # QuerySpecExpression
| LEFT_PAREN queryExpression RIGHT_PAREN queryOrder? # NestedQueryExpression | LEFT_PAREN queryExpression RIGHT_PAREN queryOrder? # NestedQueryExpression
; ;
@ -91,10 +91,10 @@ setOperator
; ;
queryOrder queryOrder
: orderByClause limitClause? offsetClause? fetchClause? : orderByClause limitClause? offsetClause? fetchClause?
; ;
querySpec query
// TODO: add with clause // TODO: add with clause
: selectClause fromClause? whereClause? ( groupByClause havingClause? )? : selectClause fromClause? whereClause? ( groupByClause havingClause? )?
| fromClause whereClause? ( groupByClause havingClause? )? selectClause? | fromClause whereClause? ( groupByClause havingClause? )? selectClause?
@ -230,7 +230,7 @@ dotIdentifierSequenceContinuation
* path; see `syntacticNavigablePath` rule * path; see `syntacticNavigablePath` rule
*/ */
path path
: syntacticDomainPath (pathContinuation)? : syntacticDomainPath pathContinuation?
| generalPathFragment | generalPathFragment
; ;
@ -390,15 +390,15 @@ whereClause
predicate predicate
//highest to lowest precedence //highest to lowest precedence
: LEFT_PAREN predicate RIGHT_PAREN # GroupedPredicate : LEFT_PAREN predicate RIGHT_PAREN # GroupedPredicate
| expression IS (NOT)? NULL # IsNullPredicate | expression IS NOT? NULL # IsNullPredicate
| expression IS (NOT)? EMPTY # IsEmptyPredicate | expression IS NOT? EMPTY # IsEmptyPredicate
| expression (NOT)? IN inList # InPredicate | expression NOT? IN inList # InPredicate
| expression (NOT)? BETWEEN expression AND expression # BetweenPredicate | expression NOT? BETWEEN expression AND expression # BetweenPredicate
| expression (NOT)? (LIKE | ILIKE) expression (likeEscape)? # LikePredicate | expression NOT? (LIKE | ILIKE) expression likeEscape? # LikePredicate
| expression comparisonOperator expression # ComparisonPredicate | expression comparisonOperator expression # ComparisonPredicate
| EXISTS (ELEMENTS|INDICES) LEFT_PAREN dotIdentifierSequence RIGHT_PAREN # ExistsCollectionPartPredicate | EXISTS (ELEMENTS|INDICES) LEFT_PAREN dotIdentifierSequence RIGHT_PAREN # ExistsCollectionPartPredicate
| EXISTS expression # ExistsPredicate | EXISTS expression # ExistsPredicate
| expression (NOT)? MEMBER OF path # MemberOfPredicate | expression NOT? MEMBER OF? path # MemberOfPredicate
| NOT predicate # NegatedPredicate | NOT predicate # NegatedPredicate
| predicate AND predicate # AndPredicate | predicate AND predicate # AndPredicate
| predicate OR predicate # OrPredicate | predicate OR predicate # OrPredicate
@ -419,12 +419,12 @@ comparisonOperator
inList inList
: (ELEMENTS|INDICES) LEFT_PAREN dotIdentifierSequence RIGHT_PAREN # PersistentCollectionReferenceInList : (ELEMENTS|INDICES) LEFT_PAREN dotIdentifierSequence RIGHT_PAREN # PersistentCollectionReferenceInList
| LEFT_PAREN (expressionOrPredicate (COMMA expressionOrPredicate)*)? RIGHT_PAREN# ExplicitTupleInList | LEFT_PAREN (expressionOrPredicate (COMMA expressionOrPredicate)*)? RIGHT_PAREN# ExplicitTupleInList
| LEFT_PAREN subQuery RIGHT_PAREN # SubQueryInList | LEFT_PAREN subquery RIGHT_PAREN # SubqueryInList
| parameter # ParamInList | parameter # ParamInList
; ;
likeEscape likeEscape
: ESCAPE expression : ESCAPE STRING_LITERAL
; ;
@ -435,7 +435,7 @@ expression
//highest to lowest precedence //highest to lowest precedence
: LEFT_PAREN expression RIGHT_PAREN # GroupedExpression : LEFT_PAREN expression RIGHT_PAREN # GroupedExpression
| LEFT_PAREN expressionOrPredicate (COMMA expressionOrPredicate)+ RIGHT_PAREN # TupleExpression | LEFT_PAREN expressionOrPredicate (COMMA expressionOrPredicate)+ RIGHT_PAREN # TupleExpression
| LEFT_PAREN subQuery RIGHT_PAREN # SubQueryExpression | LEFT_PAREN subquery RIGHT_PAREN # SubqueryExpression
| primaryExpression collationSpecification? # CollateExpression | primaryExpression collationSpecification? # CollateExpression
| signOperator numericLiteral # UnaryNumericLiteralExpression | signOperator numericLiteral # UnaryNumericLiteralExpression
| signOperator expression # UnaryExpression | signOperator expression # UnaryExpression
@ -454,7 +454,7 @@ primaryExpression
| entityIdReference # EntityIdExpression | entityIdReference # EntityIdExpression
| entityVersionReference # EntityVersionExpression | entityVersionReference # EntityVersionExpression
| entityNaturalIdReference # EntityNaturalIdExpression | entityNaturalIdReference # EntityNaturalIdExpression
| syntacticDomainPath (pathContinuation)? # SyntacticPathExpression | syntacticDomainPath pathContinuation? # SyntacticPathExpression
| function # FunctionExpression | function # FunctionExpression
| generalPathFragment # GeneralPathExpression | generalPathFragment # GeneralPathExpression
; ;
@ -502,7 +502,7 @@ caseList
; ;
simpleCaseList simpleCaseList
: CASE expressionOrPredicate (simpleCaseWhen)+ (caseOtherwise)? END : CASE expressionOrPredicate simpleCaseWhen+ caseOtherwise? END
; ;
simpleCaseWhen simpleCaseWhen
@ -514,7 +514,7 @@ caseOtherwise
; ;
searchedCaseList searchedCaseList
: CASE (searchedCaseWhen)+ (caseOtherwise)? END : CASE searchedCaseWhen+ caseOtherwise? END
; ;
searchedCaseWhen searchedCaseWhen
@ -553,7 +553,7 @@ temporalLiteral
| timeLiteral | timeLiteral
| jdbcTimestampLiteral | jdbcTimestampLiteral
| jdbcDateLiteral | jdbcDateLiteral
| jdbcTimeLiteral | jdbcTimeLiteral
; ;
dateTimeLiteral dateTimeLiteral
@ -674,13 +674,13 @@ aggregateFunction
everyFunction everyFunction
: (EVERY|ALL) LEFT_PAREN predicate RIGHT_PAREN filterClause? : (EVERY|ALL) LEFT_PAREN predicate RIGHT_PAREN filterClause?
| (EVERY|ALL) LEFT_PAREN subQuery RIGHT_PAREN | (EVERY|ALL) LEFT_PAREN subquery RIGHT_PAREN
| (EVERY|ALL) (ELEMENTS|INDICES) LEFT_PAREN dotIdentifierSequence RIGHT_PAREN | (EVERY|ALL) (ELEMENTS|INDICES) LEFT_PAREN dotIdentifierSequence RIGHT_PAREN
; ;
anyFunction anyFunction
: (ANY|SOME) LEFT_PAREN predicate RIGHT_PAREN filterClause? : (ANY|SOME) LEFT_PAREN predicate RIGHT_PAREN filterClause?
| (ANY|SOME) LEFT_PAREN subQuery RIGHT_PAREN | (ANY|SOME) LEFT_PAREN subquery RIGHT_PAREN
| (ANY|SOME) (ELEMENTS|INDICES) LEFT_PAREN dotIdentifierSequence RIGHT_PAREN | (ANY|SOME) (ELEMENTS|INDICES) LEFT_PAREN dotIdentifierSequence RIGHT_PAREN
; ;
@ -982,9 +982,9 @@ identifier
| LIMIT | LIMIT
| LIST | LIST
| LOCAL | LOCAL
| LOCAL_DATE | LOCAL_DATE
| LOCAL_DATETIME | LOCAL_DATETIME
| LOCAL_TIME | LOCAL_TIME
| MAP | MAP
| MAXELEMENT | MAXELEMENT
| MAXINDEX | MAXINDEX

View File

@ -320,11 +320,6 @@ public class SemanticQueryBuilder<R> extends HqlParserBaseVisitor<Object> implem
return processingStateStack; return processingStateStack;
} }
protected Stack<ParameterDeclarationContext> getParameterDeclarationContextStack() {
return parameterDeclarationContextStack;
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Grammar rules // Grammar rules
@ -388,7 +383,7 @@ public class SemanticQueryBuilder<R> extends HqlParserBaseVisitor<Object> implem
} }
@Override @Override
public SqmRoot<R> visitDmlTarget(HqlParser.DmlTargetContext dmlTargetContext) { public SqmRoot<R> visitTargetEntity(HqlParser.TargetEntityContext dmlTargetContext) {
final HqlParser.EntityNameContext entityNameContext = (HqlParser.EntityNameContext) dmlTargetContext.getChild( 0 ); final HqlParser.EntityNameContext entityNameContext = (HqlParser.EntityNameContext) dmlTargetContext.getChild( 0 );
final String identificationVariable; final String identificationVariable;
if ( dmlTargetContext.getChildCount() == 1 ) { if ( dmlTargetContext.getChildCount() == 1 ) {
@ -413,17 +408,17 @@ public class SemanticQueryBuilder<R> extends HqlParserBaseVisitor<Object> implem
@Override @Override
public SqmInsertStatement<R> visitInsertStatement(HqlParser.InsertStatementContext ctx) { public SqmInsertStatement<R> visitInsertStatement(HqlParser.InsertStatementContext ctx) {
final int dmlTargetIndex; final int dmlTargetIndex;
if ( ctx.getChild( 1 ) instanceof HqlParser.DmlTargetContext ) { if ( ctx.getChild( 1 ) instanceof HqlParser.TargetEntityContext ) {
dmlTargetIndex = 1; dmlTargetIndex = 1;
} }
else { else {
dmlTargetIndex = 2; dmlTargetIndex = 2;
} }
final HqlParser.DmlTargetContext dmlTargetContext = (HqlParser.DmlTargetContext) ctx.getChild( dmlTargetIndex ); final HqlParser.TargetEntityContext dmlTargetContext = (HqlParser.TargetEntityContext) ctx.getChild( dmlTargetIndex );
final HqlParser.TargetFieldsSpecContext targetFieldsSpecContext = (HqlParser.TargetFieldsSpecContext) ctx.getChild( final HqlParser.TargetFieldsContext targetFieldsSpecContext = (HqlParser.TargetFieldsContext) ctx.getChild(
dmlTargetIndex + 1 dmlTargetIndex + 1
); );
final SqmRoot<R> root = visitDmlTarget( dmlTargetContext ); final SqmRoot<R> root = visitTargetEntity( dmlTargetContext );
if ( root.getReferencedPathSource() instanceof SqmPolymorphicRootDescriptor<?> ) { if ( root.getReferencedPathSource() instanceof SqmPolymorphicRootDescriptor<?> ) {
throw new SemanticException( throw new SemanticException(
"Can't create an INSERT for a non entity name: " + root.getReferencedPathSource().getHibernateEntityName() "Can't create an INSERT for a non entity name: " + root.getReferencedPathSource().getHibernateEntityName()
@ -508,10 +503,10 @@ public class SemanticQueryBuilder<R> extends HqlParserBaseVisitor<Object> implem
@Override @Override
public SqmUpdateStatement<R> visitUpdateStatement(HqlParser.UpdateStatementContext ctx) { public SqmUpdateStatement<R> visitUpdateStatement(HqlParser.UpdateStatementContext ctx) {
final boolean versioned = !( ctx.getChild( 1 ) instanceof HqlParser.DmlTargetContext ); final boolean versioned = !( ctx.getChild( 1 ) instanceof HqlParser.TargetEntityContext );
final int dmlTargetIndex = versioned ? 2 : 1; final int dmlTargetIndex = versioned ? 2 : 1;
final HqlParser.DmlTargetContext dmlTargetContext = (HqlParser.DmlTargetContext) ctx.getChild( dmlTargetIndex ); final HqlParser.TargetEntityContext dmlTargetContext = (HqlParser.TargetEntityContext) ctx.getChild( dmlTargetIndex );
final SqmRoot<R> root = visitDmlTarget( dmlTargetContext ); final SqmRoot<R> root = visitTargetEntity( dmlTargetContext );
if ( root.getReferencedPathSource() instanceof SqmPolymorphicRootDescriptor<?> ) { if ( root.getReferencedPathSource() instanceof SqmPolymorphicRootDescriptor<?> ) {
throw new SemanticException( throw new SemanticException(
"Can't create an UPDATE for a non entity name: " + root.getReferencedPathSource().getHibernateEntityName() "Can't create an UPDATE for a non entity name: " + root.getReferencedPathSource().getHibernateEntityName()
@ -556,14 +551,14 @@ public class SemanticQueryBuilder<R> extends HqlParserBaseVisitor<Object> implem
@Override @Override
public SqmDeleteStatement<R> visitDeleteStatement(HqlParser.DeleteStatementContext ctx) { public SqmDeleteStatement<R> visitDeleteStatement(HqlParser.DeleteStatementContext ctx) {
final int dmlTargetIndex; final int dmlTargetIndex;
if ( ctx.getChild( 1 ) instanceof HqlParser.DmlTargetContext ) { if ( ctx.getChild( 1 ) instanceof HqlParser.TargetEntityContext ) {
dmlTargetIndex = 1; dmlTargetIndex = 1;
} }
else { else {
dmlTargetIndex = 2; dmlTargetIndex = 2;
} }
final HqlParser.DmlTargetContext dmlTargetContext = (HqlParser.DmlTargetContext) ctx.getChild( dmlTargetIndex ); final HqlParser.TargetEntityContext dmlTargetContext = (HqlParser.TargetEntityContext) ctx.getChild( dmlTargetIndex );
final SqmRoot<R> root = visitDmlTarget( dmlTargetContext ); final SqmRoot<R> root = visitTargetEntity( dmlTargetContext );
final SqmDeleteStatement<R> deleteStatement = new SqmDeleteStatement<>( root, SqmQuerySource.HQL, creationContext.getNodeBuilder() ); final SqmDeleteStatement<R> deleteStatement = new SqmDeleteStatement<>( root, SqmQuerySource.HQL, creationContext.getNodeBuilder() );
@ -604,7 +599,7 @@ public class SemanticQueryBuilder<R> extends HqlParserBaseVisitor<Object> implem
@Override @Override
public SqmQueryPart<Object> visitQuerySpecExpression(HqlParser.QuerySpecExpressionContext ctx) { public SqmQueryPart<Object> visitQuerySpecExpression(HqlParser.QuerySpecExpressionContext ctx) {
final List<ParseTree> children = ctx.children; final List<ParseTree> children = ctx.children;
final SqmQueryPart<Object> queryPart = visitQuerySpec( (HqlParser.QuerySpecContext) children.get( 0 ) ); final SqmQueryPart<Object> queryPart = visitQuery( (HqlParser.QueryContext) children.get( 0 ) );
if ( children.size() > 1 ) { if ( children.size() > 1 ) {
visitQueryOrder( queryPart, (HqlParser.QueryOrderContext) children.get( 1 ) ); visitQueryOrder( queryPart, (HqlParser.QueryOrderContext) children.get( 1 ) );
} }
@ -644,8 +639,8 @@ public class SemanticQueryBuilder<R> extends HqlParserBaseVisitor<Object> implem
final SqmCreationProcessingState firstProcessingState = processingStateStack.pop(); final SqmCreationProcessingState firstProcessingState = processingStateStack.pop();
for ( int i = 1; i < size; i += 2 ) { for ( int i = 1; i < size; i += 2 ) {
final SetOperator operator = visitSetOperator( (HqlParser.SetOperatorContext) children.get( i ) ); final SetOperator operator = visitSetOperator( (HqlParser.SetOperatorContext) children.get( i ) );
final HqlParser.SimpleQueryExpressionContext simpleQueryCtx = final HqlParser.OrderedQueryContext simpleQueryCtx =
(HqlParser.SimpleQueryExpressionContext) children.get( i + 1 ); (HqlParser.OrderedQueryContext) children.get( i + 1 );
final List<SqmQueryPart<Object>> queryParts; final List<SqmQueryPart<Object>> queryParts;
if ( queryGroup.getSetOperator() == null || queryGroup.getSetOperator() == operator ) { if ( queryGroup.getSetOperator() == null || queryGroup.getSetOperator() == operator ) {
queryGroup.setSetOperator( operator ); queryGroup.setSetOperator( operator );
@ -672,7 +667,7 @@ public class SemanticQueryBuilder<R> extends HqlParserBaseVisitor<Object> implem
) )
); );
final List<ParseTree> subChildren = simpleQueryCtx.children; final List<ParseTree> subChildren = simpleQueryCtx.children;
if ( subChildren.get( 0 ) instanceof HqlParser.QuerySpecContext ) { if ( subChildren.get( 0 ) instanceof HqlParser.QueryContext ) {
final SqmQuerySpec<Object> querySpec = new SqmQuerySpec<>( creationContext.getNodeBuilder() ); final SqmQuerySpec<Object> querySpec = new SqmQuerySpec<>( creationContext.getNodeBuilder() );
queryParts.add( querySpec ); queryParts.add( querySpec );
visitQuerySpecExpression( (HqlParser.QuerySpecExpressionContext) simpleQueryCtx ); visitQuerySpecExpression( (HqlParser.QuerySpecExpressionContext) simpleQueryCtx );
@ -788,7 +783,7 @@ public class SemanticQueryBuilder<R> extends HqlParserBaseVisitor<Object> implem
} }
@Override @Override
public SqmQuerySpec<Object> visitQuerySpec(HqlParser.QuerySpecContext ctx) { public SqmQuerySpec<Object> visitQuery(HqlParser.QueryContext ctx) {
//noinspection unchecked //noinspection unchecked
final SqmQuerySpec<Object> sqmQuerySpec = (SqmQuerySpec<Object>) currentQuerySpec(); final SqmQuerySpec<Object> sqmQuerySpec = (SqmQuerySpec<Object>) currentQuerySpec();
final int fromIndex; final int fromIndex;
@ -939,7 +934,7 @@ public class SemanticQueryBuilder<R> extends HqlParserBaseVisitor<Object> implem
); );
} }
final SqmPath<?> elementPath = (SqmPath<?>) sqmPath.resolvePathPart( CollectionPart.Nature.ELEMENT.getName(), true, this ); final SqmPath<?> elementPath = sqmPath.resolvePathPart( CollectionPart.Nature.ELEMENT.getName(), true, this );
processingStateStack.getCurrent().getPathRegistry().register( elementPath ); processingStateStack.getCurrent().getPathRegistry().register( elementPath );
return elementPath; return elementPath;
} }
@ -1220,10 +1215,6 @@ public class SemanticQueryBuilder<R> extends HqlParserBaseVisitor<Object> implem
} }
} }
private int getSelectionPosition(SqmSelection<?> selection) {
return currentQuerySpec().getSelectClause().getSelections().indexOf( selection ) + 1;
}
@Override @Override
public SqmExpression<?> visitLimitClause(HqlParser.LimitClauseContext ctx) { public SqmExpression<?> visitLimitClause(HqlParser.LimitClauseContext ctx) {
if ( ctx == null ) { if ( ctx == null ) {
@ -1286,7 +1277,7 @@ public class SemanticQueryBuilder<R> extends HqlParserBaseVisitor<Object> implem
if ( part instanceof DomainPathPart ) { if ( part instanceof DomainPathPart ) {
return ( (DomainPathPart) part ).getSqmExpression(); return ( (DomainPathPart) part ).getSqmExpression();
} }
return (SqmExpression<?>) part; return part;
} }
@Override @Override
@ -1295,7 +1286,7 @@ public class SemanticQueryBuilder<R> extends HqlParserBaseVisitor<Object> implem
if ( part instanceof DomainPathPart ) { if ( part instanceof DomainPathPart ) {
return ( (DomainPathPart) part ).getSqmExpression(); return ( (DomainPathPart) part ).getSqmExpression();
} }
return (SqmExpression<?>) part; return part;
} }
@Override @Override
@ -1453,7 +1444,7 @@ public class SemanticQueryBuilder<R> extends HqlParserBaseVisitor<Object> implem
// Handle the use of a correlation path in subqueries // Handle the use of a correlation path in subqueries
if ( processingStateStack.depth() > 1 && size > 2 ) { if ( processingStateStack.depth() > 1 && size > 2 ) {
final String parentAlias = entityNameParseTreeChildren.get( 0 ).getText(); final String parentAlias = entityNameParseTreeChildren.get( 0 ).getText();
final AbstractSqmFrom<?, ?> correlationBasis = (AbstractSqmFrom<?, ?>) processingState.getParentProcessingState() final AbstractSqmFrom<?, ?> correlationBasis = processingState.getParentProcessingState()
.getPathRegistry() .getPathRegistry()
.findFromByAlias( parentAlias ); .findFromByAlias( parentAlias );
if ( correlationBasis != null ) { if ( correlationBasis != null ) {
@ -2051,11 +2042,11 @@ public class SemanticQueryBuilder<R> extends HqlParserBaseVisitor<Object> implem
parameterDeclarationContextStack.pop(); parameterDeclarationContextStack.pop();
} }
} }
else if ( inListContext instanceof HqlParser.SubQueryInListContext ) { else if ( inListContext instanceof HqlParser.SubqueryInListContext ) {
final HqlParser.SubQueryInListContext subQueryOrParamInListContext = (HqlParser.SubQueryInListContext) inListContext; final HqlParser.SubqueryInListContext subQueryOrParamInListContext = (HqlParser.SubqueryInListContext) inListContext;
return new SqmInSubQueryPredicate( return new SqmInSubQueryPredicate(
testExpression, testExpression,
visitSubQuery( (HqlParser.SubQueryContext) subQueryOrParamInListContext.getChild( 1 ) ), visitSubquery( (HqlParser.SubqueryContext) subQueryOrParamInListContext.getChild( 1 ) ),
negated, negated,
creationContext.getNodeBuilder() creationContext.getNodeBuilder()
); );
@ -2095,7 +2086,7 @@ public class SemanticQueryBuilder<R> extends HqlParserBaseVisitor<Object> implem
return new SqmExistsPredicate( expression, creationContext.getNodeBuilder() ); return new SqmExistsPredicate( expression, creationContext.getNodeBuilder() );
} }
@Override @Override @SuppressWarnings("rawtypes")
public SqmPredicate visitBooleanExpressionPredicate(HqlParser.BooleanExpressionPredicateContext ctx) { public SqmPredicate visitBooleanExpressionPredicate(HqlParser.BooleanExpressionPredicateContext ctx) {
final SqmExpression expression = (SqmExpression) ctx.expression().accept( this ); final SqmExpression expression = (SqmExpression) ctx.expression().accept( this );
if ( expression.getJavaType() != Boolean.class ) { if ( expression.getJavaType() != Boolean.class ) {
@ -3563,7 +3554,7 @@ public class SemanticQueryBuilder<R> extends HqlParserBaseVisitor<Object> implem
public SqmExpression<?> visitEveryFunction(HqlParser.EveryFunctionContext ctx) { public SqmExpression<?> visitEveryFunction(HqlParser.EveryFunctionContext ctx) {
final SqmPredicate filterExpression = getFilterExpression( ctx ); final SqmPredicate filterExpression = getFilterExpression( ctx );
final ParseTree argumentChild = ctx.getChild( 2 ); final ParseTree argumentChild = ctx.getChild( 2 );
if ( argumentChild instanceof HqlParser.SubQueryContext ) { if ( argumentChild instanceof HqlParser.SubqueryContext ) {
final SqmSubQuery<?> subquery = (SqmSubQuery<?>) argumentChild.accept( this ); final SqmSubQuery<?> subquery = (SqmSubQuery<?>) argumentChild.accept( this );
return new SqmEvery<>( subquery, creationContext.getNodeBuilder() ); return new SqmEvery<>( subquery, creationContext.getNodeBuilder() );
} }
@ -3599,7 +3590,7 @@ public class SemanticQueryBuilder<R> extends HqlParserBaseVisitor<Object> implem
public SqmExpression<?> visitAnyFunction(HqlParser.AnyFunctionContext ctx) { public SqmExpression<?> visitAnyFunction(HqlParser.AnyFunctionContext ctx) {
final SqmPredicate filterExpression = getFilterExpression( ctx ); final SqmPredicate filterExpression = getFilterExpression( ctx );
final ParseTree argumentChild = ctx.getChild( 2 ); final ParseTree argumentChild = ctx.getChild( 2 );
if ( argumentChild instanceof HqlParser.SubQueryContext ) { if ( argumentChild instanceof HqlParser.SubqueryContext ) {
final SqmSubQuery<?> subquery = (SqmSubQuery<?>) argumentChild.accept( this ); final SqmSubQuery<?> subquery = (SqmSubQuery<?>) argumentChild.accept( this );
return new SqmAny<>( subquery, creationContext.getNodeBuilder() ); return new SqmAny<>( subquery, creationContext.getNodeBuilder() );
} }
@ -3642,7 +3633,6 @@ public class SemanticQueryBuilder<R> extends HqlParserBaseVisitor<Object> implem
"Illegal attempt to treat non-plural path as a plural path : " + pluralAttributePath.getNavigablePath() "Illegal attempt to treat non-plural path as a plural path : " + pluralAttributePath.getNavigablePath()
); );
} }
final PluralPersistentAttribute<?, ?, ?> attribute = (PluralPersistentAttribute<?, ?, ?>) referencedPathSource;
final SqmSubQuery<?> subQuery = new SqmSubQuery<>( final SqmSubQuery<?> subQuery = new SqmSubQuery<>(
processingStateStack.getCurrent().getProcessingQuery(), processingStateStack.getCurrent().getProcessingQuery(),
creationContext.getNodeBuilder() creationContext.getNodeBuilder()
@ -3934,12 +3924,12 @@ public class SemanticQueryBuilder<R> extends HqlParserBaseVisitor<Object> implem
} }
@Override @Override
public SqmSubQuery<?> visitSubQueryExpression(HqlParser.SubQueryExpressionContext ctx) { public SqmSubQuery<?> visitSubqueryExpression(HqlParser.SubqueryExpressionContext ctx) {
return visitSubQuery( (HqlParser.SubQueryContext) ctx.getChild( 1 ) ); return visitSubquery( (HqlParser.SubqueryContext) ctx.getChild( 1 ) );
} }
@Override @Override
public SqmSubQuery<?> visitSubQuery(HqlParser.SubQueryContext ctx) { public SqmSubQuery<?> visitSubquery(HqlParser.SubqueryContext ctx) {
final HqlParser.QueryExpressionContext queryExpressionContext = (HqlParser.QueryExpressionContext) ctx.getChild( 0 ); final HqlParser.QueryExpressionContext queryExpressionContext = (HqlParser.QueryExpressionContext) ctx.getChild( 0 );
final SqmSubQuery<?> subQuery = new SqmSubQuery<>( final SqmSubQuery<?> subQuery = new SqmSubQuery<>(
processingStateStack.getCurrent().getProcessingQuery(), processingStateStack.getCurrent().getProcessingQuery(),
@ -4159,7 +4149,7 @@ public class SemanticQueryBuilder<R> extends HqlParserBaseVisitor<Object> implem
} }
} }
SqmPath<?> result = (SqmPath<?>) pluralAttributePath.resolvePathPart( CollectionPart.Nature.ELEMENT.getName(), true, this ); SqmPath<?> result = pluralAttributePath.resolvePathPart( CollectionPart.Nature.ELEMENT.getName(), true, this );
if ( ctx.getChildCount() == 5 ) { if ( ctx.getChildCount() == 5 ) {
result = consumeDomainPath( (HqlParser.DotIdentifierSequenceContext) ctx.getChild( 4 ).getChild( 1 ) ); result = consumeDomainPath( (HqlParser.DotIdentifierSequenceContext) ctx.getChild( 4 ).getChild( 1 ) );
@ -4183,11 +4173,11 @@ public class SemanticQueryBuilder<R> extends HqlParserBaseVisitor<Object> implem
); );
} }
return (SqmPath<?>) pluralAttributePath.resolvePathPart( CollectionPart.Nature.INDEX.getName(), true, this ); return pluralAttributePath.resolvePathPart( CollectionPart.Nature.INDEX.getName(), true, this );
} }
@Override @Override
@SuppressWarnings({ "rawtypes" }) @SuppressWarnings("rawtypes")
public SqmPath visitMapKeyNavigablePath(HqlParser.MapKeyNavigablePathContext ctx) { public SqmPath visitMapKeyNavigablePath(HqlParser.MapKeyNavigablePathContext ctx) {
final DotIdentifierConsumer consumer = dotIdentifierConsumerStack.getCurrent(); final DotIdentifierConsumer consumer = dotIdentifierConsumerStack.getCurrent();
final boolean madeNested; final boolean madeNested;