Search in sources :

Example 11 with IdentificationVariable

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);
        }
    }
}
Also used : IdentificationVariable(org.eclipse.persistence.jpa.jpql.parser.IdentificationVariable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap)

Example 12 with IdentificationVariable

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);
}
Also used : IdentificationVariable(org.eclipse.persistence.jpa.jpql.parser.IdentificationVariable) SelectClause(org.eclipse.persistence.jpa.jpql.parser.SelectClause) Expression(org.eclipse.persistence.jpa.jpql.parser.Expression) StateFieldPathExpression(org.eclipse.persistence.jpa.jpql.parser.StateFieldPathExpression) ObjectExpression(org.eclipse.persistence.jpa.jpql.parser.ObjectExpression) LikeExpression(org.eclipse.persistence.jpa.jpql.parser.LikeExpression) JPQLExpression(org.eclipse.persistence.jpa.jpql.parser.JPQLExpression) CollectionExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionExpression) UnknownExpression(org.eclipse.persistence.jpa.jpql.parser.UnknownExpression) JPQLExpression(org.eclipse.persistence.jpa.jpql.parser.JPQLExpression) Test(org.junit.Test)

Aggregations

IdentificationVariable (org.eclipse.persistence.jpa.jpql.parser.IdentificationVariable)12 CollectionExpression (org.eclipse.persistence.jpa.jpql.parser.CollectionExpression)4 ObjectExpression (org.eclipse.persistence.jpa.jpql.parser.ObjectExpression)4 StateFieldPathExpression (org.eclipse.persistence.jpa.jpql.parser.StateFieldPathExpression)4 Expression (org.eclipse.persistence.jpa.jpql.parser.Expression)3 JPQLExpression (org.eclipse.persistence.jpa.jpql.parser.JPQLExpression)3 LikeExpression (org.eclipse.persistence.jpa.jpql.parser.LikeExpression)3 UnknownExpression (org.eclipse.persistence.jpa.jpql.parser.UnknownExpression)3 JPQLQueryDeclaration (org.eclipse.persistence.jpa.jpql.JPQLQueryDeclaration)2 AbsExpression (org.eclipse.persistence.jpa.jpql.parser.AbsExpression)2 AdditionExpression (org.eclipse.persistence.jpa.jpql.parser.AdditionExpression)2 CaseExpression (org.eclipse.persistence.jpa.jpql.parser.CaseExpression)2 CoalesceExpression (org.eclipse.persistence.jpa.jpql.parser.CoalesceExpression)2 CollectionValuedPathExpression (org.eclipse.persistence.jpa.jpql.parser.CollectionValuedPathExpression)2 ConcatExpression (org.eclipse.persistence.jpa.jpql.parser.ConcatExpression)2 ConstructorExpression (org.eclipse.persistence.jpa.jpql.parser.ConstructorExpression)2 DivisionExpression (org.eclipse.persistence.jpa.jpql.parser.DivisionExpression)2 EntryExpression (org.eclipse.persistence.jpa.jpql.parser.EntryExpression)2 FunctionExpression (org.eclipse.persistence.jpa.jpql.parser.FunctionExpression)2 IndexExpression (org.eclipse.persistence.jpa.jpql.parser.IndexExpression)2