use of org.eclipse.persistence.jpa.jpql.parser.IdentificationVariable in project eclipselink by eclipse-ee4j.
the class AbstractSemanticValidator method validateIdentificationVariables.
/**
* Validates the identification variables:
* <ul>
* <li>Assures those used throughout the query have been defined in the <code><b>FROM</b></code>
* clause in the current subquery or in a superquery.</li>
* <li>They have been defined only once.</li>
* </ul>
*/
protected void validateIdentificationVariables() {
// Collect the identification variables from the Declarations
Map<String, List<IdentificationVariable>> identificationVariables = new HashMap<>();
helper.collectLocalDeclarationIdentificationVariables(identificationVariables);
// Check for duplicate identification variables
for (Map.Entry<String, List<IdentificationVariable>> entry : identificationVariables.entrySet()) {
List<IdentificationVariable> variables = entry.getValue();
// More than one identification variable was used in a declaration
if (variables.size() > 1) {
for (IdentificationVariable variable : variables) {
addProblem(variable, IdentificationVariable_Invalid_Duplicate, variable.getText());
}
}
}
// Now collect the identification variables from the parent queries
identificationVariables.clear();
helper.collectAllDeclarationIdentificationVariables(identificationVariables);
// Check for undeclared identification variables
for (IdentificationVariable identificationVariable : usedIdentificationVariables) {
String variableName = identificationVariable.getText();
if (ExpressionTools.stringIsNotEmpty(variableName) && !identificationVariables.containsKey(variableName.toUpperCase(Locale.ROOT))) {
addProblem(identificationVariable, IdentificationVariable_Invalid_NotDeclared, variableName);
}
}
}
use of org.eclipse.persistence.jpa.jpql.parser.IdentificationVariable in project eclipselink by eclipse-ee4j.
the class JPQLExpressionTest1_0 method testGetExpression_3.
@Test
public void testGetExpression_3() {
String query = "SELECT e FROM Employee e";
JPQLExpression jpqlExpression = JPQLQueryBuilder.buildQuery(query, getGrammar(), true);
Expression expression = jpqlExpression.getExpression(query, 8);
assertNotNull(expression);
assertTrue("The expression was " + expression.getClass().getSimpleName(), expression instanceof IdentificationVariable);
expression = jpqlExpression.getExpression(query, 6);
assertNotNull(expression);
assertTrue("The expression was " + expression.getClass().getSimpleName(), expression instanceof SelectClause);
}
Aggregations