@Test public void testVariableImpacted() { final Set<String> attr = new HashSet<>(); attr.add("attr"); final Set<String> attr2 = new HashSet<>(); attr2.add("attr"); attr2.add("attr2"); final Set<String> abc = new HashSet<>(); abc.add("a"); abc.add("b"); abc.add("c"); assertTrue(Query.prepare("${attr}").getVariableImpact().isImpacted("attr")); assertFalse(Query.prepare("${attr}").getVariableImpact().isImpacted("attr2")); assertTrue(Query.prepare("${attr:trim():toUpper():equals('abc')}").getVariableImpact().isImpacted("attr")); assertFalse(Query.prepare("${anyAttribute('a', 'b', 'c'):equals('hello')}").getVariableImpact().isImpacted("attr")); assertTrue(Query.prepare("${anyAttribute('a', 'b', 'c'):equals('hello')}").getVariableImpact().isImpacted("a")); assertTrue(Query.prepare("${anyAttribute('a', 'b', 'c'):equals('hello')}").getVariableImpact().isImpacted("b")); assertTrue(Query.prepare("${anyAttribute('a', 'b', 'c'):equals('hello')}").getVariableImpact().isImpacted("c")); assertFalse(Query.prepare("${allAttributes('a', 'b', 'c'):equals('hello')}").getVariableImpact().isImpacted("attr")); assertTrue(Query.prepare("${allAttributes('a', 'b', 'c'):equals('hello')}").getVariableImpact().isImpacted("a")); assertTrue(Query.prepare("${allAttributes('a', 'b', 'c'):equals('hello')}").getVariableImpact().isImpacted("b")); assertTrue(Query.prepare("${allAttributes('a', 'b', 'c'):equals('hello')}").getVariableImpact().isImpacted("c")); assertTrue(Query.prepare("${attr:equals('${attr2}')}").getVariableImpact().isImpacted("attr")); assertTrue(Query.prepare("${attr:equals('${attr2}')}").getVariableImpact().isImpacted("attr2")); assertFalse(Query.prepare("${attr:equals('${attr2}')}").getVariableImpact().isImpacted("attr3")); assertTrue(Query.prepare("${allMatchingAttributes('a.*'):equals('hello')}").getVariableImpact().isImpacted("attr")); assertTrue(Query.prepare("${anyMatchingAttribute('a.*'):equals('hello')}").getVariableImpact().isImpacted("attr")); }
@Override public VariableImpact getVariableImpact() { final VariableImpact existing = this.variableImpact; if (existing != null) { return existing; } final Set<String> variables = new HashSet<>(); for (final Expression expression : expressions) { if (!(expression instanceof CompiledExpression)) { continue; } final CompiledExpression compiled = (CompiledExpression) expression; for (final Evaluator<?> evaluator : compiled.getAllEvaluators()) { if (evaluator instanceof AttributeEvaluator) { final AttributeEvaluator attributeEval = (AttributeEvaluator) evaluator; final Evaluator<String> nameEval = attributeEval.getNameEvaluator(); if (nameEval instanceof StringLiteralEvaluator) { final String referencedVar = nameEval.evaluate(Collections.emptyMap()).getValue(); variables.add(referencedVar); } } else if (evaluator instanceof AllAttributesEvaluator) { final AllAttributesEvaluator allAttrsEval = (AllAttributesEvaluator) evaluator; final MultiAttributeEvaluator iteratingEval = allAttrsEval.getVariableIteratingEvaluator(); if (iteratingEval instanceof MultiNamedAttributeEvaluator) { variables.addAll(((MultiNamedAttributeEvaluator) iteratingEval).getAttributeNames()); } else if (iteratingEval instanceof MultiMatchAttributeEvaluator) { return VariableImpact.ALWAYS_IMPACTED; } } else if (evaluator instanceof AnyAttributeEvaluator) { final AnyAttributeEvaluator allAttrsEval = (AnyAttributeEvaluator) evaluator; final MultiAttributeEvaluator iteratingEval = allAttrsEval.getVariableIteratingEvaluator(); if (iteratingEval instanceof MultiNamedAttributeEvaluator) { variables.addAll(((MultiNamedAttributeEvaluator) iteratingEval).getAttributeNames()); } else if (iteratingEval instanceof MultiMatchAttributeEvaluator) { return VariableImpact.ALWAYS_IMPACTED; } } else if (evaluator instanceof MappingEvaluator) { final MappingEvaluator<?> allAttrsEval = (MappingEvaluator<?>) evaluator; final MultiAttributeEvaluator iteratingEval = allAttrsEval.getVariableIteratingEvaluator(); if (iteratingEval instanceof MultiNamedAttributeEvaluator) { variables.addAll(((MultiNamedAttributeEvaluator) iteratingEval).getAttributeNames()); } } } } final VariableImpact impact = new NamedVariableImpact(variables); this.variableImpact = impact; return impact; }
StandardPreparedQuery implements PreparedQuery { @Override public VariableImpact getVariableImpact() { final VariableImpact existing = this.variableImpact; if (existing != null) { return existing; } final Set<String> variables = new HashSet<>(); for (final Expression expression : expressions) { if (!(expression instanceof CompiledExpression)) { continue; } final CompiledExpression compiled = (CompiledExpression) expression; for (final Evaluator<?> evaluator : compiled.getAllEvaluators()) { if (evaluator instanceof AttributeEvaluator) { final AttributeEvaluator attributeEval = (AttributeEvaluator) evaluator; final Evaluator<String> nameEval = attributeEval.getNameEvaluator(); if (nameEval instanceof StringLiteralEvaluator) { final String referencedVar = nameEval.evaluate(Collections.emptyMap()).getValue(); variables.add(referencedVar); } } else if (evaluator instanceof AllAttributesEvaluator) { final AllAttributesEvaluator allAttrsEval = (AllAttributesEvaluator) evaluator; final MultiAttributeEvaluator iteratingEval = allAttrsEval.getVariableIteratingEvaluator(); if (iteratingEval instanceof MultiNamedAttributeEvaluator) { variables.addAll(((MultiNamedAttributeEvaluator) iteratingEval).getAttributeNames()); } else if (iteratingEval instanceof MultiMatchAttributeEvaluator) { return VariableImpact.ALWAYS_IMPACTED; } } else if (evaluator instanceof AnyAttributeEvaluator) { final AnyAttributeEvaluator allAttrsEval = (AnyAttributeEvaluator) evaluator; final MultiAttributeEvaluator iteratingEval = allAttrsEval.getVariableIteratingEvaluator(); if (iteratingEval instanceof MultiNamedAttributeEvaluator) { variables.addAll(((MultiNamedAttributeEvaluator) iteratingEval).getAttributeNames()); } else if (iteratingEval instanceof MultiMatchAttributeEvaluator) { return VariableImpact.ALWAYS_IMPACTED; } } else if (evaluator instanceof MappingEvaluator) { final MappingEvaluator<?> allAttrsEval = (MappingEvaluator<?>) evaluator; final MultiAttributeEvaluator iteratingEval = allAttrsEval.getVariableIteratingEvaluator(); if (iteratingEval instanceof MultiNamedAttributeEvaluator) { variables.addAll(((MultiNamedAttributeEvaluator) iteratingEval).getAttributeNames()); } } } } final VariableImpact impact = new NamedVariableImpact(variables); this.variableImpact = impact; return impact; } }
StandardPreparedQuery implements PreparedQuery { @Override public VariableImpact getVariableImpact() { final VariableImpact existing = this.variableImpact; if (existing != null) { return existing; } final Set<String> variables = new HashSet<>(); for (final Expression expression : expressions) { if (!(expression instanceof CompiledExpression)) { continue; } final CompiledExpression compiled = (CompiledExpression) expression; for (final Evaluator<?> evaluator : compiled.getAllEvaluators()) { if (evaluator instanceof AttributeEvaluator) { final AttributeEvaluator attributeEval = (AttributeEvaluator) evaluator; final Evaluator<String> nameEval = attributeEval.getNameEvaluator(); if (nameEval instanceof StringLiteralEvaluator) { final String referencedVar = nameEval.evaluate(Collections.emptyMap()).getValue(); variables.add(referencedVar); } } else if (evaluator instanceof AllAttributesEvaluator) { final AllAttributesEvaluator allAttrsEval = (AllAttributesEvaluator) evaluator; final MultiAttributeEvaluator iteratingEval = allAttrsEval.getVariableIteratingEvaluator(); if (iteratingEval instanceof MultiNamedAttributeEvaluator) { variables.addAll(((MultiNamedAttributeEvaluator) iteratingEval).getAttributeNames()); } else if (iteratingEval instanceof MultiMatchAttributeEvaluator) { return VariableImpact.ALWAYS_IMPACTED; } } else if (evaluator instanceof AnyAttributeEvaluator) { final AnyAttributeEvaluator allAttrsEval = (AnyAttributeEvaluator) evaluator; final MultiAttributeEvaluator iteratingEval = allAttrsEval.getVariableIteratingEvaluator(); if (iteratingEval instanceof MultiNamedAttributeEvaluator) { variables.addAll(((MultiNamedAttributeEvaluator) iteratingEval).getAttributeNames()); } else if (iteratingEval instanceof MultiMatchAttributeEvaluator) { return VariableImpact.ALWAYS_IMPACTED; } } else if (evaluator instanceof MappingEvaluator) { final MappingEvaluator<?> allAttrsEval = (MappingEvaluator<?>) evaluator; final MultiAttributeEvaluator iteratingEval = allAttrsEval.getVariableIteratingEvaluator(); if (iteratingEval instanceof MultiNamedAttributeEvaluator) { variables.addAll(((MultiNamedAttributeEvaluator) iteratingEval).getAttributeNames()); } } } } final VariableImpact impact = new NamedVariableImpact(variables); this.variableImpact = impact; return impact; } StandardPreparedQuery(final List<Expression> expressions); }
StandardPreparedQuery implements PreparedQuery { @Override public VariableImpact getVariableImpact() { final VariableImpact existing = this.variableImpact; if (existing != null) { return existing; } final Set<String> variables = new HashSet<>(); for (final Expression expression : expressions) { if (!(expression instanceof CompiledExpression)) { continue; } final CompiledExpression compiled = (CompiledExpression) expression; for (final Evaluator<?> evaluator : compiled.getAllEvaluators()) { if (evaluator instanceof AttributeEvaluator) { final AttributeEvaluator attributeEval = (AttributeEvaluator) evaluator; final Evaluator<String> nameEval = attributeEval.getNameEvaluator(); if (nameEval instanceof StringLiteralEvaluator) { final String referencedVar = nameEval.evaluate(Collections.emptyMap()).getValue(); variables.add(referencedVar); } } else if (evaluator instanceof AllAttributesEvaluator) { final AllAttributesEvaluator allAttrsEval = (AllAttributesEvaluator) evaluator; final MultiAttributeEvaluator iteratingEval = allAttrsEval.getVariableIteratingEvaluator(); if (iteratingEval instanceof MultiNamedAttributeEvaluator) { variables.addAll(((MultiNamedAttributeEvaluator) iteratingEval).getAttributeNames()); } else if (iteratingEval instanceof MultiMatchAttributeEvaluator) { return VariableImpact.ALWAYS_IMPACTED; } } else if (evaluator instanceof AnyAttributeEvaluator) { final AnyAttributeEvaluator allAttrsEval = (AnyAttributeEvaluator) evaluator; final MultiAttributeEvaluator iteratingEval = allAttrsEval.getVariableIteratingEvaluator(); if (iteratingEval instanceof MultiNamedAttributeEvaluator) { variables.addAll(((MultiNamedAttributeEvaluator) iteratingEval).getAttributeNames()); } else if (iteratingEval instanceof MultiMatchAttributeEvaluator) { return VariableImpact.ALWAYS_IMPACTED; } } else if (evaluator instanceof MappingEvaluator) { final MappingEvaluator<?> allAttrsEval = (MappingEvaluator<?>) evaluator; final MultiAttributeEvaluator iteratingEval = allAttrsEval.getVariableIteratingEvaluator(); if (iteratingEval instanceof MultiNamedAttributeEvaluator) { variables.addAll(((MultiNamedAttributeEvaluator) iteratingEval).getAttributeNames()); } } } } final VariableImpact impact = new NamedVariableImpact(variables); this.variableImpact = impact; return impact; } StandardPreparedQuery(final List<Expression> expressions); @Override String evaluateExpressions(final Map<String, String> valMap, final AttributeValueDecorator decorator, final Map<String, String> stateVariables); @Override String evaluateExpressions(final Map<String, String> valMap, final AttributeValueDecorator decorator); @Override boolean isExpressionLanguagePresent(); @Override VariableImpact getVariableImpact(); }
StandardPreparedQuery implements PreparedQuery { @Override public VariableImpact getVariableImpact() { final VariableImpact existing = this.variableImpact; if (existing != null) { return existing; } final Set<String> variables = new HashSet<>(); for (final Expression expression : expressions) { if (!(expression instanceof CompiledExpression)) { continue; } final CompiledExpression compiled = (CompiledExpression) expression; for (final Evaluator<?> evaluator : compiled.getAllEvaluators()) { if (evaluator instanceof AttributeEvaluator) { final AttributeEvaluator attributeEval = (AttributeEvaluator) evaluator; final Evaluator<String> nameEval = attributeEval.getNameEvaluator(); if (nameEval instanceof StringLiteralEvaluator) { final String referencedVar = nameEval.evaluate(Collections.emptyMap()).getValue(); variables.add(referencedVar); } } else if (evaluator instanceof AllAttributesEvaluator) { final AllAttributesEvaluator allAttrsEval = (AllAttributesEvaluator) evaluator; final MultiAttributeEvaluator iteratingEval = allAttrsEval.getVariableIteratingEvaluator(); if (iteratingEval instanceof MultiNamedAttributeEvaluator) { variables.addAll(((MultiNamedAttributeEvaluator) iteratingEval).getAttributeNames()); } else if (iteratingEval instanceof MultiMatchAttributeEvaluator) { return VariableImpact.ALWAYS_IMPACTED; } } else if (evaluator instanceof AnyAttributeEvaluator) { final AnyAttributeEvaluator allAttrsEval = (AnyAttributeEvaluator) evaluator; final MultiAttributeEvaluator iteratingEval = allAttrsEval.getVariableIteratingEvaluator(); if (iteratingEval instanceof MultiNamedAttributeEvaluator) { variables.addAll(((MultiNamedAttributeEvaluator) iteratingEval).getAttributeNames()); } else if (iteratingEval instanceof MultiMatchAttributeEvaluator) { return VariableImpact.ALWAYS_IMPACTED; } } else if (evaluator instanceof MappingEvaluator) { final MappingEvaluator<?> allAttrsEval = (MappingEvaluator<?>) evaluator; final MultiAttributeEvaluator iteratingEval = allAttrsEval.getVariableIteratingEvaluator(); if (iteratingEval instanceof MultiNamedAttributeEvaluator) { variables.addAll(((MultiNamedAttributeEvaluator) iteratingEval).getAttributeNames()); } } } } final VariableImpact impact = new NamedVariableImpact(variables); this.variableImpact = impact; return impact; } StandardPreparedQuery(final List<Expression> expressions); @Override String evaluateExpressions(final Map<String, String> valMap, final AttributeValueDecorator decorator, final Map<String, String> stateVariables); @Override String evaluateExpressions(final Map<String, String> valMap, final AttributeValueDecorator decorator); @Override boolean isExpressionLanguagePresent(); @Override VariableImpact getVariableImpact();  }