Skip to content

Package: SoqlQueryListener

SoqlQueryListener

nameinstructionbranchcomplexitylinemethod
SoqlQueryListener(MetamodelImpl)
M: 0 C: 48
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 13
100%
M: 0 C: 1
100%
buildGrouping()
M: 0 C: 27
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
buildOrdering()
M: 0 C: 27
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
buildSparqlQueryString()
M: 1 C: 105
99%
M: 1 C: 13
93%
M: 1 C: 7
88%
M: 1 C: 22
96%
M: 0 C: 1
100%
createSyntheticAttributeForEntityId()
M: 0 C: 21
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
enterArithmeticFactor(SoqlParser.ArithmeticFactorContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterArithmeticPrimary(SoqlParser.ArithmeticPrimaryContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterArithmeticTerm(SoqlParser.ArithmeticTermContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterAttribute(SoqlParser.AttributeContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterComparisonExpression(SoqlParser.ComparisonExpressionContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterConditionalExpression(SoqlParser.ConditionalExpressionContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterConditionalFactor(SoqlParser.ConditionalFactorContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterConditionalTerm(SoqlParser.ConditionalTermContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterCount(SoqlParser.CountContext)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
enterDistinct(SoqlParser.DistinctContext)
M: 0 C: 11
100%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 3
100%
M: 0 C: 1
100%
enterDistinctParam(SoqlParser.DistinctParamContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterEveryRule(ParserRuleContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterFunctionsReturningNumerics(SoqlParser.FunctionsReturningNumericsContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterFunctionsReturningStrings(SoqlParser.FunctionsReturningStringsContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterGroupByClause(SoqlParser.GroupByClauseContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterGroupByParam(SoqlParser.GroupByParamContext)
M: 0 C: 64
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 16
100%
M: 0 C: 1
100%
enterGroupByParamComma(SoqlParser.GroupByParamCommaContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterInExpression(SoqlParser.InExpressionContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterInItem(SoqlParser.InItemContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterInputParameter(SoqlParser.InputParameterContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterJoinedParams(SoqlParser.JoinedParamsContext)
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
enterLikeExpression(SoqlParser.LikeExpressionContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterLiteral(SoqlParser.LiteralContext)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
enterObjWithAttr(SoqlParser.ObjWithAttrContext)
M: 0 C: 43
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
enterObjWithOutAttr(SoqlParser.ObjWithOutAttrContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterObject(SoqlParser.ObjectContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterOrderByClause(SoqlParser.OrderByClauseContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterOrderByFullForm(SoqlParser.OrderByFullFormContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterOrderByFullFormComma(SoqlParser.OrderByFullFormCommaContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterOrderByParam(SoqlParser.OrderByParamContext)
M: 0 C: 70
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 17
100%
M: 0 C: 1
100%
enterParam(SoqlParser.ParamContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterParamComma(SoqlParser.ParamCommaContext)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
enterParams(SoqlParser.ParamsContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterQuerySentence(SoqlParser.QuerySentenceContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterSelectStatement(SoqlParser.SelectStatementContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterSelectedParam(SoqlParser.SelectedParamContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterSimpleArithmeticExpression(SoqlParser.SimpleArithmeticExpressionContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterSimpleConditionalExpression(SoqlParser.SimpleConditionalExpressionContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterStringExpression(SoqlParser.StringExpressionContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterTable(SoqlParser.TableContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterTableName(SoqlParser.TableNameContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterTableWithName(SoqlParser.TableWithNameContext)
M: 0 C: 37
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
enterTables(SoqlParser.TablesContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterTypeDef(SoqlParser.TypeDefContext)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
enterWhereClauseParam(SoqlParser.WhereClauseParamContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterWhereClauseValue(SoqlParser.WhereClauseValueContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
enterWhereClauseWrapper(SoqlParser.WhereClauseWrapperContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitArithmeticFactor(SoqlParser.ArithmeticFactorContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitArithmeticPrimary(SoqlParser.ArithmeticPrimaryContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitArithmeticTerm(SoqlParser.ArithmeticTermContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitAttribute(SoqlParser.AttributeContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitComparisonExpression(SoqlParser.ComparisonExpressionContext)
M: 5 C: 62
93%
M: 2 C: 6
75%
M: 2 C: 3
60%
M: 0 C: 14
100%
M: 0 C: 1
100%
exitConditionalExpression(SoqlParser.ConditionalExpressionContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitConditionalFactor(SoqlParser.ConditionalFactorContext)
M: 0 C: 9
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
exitConditionalTerm(SoqlParser.ConditionalTermContext)
M: 0 C: 20
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
exitCount(SoqlParser.CountContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitDistinct(SoqlParser.DistinctContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitDistinctParam(SoqlParser.DistinctParamContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitEveryRule(ParserRuleContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitFunctionsReturningNumerics(SoqlParser.FunctionsReturningNumericsContext)
M: 0 C: 18
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
exitFunctionsReturningStrings(SoqlParser.FunctionsReturningStringsContext)
M: 0 C: 18
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
exitGroupByClause(SoqlParser.GroupByClauseContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitGroupByParam(SoqlParser.GroupByParamContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitGroupByParamComma(SoqlParser.GroupByParamCommaContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitInExpression(SoqlParser.InExpressionContext)
M: 4 C: 41
91%
M: 1 C: 5
83%
M: 1 C: 3
75%
M: 0 C: 10
100%
M: 0 C: 1
100%
exitInItem(SoqlParser.InItemContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitInputParameter(SoqlParser.InputParameterContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitJoinedParams(SoqlParser.JoinedParamsContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitLikeExpression(SoqlParser.LikeExpressionContext)
M: 0 C: 42
100%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 10
100%
M: 0 C: 1
100%
exitLiteral(SoqlParser.LiteralContext)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
exitObjWithAttr(SoqlParser.ObjWithAttrContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitObjWithOutAttr(SoqlParser.ObjWithOutAttrContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitObject(SoqlParser.ObjectContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitOrderByClause(SoqlParser.OrderByClauseContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitOrderByFullForm(SoqlParser.OrderByFullFormContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitOrderByFullFormComma(SoqlParser.OrderByFullFormCommaContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitOrderByParam(SoqlParser.OrderByParamContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitParam(SoqlParser.ParamContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitParamComma(SoqlParser.ParamCommaContext)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
exitParams(SoqlParser.ParamsContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitQuerySentence(SoqlParser.QuerySentenceContext)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
exitSelectStatement(SoqlParser.SelectStatementContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitSelectedParam(SoqlParser.SelectedParamContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitSimpleArithmeticExpression(SoqlParser.SimpleArithmeticExpressionContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitSimpleConditionalExpression(SoqlParser.SimpleConditionalExpressionContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitStringExpression(SoqlParser.StringExpressionContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitTable(SoqlParser.TableContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitTableName(SoqlParser.TableNameContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitTableWithName(SoqlParser.TableWithNameContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitTables(SoqlParser.TablesContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitTypeDef(SoqlParser.TypeDefContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitWhereClauseParam(SoqlParser.WhereClauseParamContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitWhereClauseValue(SoqlParser.WhereClauseValueContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exitWhereClauseWrapper(SoqlParser.WhereClauseWrapperContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getAttributeFromParam(ParserRuleContext)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getCountPart()
M: 0 C: 23
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
getEntityType(String)
M: 2 C: 23
92%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 1 C: 5
83%
M: 0 C: 1
100%
getOrderingBy(ParserRuleContext)
M: 0 C: 11
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getOwnerFromParam(ParserRuleContext)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getSparqlQuery()
M: 4 C: 7
64%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 2
100%
M: 0 C: 1
100%
isIdentifier(SoqlNode, SoqlNode)
M: 4 C: 26
87%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 2 C: 5
71%
M: 0 C: 1
100%
linkContextNodes(ParserRuleContext)
M: 0 C: 47
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
processAllFilters(ArrayList, ArrayList)
M: 0 C: 24
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
processAttribute(SoqlAttribute)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
processAttributes()
M: 0 C: 89
100%
M: 0 C: 10
100%
M: 0 C: 6
100%
M: 0 C: 21
100%
M: 0 C: 1
100%
processFilter(ArrayList)
M: 0 C: 33
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
processInvFilter(ArrayList)
M: 2 C: 50
96%
M: 1 C: 5
83%
M: 1 C: 3
75%
M: 1 C: 11
92%
M: 0 C: 1
100%
processSupremeAttributes()
M: 0 C: 35
100%
M: 0 C: 8
100%
M: 0 C: 5
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
pushNewAttribute(SoqlAttribute)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
resolveBindableType(Attribute)
M: 0 C: 11
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
resolveInExpressionValue(SoqlParser.InExpressionContext)
M: 0 C: 21
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
setAllNodesIris(EntityType, SoqlNode)
M: 1 C: 35
97%
M: 1 C: 5
83%
M: 1 C: 3
75%
M: 1 C: 9
90%
M: 0 C: 1
100%
setIris(SoqlNode)
M: 2 C: 28
93%
M: 3 C: 3
50%
M: 3 C: 1
25%
M: 2 C: 7
78%
M: 0 C: 1
100%
setObjectIri(SoqlNode)
M: 6 C: 16
73%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 2 C: 5
71%
M: 0 C: 1
100%
static {...}
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
visitErrorNode(ErrorNode)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
visitTerminal(TerminalNode)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (C) 2022 Czech Technical University in Prague
3: * <p>
4: * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
5: * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
6: * version.
7: * <p>
8: * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
9: * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
10: * details. You should have received a copy of the GNU General Public License along with this program. If not, see
11: * <http://www.gnu.org/licenses/>.
12: */
13: package cz.cvut.kbss.jopa.query.soql;
14:
15: import cz.cvut.kbss.jopa.model.MetamodelImpl;
16: import cz.cvut.kbss.jopa.model.metamodel.*;
17: import org.antlr.v4.runtime.ParserRuleContext;
18: import org.antlr.v4.runtime.tree.ErrorNode;
19: import org.antlr.v4.runtime.tree.ParseTree;
20: import org.antlr.v4.runtime.tree.TerminalNode;
21: import org.slf4j.Logger;
22: import org.slf4j.LoggerFactory;
23:
24: import java.util.*;
25: import java.util.stream.Collectors;
26:
27: public class SoqlQueryListener implements SoqlListener {
28:
29: private static final Logger LOG = LoggerFactory.getLogger(SoqlQueryListener.class);
30:
31: private final MetamodelImpl metamodel;
32:
33: private String soql;
34: private String sparql;
35:
36: private String typeDef = "SELECT";
37:
38: // keeps pointer at created object of SoqlAttribute while processing other necessary rules
39: private SoqlAttribute attrPointer;
40:
41: private final List<SoqlAttribute> attributes;
42:
43: // keeps index of first object of SoqlAttribute after OR operator
44: private final Set<SoqlAttribute> objectOfNextOr;
45:
46: private final List<SoqlOrderParameter> orderAttributes;
47:
48: private final List<SoqlGroupParameter> groupAttributes;
49:
50: private final Map<String, String> objectTypes;
51:
52: private boolean isSelectedParamDistinct = false;
53:
54: private boolean isSelectedParamCount = false;
55:
56: private boolean isInObjectIdentifierExpression = false;
57:
58: private String rootVariable = "?x";
59:
60:
61: public SoqlQueryListener(MetamodelImpl metamodel) {
62: this.metamodel = Objects.requireNonNull(metamodel);
63: this.attributes = new ArrayList<>();
64: this.objectOfNextOr = new HashSet<>();
65: this.orderAttributes = new ArrayList<>();
66: this.groupAttributes = new ArrayList<>();
67: this.objectTypes = new HashMap<>();
68: }
69:
70: @Override
71: public void enterQuerySentence(SoqlParser.QuerySentenceContext ctx) {
72: }
73:
74: @Override
75: public void exitQuerySentence(SoqlParser.QuerySentenceContext ctx) {
76: this.soql = ctx.getText();
77: buildSparqlQueryString();
78: }
79:
80: @Override
81: public void enterSelectStatement(SoqlParser.SelectStatementContext ctx) {
82: }
83:
84: @Override
85: public void exitSelectStatement(SoqlParser.SelectStatementContext ctx) {
86: }
87:
88: @Override
89: public void enterParams(SoqlParser.ParamsContext ctx) {
90: }
91:
92: @Override
93: public void exitParams(SoqlParser.ParamsContext ctx) {
94: }
95:
96: @Override
97: public void enterParam(SoqlParser.ParamContext ctx) {
98: }
99:
100: @Override
101: public void exitParam(SoqlParser.ParamContext ctx) {
102: }
103:
104: @Override
105: public void enterJoinedParams(SoqlParser.JoinedParamsContext ctx) {
106: SoqlNode firstNode = linkContextNodes(ctx);
107: SoqlAttribute myAttr = new SoqlAttribute(firstNode);
108: pushNewAttribute(myAttr);
109: }
110:
111: private void pushNewAttribute(SoqlAttribute myAttr) {
112: attributes.add(myAttr);
113: this.attrPointer = myAttr;
114: }
115:
116: @Override
117: public void exitJoinedParams(SoqlParser.JoinedParamsContext ctx) {
118: }
119:
120: @Override
121: public void enterParamComma(SoqlParser.ParamCommaContext ctx) {
122: }
123:
124: @Override
125: public void exitParamComma(SoqlParser.ParamCommaContext ctx) {
126: }
127:
128: @Override
129: public void enterDistinctParam(SoqlParser.DistinctParamContext ctx) {
130: }
131:
132: @Override
133: public void exitDistinctParam(SoqlParser.DistinctParamContext ctx) {
134: }
135:
136: @Override
137: public void enterSelectedParam(SoqlParser.SelectedParamContext ctx) {
138: }
139:
140: @Override
141: public void exitSelectedParam(SoqlParser.SelectedParamContext ctx) {
142: }
143:
144: @Override
145: public void enterCount(SoqlParser.CountContext ctx) {
146: isSelectedParamCount = true;
147: }
148:
149: @Override
150: public void exitCount(SoqlParser.CountContext ctx) {
151: }
152:
153: @Override
154: public void enterObject(SoqlParser.ObjectContext ctx) {
155: }
156:
157: @Override
158: public void exitObject(SoqlParser.ObjectContext ctx) {
159: }
160:
161: @Override
162: public void enterObjWithAttr(SoqlParser.ObjWithAttrContext ctx) {
163: String owner = getOwnerFromParam(ctx);
164: String attribute = getAttributeFromParam(ctx);
165: // objectNode.attributeNode
166: SoqlNode objectNode = new AttributeNode(owner);
167: SoqlNode attributeNode = new AttributeNode(objectNode, attribute);
168: objectNode.setChild(attributeNode);
169:• if (isIdentifier(objectNode, attributeNode)) {
170: this.isInObjectIdentifierExpression = true;
171: } else {
172: setIris(objectNode);
173: SoqlAttribute myAttr = new SoqlAttribute(objectNode);
174: pushNewAttribute(myAttr);
175: }
176: }
177:
178: private boolean isIdentifier(SoqlNode objectNode, SoqlNode attributeNode) {
179:• if (!objectTypes.containsKey(objectNode.getValue())) {
180: return false;
181: }
182: String objectName = objectTypes.get(objectNode.getValue());
183: EntityTypeImpl<?> entityType = getEntityType(objectName);
184:• if (entityType == null) {
185: return false;
186: }
187: return entityType.getIdentifier().getName().equals(attributeNode.getValue());
188: }
189:
190: @Override
191: public void exitObjWithAttr(SoqlParser.ObjWithAttrContext ctx) {
192: }
193:
194: @Override
195: public void enterObjWithOutAttr(SoqlParser.ObjWithOutAttrContext ctx) {
196: }
197:
198: @Override
199: public void exitObjWithOutAttr(SoqlParser.ObjWithOutAttrContext ctx) {
200: }
201:
202: @Override
203: public void enterAttribute(SoqlParser.AttributeContext ctx) {
204: }
205:
206: @Override
207: public void exitAttribute(SoqlParser.AttributeContext ctx) {
208: }
209:
210: @Override
211: public void enterTypeDef(SoqlParser.TypeDefContext ctx) {
212: typeDef = ctx.getChild(0).getText();
213: }
214:
215: @Override
216: public void exitTypeDef(SoqlParser.TypeDefContext ctx) {
217: }
218:
219: @Override
220: public void enterDistinct(SoqlParser.DistinctContext ctx) {
221:• if (SoqlConstants.DISTINCT.equals(ctx.getChild(0).getText())) {
222: isSelectedParamDistinct = true;
223: }
224: }
225:
226: @Override
227: public void exitDistinct(SoqlParser.DistinctContext ctx) {
228: }
229:
230: @Override
231: public void enterWhereClauseWrapper(SoqlParser.WhereClauseWrapperContext ctx) {
232: }
233:
234: @Override
235: public void exitWhereClauseWrapper(SoqlParser.WhereClauseWrapperContext ctx) {
236: }
237:
238: @Override
239: public void enterConditionalExpression(SoqlParser.ConditionalExpressionContext ctx) {
240: }
241:
242: @Override
243: public void exitConditionalExpression(SoqlParser.ConditionalExpressionContext ctx) {
244: }
245:
246: @Override
247: public void enterConditionalTerm(SoqlParser.ConditionalTermContext ctx) {
248: }
249:
250: @Override
251: public void exitConditionalTerm(SoqlParser.ConditionalTermContext ctx) {
252: final ParserRuleContext parentCtx = ctx.getParent();
253:• if (parentCtx.getChildCount() > 1 && !parentCtx.getChild(0).equals(ctx)) {
254: objectOfNextOr.add(attrPointer);
255: }
256: }
257:
258: @Override
259: public void enterConditionalFactor(SoqlParser.ConditionalFactorContext ctx) {
260: }
261:
262: @Override
263: public void exitConditionalFactor(SoqlParser.ConditionalFactorContext ctx) {
264:• if (ctx.getChildCount() > 1) {
265: attrPointer.setNot(true);
266: }
267: }
268:
269: @Override
270: public void enterSimpleConditionalExpression(SoqlParser.SimpleConditionalExpressionContext ctx) {
271: }
272:
273: @Override
274: public void exitSimpleConditionalExpression(SoqlParser.SimpleConditionalExpressionContext ctx) {
275: }
276:
277: @Override
278: public void enterInExpression(SoqlParser.InExpressionContext ctx) {
279: }
280:
281: @Override
282: public void exitInExpression(SoqlParser.InExpressionContext ctx) {
283:• assert ctx.getChildCount() > 2;
284:• if (isInObjectIdentifierExpression) {
285: pushNewAttribute(createSyntheticAttributeForEntityId());
286: }
287: final ParseTree value = resolveInExpressionValue(ctx);
288:• if (ctx.getChild(1).getText().equals(SoqlConstants.NOT)) {
289: attrPointer.setOperator(InOperator.notIn());
290: } else {
291: attrPointer.setOperator(InOperator.in());
292: }
293: attrPointer.setValue(value.getText());
294: this.isInObjectIdentifierExpression = false;
295: }
296:
297: private SoqlAttribute createSyntheticAttributeForEntityId() {
298: return new SoqlAttribute(
299:• attrPointer.getFirstNode().hasChild() ? attrPointer.getFirstNode().getChild() :
300: new AttributeNode(rootVariable.substring(1)));
301: }
302:
303: private ParseTree resolveInExpressionValue(SoqlParser.InExpressionContext ctx) {
304: final ParseTree lastToken = ctx.getChild(ctx.getChildCount() - 1);
305:• if (")".equals(lastToken.getText())) {
306: return ctx.getChild(ctx.getChildCount() - 2);
307: }
308: return lastToken;
309: }
310:
311: @Override
312: public void enterInItem(SoqlParser.InItemContext ctx) {
313: }
314:
315: @Override
316: public void exitInItem(SoqlParser.InItemContext ctx) {
317: }
318:
319: @Override
320: public void enterLiteral(SoqlParser.LiteralContext ctx) {
321: }
322:
323: @Override
324: public void exitLiteral(SoqlParser.LiteralContext ctx) {
325: }
326:
327: @Override
328: public void enterLikeExpression(SoqlParser.LikeExpressionContext ctx) {
329: }
330:
331: @Override
332: public void exitLikeExpression(SoqlParser.LikeExpressionContext ctx) {
333:• if (ctx.getChildCount() > 2 && ctx.getChild(1).getText().equals(SoqlConstants.NOT)) {
334: attrPointer.setOperator(LikeOperator.notLike());
335: ParseTree whereClauseValue = ctx.getChild(3);
336: attrPointer.setValue(whereClauseValue.getText());
337: } else {
338: attrPointer.setOperator(LikeOperator.like());
339: ParseTree whereClauseValue = ctx.getChild(2);
340: attrPointer.setValue(whereClauseValue.getText());
341: }
342: this.isInObjectIdentifierExpression = false;
343: }
344:
345: @Override
346: public void enterComparisonExpression(SoqlParser.ComparisonExpressionContext ctx) {
347: }
348:
349: @Override
350: public void exitComparisonExpression(SoqlParser.ComparisonExpressionContext ctx) {
351: String operator = ctx.getChild(1).getText();
352:
353: ParseTree whereClauseValue = ctx.getChild(2);
354:
355:• if (isInObjectIdentifierExpression) {
356:• assert Objects.equals(operator, "=");
357:• if (attributes.size() == 1) {
358: this.rootVariable = SoqlUtils.soqlVariableToSparqlVariable(whereClauseValue.getText());
359: } else {
360: final String varName = whereClauseValue.getText();
361: attrPointer.getFirstNode().getChild().setValue(
362:• varName.charAt(0) == SoqlConstants.VARIABLE_PREFIX ? varName.substring(1) : varName);
363: }
364: } else {
365: attrPointer.setOperator(new ComparisonOperator(operator));
366: attrPointer.setValue(whereClauseValue.getText());
367: }
368: this.isInObjectIdentifierExpression = false;
369: }
370:
371: @Override
372: public void enterTables(SoqlParser.TablesContext ctx) {
373: }
374:
375: @Override
376: public void exitTables(SoqlParser.TablesContext ctx) {
377: }
378:
379: @Override
380: public void enterTable(SoqlParser.TableContext ctx) {
381: }
382:
383: @Override
384: public void exitTable(SoqlParser.TableContext ctx) {
385: }
386:
387: @Override
388: public void enterTableName(SoqlParser.TableNameContext ctx) {
389: }
390:
391: @Override
392: public void exitTableName(SoqlParser.TableNameContext ctx) {
393: }
394:
395: @Override
396: public void enterTableWithName(SoqlParser.TableWithNameContext ctx) {
397: String table = ctx.getChild(0).getChild(0).getText();
398: String objectName = ctx.getChild(1).getChild(0).getText();
399: objectTypes.put(objectName, table);
400: SoqlNode node = new AttributeNode(table);
401: setObjectIri(node);
402: SoqlAttribute myAttr = new SoqlAttribute(node);
403: pushNewAttribute(myAttr);
404: }
405:
406: @Override
407: public void exitTableWithName(SoqlParser.TableWithNameContext ctx) {
408: }
409:
410: @Override
411: public void enterWhereClauseValue(SoqlParser.WhereClauseValueContext ctx) {
412: }
413:
414: @Override
415: public void exitWhereClauseValue(SoqlParser.WhereClauseValueContext ctx) {
416: }
417:
418: @Override
419: public void enterWhereClauseParam(SoqlParser.WhereClauseParamContext ctx) {
420: }
421:
422: @Override
423: public void exitWhereClauseParam(SoqlParser.WhereClauseParamContext ctx) {
424: }
425:
426: @Override
427: public void enterStringExpression(SoqlParser.StringExpressionContext ctx) {
428:
429: }
430:
431: @Override
432: public void exitStringExpression(SoqlParser.StringExpressionContext ctx) {
433:
434: }
435:
436: @Override
437: public void enterFunctionsReturningStrings(SoqlParser.FunctionsReturningStringsContext ctx) {
438:
439: }
440:
441: @Override
442: public void exitFunctionsReturningStrings(SoqlParser.FunctionsReturningStringsContext ctx) {
443: final String functionName = ctx.getChild(0).getText();
444: final FunctionNode node = new FunctionNode(attrPointer.getFirstNode(), functionName);
445: attrPointer.setFirstNode(node);
446: }
447:
448: @Override
449: public void enterSimpleArithmeticExpression(SoqlParser.SimpleArithmeticExpressionContext ctx) {
450:
451: }
452:
453: @Override
454: public void exitSimpleArithmeticExpression(SoqlParser.SimpleArithmeticExpressionContext ctx) {
455:
456: }
457:
458: @Override
459: public void enterArithmeticTerm(SoqlParser.ArithmeticTermContext ctx) {
460:
461: }
462:
463: @Override
464: public void exitArithmeticTerm(SoqlParser.ArithmeticTermContext ctx) {
465:
466: }
467:
468: @Override
469: public void enterArithmeticFactor(SoqlParser.ArithmeticFactorContext ctx) {
470:
471: }
472:
473: @Override
474: public void exitArithmeticFactor(SoqlParser.ArithmeticFactorContext ctx) {
475:
476: }
477:
478: @Override
479: public void enterArithmeticPrimary(SoqlParser.ArithmeticPrimaryContext ctx) {
480:
481: }
482:
483: @Override
484: public void exitArithmeticPrimary(SoqlParser.ArithmeticPrimaryContext ctx) {
485:
486: }
487:
488: @Override
489: public void enterFunctionsReturningNumerics(SoqlParser.FunctionsReturningNumericsContext ctx) {
490: }
491:
492: @Override
493: public void exitFunctionsReturningNumerics(SoqlParser.FunctionsReturningNumericsContext ctx) {
494: final String functionName = ctx.getChild(0).getText();
495: final FunctionNode node = new FunctionNode(attrPointer.getFirstNode(), functionName);
496: attrPointer.setFirstNode(node);
497: }
498:
499: @Override
500: public void enterOrderByClause(SoqlParser.OrderByClauseContext ctx) {
501: }
502:
503: @Override
504: public void exitOrderByClause(SoqlParser.OrderByClauseContext ctx) {
505: }
506:
507: @Override
508: public void enterOrderByFullFormComma(SoqlParser.OrderByFullFormCommaContext ctx) {
509: }
510:
511: @Override
512: public void exitOrderByFullFormComma(SoqlParser.OrderByFullFormCommaContext ctx) {
513: }
514:
515: @Override
516: public void enterOrderByFullForm(SoqlParser.OrderByFullFormContext ctx) {
517: }
518:
519: @Override
520: public void exitOrderByFullForm(SoqlParser.OrderByFullFormContext ctx) {
521: }
522:
523: @Override
524: public void enterOrderByParam(SoqlParser.OrderByParamContext ctx) {
525: SoqlNode firstNode = linkContextNodes(ctx);
526: String orderingBy = getOrderingBy(ctx.getParent());
527: SoqlOrderParameter orderParam = new SoqlOrderParameter(firstNode, orderingBy);
528: boolean attrSet = false;
529:• for (SoqlAttribute attr : attributes) {
530:• if (attr.getAsParam().equals(orderParam.getAsParam())) {
531: orderParam.setAttribute(attr);
532: attrSet = true;
533: }
534: }
535:• if (!attrSet) {
536: SoqlAttribute myAttr = new SoqlAttribute(firstNode);
537: myAttr.setValue(orderParam.getAsValue(rootVariable));
538: myAttr.setOrderBy(true);
539: attributes.add(1, myAttr);
540: orderParam.setAttribute(myAttr);
541: }
542: orderAttributes.add(orderParam);
543: }
544:
545: @Override
546: public void exitOrderByParam(SoqlParser.OrderByParamContext ctx) {
547: }
548:
549: @Override
550: public void enterGroupByClause(SoqlParser.GroupByClauseContext ctx) {
551: }
552:
553: @Override
554: public void exitGroupByClause(SoqlParser.GroupByClauseContext ctx) {
555: }
556:
557: @Override
558: public void enterGroupByParamComma(SoqlParser.GroupByParamCommaContext ctx) {
559: }
560:
561: @Override
562: public void exitGroupByParamComma(SoqlParser.GroupByParamCommaContext ctx) {
563: }
564:
565: @Override
566: public void enterGroupByParam(SoqlParser.GroupByParamContext ctx) {
567: SoqlNode firstNode = linkContextNodes(ctx);
568: SoqlGroupParameter groupParam = new SoqlGroupParameter(firstNode);
569: boolean attrSet = false;
570:• for (SoqlAttribute attr : attributes) {
571:• if (attr.getAsParam().equals(groupParam.getAsParam())) {
572: groupParam.setAttribute(attr);
573: attrSet = true;
574: }
575: }
576:• if (!attrSet) {
577: SoqlAttribute myAttr = new SoqlAttribute(firstNode);
578: myAttr.setValue(groupParam.getAsValue(rootVariable));
579: myAttr.setGroupBy(true);
580: attributes.add(1, myAttr);
581: groupParam.setAttribute(myAttr);
582: }
583: groupAttributes.add(groupParam);
584: }
585:
586: private SoqlNode linkContextNodes(ParserRuleContext ctx) {
587: SoqlNode firstNode = new AttributeNode(getOwnerFromParam(ctx));
588: SoqlNode currentNode = firstNode;
589:• for (int i = 2; i < ctx.getChildCount(); i += 2) {
590: SoqlNode prevNode = currentNode;
591: currentNode = new AttributeNode(prevNode, ctx.getChild(i).getText());
592: prevNode.setChild(currentNode);
593: }
594: setIris(firstNode);
595:• if (currentNode.getIri().isEmpty()) {
596: currentNode.getParent().setChild(null);
597: this.isInObjectIdentifierExpression = true;
598: }
599: return firstNode;
600: }
601:
602: @Override
603: public void exitGroupByParam(SoqlParser.GroupByParamContext ctx) {
604: }
605:
606: @Override
607: public void enterInputParameter(SoqlParser.InputParameterContext ctx) {
608:
609: }
610:
611: @Override
612: public void exitInputParameter(SoqlParser.InputParameterContext ctx) {
613:
614: }
615:
616: @Override
617: public void visitTerminal(TerminalNode terminalNode) {
618: }
619:
620: @Override
621: public void visitErrorNode(ErrorNode errorNode) {
622: }
623:
624: @Override
625: public void enterEveryRule(ParserRuleContext parserRuleContext) {
626: }
627:
628: @Override
629: public void exitEveryRule(ParserRuleContext parserRuleContext) {
630: }
631:
632: //Methods to help parse tree
633: private String getOwnerFromParam(ParserRuleContext ctx) {
634: return ctx.getChild(0).getChild(0).getText();
635: }
636:
637: private String getAttributeFromParam(ParserRuleContext ctx) {
638: return ctx.getChild(2).getChild(0).getText();
639: }
640:
641: private String getOrderingBy(ParserRuleContext ctx) {
642:• return ctx.getChildCount() > 1 ? ctx.getChild(1).getText() : "";
643: }
644:
645: private void setObjectIri(SoqlNode node) {
646: EntityTypeImpl<?> entityType = getEntityType(node.getValue());
647:• if (entityType == null) {
648: return;
649: }
650: node.setIri(entityType.getIRI().toString());
651:• if (node.hasChild()) {
652: setAllNodesIris(entityType, node.getChild());
653: }
654: }
655:
656: private EntityTypeImpl<?> getEntityType(String name) {
657:• for (EntityType<?> type : metamodel.getEntities()) {
658: EntityTypeImpl<?> entityType = (EntityTypeImpl<?>) type;
659:• if (entityType.getName().equals(name)) {
660: return entityType;
661: }
662: }
663: return null;
664: }
665:
666: private void setAllNodesIris(EntityType<?> entityType, SoqlNode node) {
667:• if (entityType.getIdentifier().getName().equals(node.getValue())) {
668: return;
669: }
670: final Attribute<?, ?> abstractAttribute = entityType.getAttribute(node.getValue());
671: //not implemented case of 3 or more fragments (chained SoqlNodes)
672: node.setIri(abstractAttribute.getIRI().toString());
673:• if (node.hasChild()) {
674: final Type<?> type = resolveBindableType(abstractAttribute);
675:• if (type.getPersistenceType() != Type.PersistenceType.ENTITY) {
676: return;
677: }
678: setAllNodesIris((EntityType<?>) type, node.getChild());
679: }
680: }
681:
682: private static Type<?> resolveBindableType(Attribute<?, ?> att) {
683:• if (att.isCollection()) {
684: return ((PluralAttribute<?, ?, ?>) att).getElementType();
685: } else {
686: return ((SingularAttribute<?, ?>) att).getType();
687: }
688: }
689:
690: private void setIris(SoqlNode firstNode) {
691:• if (!objectTypes.containsKey(firstNode.getValue())) {
692: return;
693: }
694: String objectName = objectTypes.get(firstNode.getValue());
695: EntityTypeImpl<?> entityType = getEntityType(objectName);
696:• if (entityType == null) {
697: return;
698: }
699:• if (firstNode.hasChild()) {
700: setAllNodesIris(entityType, firstNode.getChild());
701: }
702: }
703:
704: public String getSparqlQuery() {
705:• assert sparql != null;
706: return sparql;
707: }
708:
709: //Methods to build new Query
710: private void buildSparqlQueryString() {
711:• if (attributes.isEmpty()) {
712: return;
713: }
714: StringBuilder newQueryBuilder = new StringBuilder(typeDef);
715:• if (isSelectedParamCount) {
716: newQueryBuilder.append(getCountPart());
717: } else {
718:• if (isSelectedParamDistinct) {
719: newQueryBuilder.append(' ').append(SoqlConstants.DISTINCT);
720: }
721: newQueryBuilder.append(' ').append(rootVariable).append(' ');
722: }
723: newQueryBuilder.append("WHERE { ");
724: newQueryBuilder.append(processSupremeAttributes());
725:• if (!objectOfNextOr.isEmpty()) {
726: newQueryBuilder.append("{ ");
727: }
728: newQueryBuilder.append(processAttributes());
729:• if (!objectOfNextOr.isEmpty()) {
730: newQueryBuilder.append("} ");
731: }
732: newQueryBuilder.append('}');
733:• if (!groupAttributes.isEmpty()) {
734: newQueryBuilder.append(' ').append(buildGrouping());
735: }
736:• if (!orderAttributes.isEmpty()) {
737: newQueryBuilder.append(' ').append(buildOrdering());
738: }
739: sparql = newQueryBuilder.toString();
740: LOG.trace("Translated SOQL query '{}' to SPARQL '{}'.", soql, sparql);
741: }
742:
743: private StringBuilder getCountPart() {
744: StringBuilder countPart = new StringBuilder(" (COUNT(");
745:• if (isSelectedParamDistinct) {
746: countPart.append(SoqlConstants.DISTINCT).append(' ');
747: }
748: countPart.append(rootVariable).append(") AS ?count) ");
749: return countPart;
750: }
751:
752: private StringBuilder processSupremeAttributes() {
753: StringBuilder attributesPart = new StringBuilder();
754: final Iterator<SoqlAttribute> it = attributes.iterator();
755:• while (it.hasNext()) {
756: final SoqlAttribute current = it.next();
757:• if (current.isInstanceOf() || current.isOrderBy() || current.isGroupBy()) {
758: attributesPart.append(processAttribute(current));
759: it.remove();
760: }
761: }
762: return attributesPart;
763: }
764:
765: private StringBuilder processAttributes() {
766: StringBuilder attributesPart = new StringBuilder();
767: ArrayList<SoqlAttribute> toFilter = new ArrayList<>();
768: ArrayList<SoqlAttribute> toInvFilter = new ArrayList<>();
769:• for (SoqlAttribute myAttr : attributes) {
770:• if (objectOfNextOr.contains(myAttr)) {
771: StringBuilder orPart = new StringBuilder();
772: orPart.append(processAllFilters(toFilter, toInvFilter));
773: toFilter.clear();
774: toInvFilter.clear();
775: orPart.append("} UNION { ");
776: attributesPart.append(orPart);
777: }
778:• if (myAttr.isNot()) {
779: toInvFilter.add(myAttr);
780: } else {
781:• if (myAttr.requiresFilter()) {
782: toFilter.add(myAttr);
783: }
784: final String bgp = processAttribute(myAttr);
785:• if (attributesPart.indexOf(bgp) == -1) {
786: attributesPart.append(bgp);
787: }
788: }
789: }
790: attributesPart.append(processAllFilters(toFilter, toInvFilter));
791: return attributesPart;
792: }
793:
794: private StringBuilder processAllFilters(ArrayList<SoqlAttribute> toFilter, ArrayList<SoqlAttribute> toInvFilter) {
795: StringBuilder part = new StringBuilder();
796:• if (!toFilter.isEmpty()) {
797: part.append(processFilter(toFilter));
798: }
799:• if (!toInvFilter.isEmpty()) {
800: part.append(processInvFilter(toInvFilter));
801: }
802: return part;
803: }
804:
805: private String processFilter(ArrayList<SoqlAttribute> toFilter) {
806: StringBuilder buildFilter = new StringBuilder();
807:• if (toFilter.isEmpty()) {
808: return "";
809: }
810: buildFilter.append("FILTER (");
811: buildFilter.append(toFilter.stream().map(SoqlAttribute::getFilterExpressions).flatMap(Collection::stream)
812: .collect(Collectors.joining(" && ")));
813: buildFilter.append(") ");
814: return buildFilter.toString();
815: }
816:
817: private String processInvFilter(ArrayList<SoqlAttribute> toInvFilter) {
818: StringBuilder buildInvFilter = new StringBuilder();
819: ArrayList<SoqlAttribute> toFilter = new ArrayList<>();
820:• if (toInvFilter.isEmpty()) {
821: return "";
822: }
823: buildInvFilter.append("FILTER NOT EXISTS { ");
824:• for (SoqlAttribute attr : toInvFilter) {
825: buildInvFilter.append(processAttribute(attr));
826:• if (attr.requiresFilter()) {
827: toFilter.add(attr);
828: }
829: }
830: buildInvFilter.append(processFilter(toFilter)).append("} ");
831: return buildInvFilter.toString();
832: }
833:
834: private String processAttribute(SoqlAttribute attr) {
835: return attr.getBasicGraphPattern(rootVariable);
836: }
837:
838: private String buildOrdering() {
839: StringBuilder sb = new StringBuilder("ORDER BY");
840:• for (SoqlOrderParameter orderParam : orderAttributes) {
841: sb.append(' ').append(orderParam.getOrderByPart());
842: }
843: return sb.toString();
844: }
845:
846: private String buildGrouping() {
847: StringBuilder sb = new StringBuilder("GROUP BY");
848:• for (SoqlGroupParameter groupParam : groupAttributes) {
849: sb.append(' ').append(groupParam.getGroupByPart());
850: }
851: return sb.toString();
852: }
853: }