Search in sources :

Example 1 with Declaration

use of org.eclipse.persistence.jpa.jpql.tools.resolver.Declaration in project eclipselink by eclipse-ee4j.

the class EclipseLinkContentAssistVisitor method getTableName.

protected String getTableName(String variableName) {
    Declaration declaration = queryContext.getDeclaration(variableName);
    Expression baseExpression = (declaration != null) ? declaration.getBaseExpression() : null;
    if ((baseExpression != null) && isTableExpression(baseExpression)) {
        return queryContext.literal(baseExpression, LiteralType.STRING_LITERAL);
    }
    return null;
}
Also used : CastExpression(org.eclipse.persistence.jpa.jpql.parser.CastExpression) Expression(org.eclipse.persistence.jpa.jpql.parser.Expression) TableExpression(org.eclipse.persistence.jpa.jpql.parser.TableExpression) AbstractPathExpression(org.eclipse.persistence.jpa.jpql.parser.AbstractPathExpression) ExtractExpression(org.eclipse.persistence.jpa.jpql.parser.ExtractExpression) CollectionExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionExpression) RegexpExpression(org.eclipse.persistence.jpa.jpql.parser.RegexpExpression) TableVariableDeclaration(org.eclipse.persistence.jpa.jpql.parser.TableVariableDeclaration) Declaration(org.eclipse.persistence.jpa.jpql.tools.resolver.Declaration)

Example 2 with Declaration

use of org.eclipse.persistence.jpa.jpql.tools.resolver.Declaration in project eclipselink by eclipse-ee4j.

the class GenericSemanticValidatorHelper method collectLocalDeclarationIdentificationVariables.

protected void collectLocalDeclarationIdentificationVariables(JPQLQueryContext queryContext, Map<String, List<IdentificationVariable>> identificationVariables) {
    DeclarationResolver declarationResolver = queryContext.getDeclarationResolverImp();
    for (Declaration declaration : declarationResolver.getDeclarations()) {
        // Register the identification variable from the base expression
        IdentificationVariable identificationVariable = declaration.getIdentificationVariable();
        addIdentificationVariable(identificationVariable, identificationVariables);
        // Register the identification variable from the JOIN expressions
        for (Join join : declaration.getJoins()) {
            IdentificationVariable joinIdentificationVariable = getIdentificationVariable(join.getIdentificationVariable());
            addIdentificationVariable(joinIdentificationVariable, identificationVariables);
        }
    }
    if (queryContext.getParent() == null) {
        for (IdentificationVariable identificationVariable : declarationResolver.getResultVariablesMap().keySet()) {
            addIdentificationVariable(identificationVariable, identificationVariables);
        }
    }
}
Also used : IdentificationVariable(org.eclipse.persistence.jpa.jpql.parser.IdentificationVariable) DeclarationResolver(org.eclipse.persistence.jpa.jpql.tools.resolver.DeclarationResolver) Join(org.eclipse.persistence.jpa.jpql.parser.Join) JPQLQueryDeclaration(org.eclipse.persistence.jpa.jpql.JPQLQueryDeclaration) ITypeDeclaration(org.eclipse.persistence.jpa.jpql.tools.spi.ITypeDeclaration) Declaration(org.eclipse.persistence.jpa.jpql.tools.resolver.Declaration)

Example 3 with Declaration

use of org.eclipse.persistence.jpa.jpql.tools.resolver.Declaration in project eclipselink by eclipse-ee4j.

the class JPQLQueryContext method convertUnqualifiedDeclaration.

/**
 * Converts the given {@link Declaration} from being set as a range variable declaration to
 * a path expression declaration.
 * <p>
 * In this query "<code>UPDATE Employee SET firstName = 'MODIFIED' WHERE (SELECT COUNT(m) FROM
 * managedEmployees m) {@literal >} 0</code>" <em>managedEmployees</em> is an unqualified
 * collection-valued path expression (<code>employee.managedEmployees</code>).
 *
 * @param declaration The {@link Declaration} that was parsed to range over an abstract schema
 * name but is actually ranging over a path expression
 */
public void convertUnqualifiedDeclaration(Declaration declaration) {
    if (parent != null) {
        // Retrieve the range identification variable from the parent declaration
        Declaration parentDeclaration = parent.getDeclarationResolverImp().getDeclarations().get(0);
        String outerVariableName = parentDeclaration.getVariableName();
        // Qualify the range expression to be fully qualified
        getDeclarationResolverImp().convertUnqualifiedDeclaration(declaration, outerVariableName);
    }
}
Also used : ITypeDeclaration(org.eclipse.persistence.jpa.jpql.tools.spi.ITypeDeclaration) Declaration(org.eclipse.persistence.jpa.jpql.tools.resolver.Declaration)

Example 4 with Declaration

use of org.eclipse.persistence.jpa.jpql.tools.resolver.Declaration in project eclipselink by eclipse-ee4j.

the class DeclarationTest method testDeclarations.

protected final void testDeclarations(JPQLQueryContext queryContext, Map<Expression, DeclarationTester[]> declarationTesters) {
    for (Map.Entry<Expression, DeclarationTester[]> entry : declarationTesters.entrySet()) {
        Expression expression = entry.getKey();
        DeclarationTester[] testers = entry.getValue();
        if (expression.getRoot() != expression) {
            queryContext.newSubqueryContext(expression);
        }
        // Retrieve the list of Declarations
        List<Declaration> declarations = queryContext.getDeclarations();
        assertNotNull(declarations);
        assertEquals(testers.length, declarations.size());
        // Test each one of them
        for (int index = testers.length; --index >= 0; ) {
            Declaration declaration = declarations.get(index);
            DeclarationTester tester = testers[index];
            tester.test(declaration);
        }
        if (expression.getRoot() != expression) {
            queryContext.disposeSubqueryContext();
        }
    }
}
Also used : Expression(org.eclipse.persistence.jpa.jpql.parser.Expression) Declaration(org.eclipse.persistence.jpa.jpql.tools.resolver.Declaration) HashMap(java.util.HashMap) Map(java.util.Map) RangeVariableDeclarationTester(org.eclipse.persistence.jpa.tests.jpql.parser.JPQLParserTest.RangeVariableDeclarationTester)

Example 5 with Declaration

use of org.eclipse.persistence.jpa.jpql.tools.resolver.Declaration in project eclipselink by eclipse-ee4j.

the class DeclarationTest method testDeclarations.

protected final void testDeclarations(String jpqlQuery, boolean tolerant, DeclarationTester... declarationTesters) {
    // Build the JPQLQueryContext, which will parse the JPQL query and create the list of Declarations
    JPQLQueryContext queryContext = buildQueryContext();
    queryContext.setTolerant(tolerant);
    queryContext.setQuery(buildQuery(jpqlQuery));
    // Retrieve the list of Declarations
    List<Declaration> declarations = queryContext.getDeclarations();
    assertNotNull(declarations);
    assertEquals(declarationTesters.length, declarations.size());
    // Test each one of them
    for (int index = declarationTesters.length; --index >= 0; ) {
        Declaration declaration = declarations.get(index);
        DeclarationTester tester = declarationTesters[index];
        tester.test(declaration);
    }
}
Also used : JPQLQueryContext(org.eclipse.persistence.jpa.jpql.tools.JPQLQueryContext) Declaration(org.eclipse.persistence.jpa.jpql.tools.resolver.Declaration) RangeVariableDeclarationTester(org.eclipse.persistence.jpa.tests.jpql.parser.JPQLParserTest.RangeVariableDeclarationTester)

Aggregations

Declaration (org.eclipse.persistence.jpa.jpql.tools.resolver.Declaration)5 Expression (org.eclipse.persistence.jpa.jpql.parser.Expression)2 ITypeDeclaration (org.eclipse.persistence.jpa.jpql.tools.spi.ITypeDeclaration)2 RangeVariableDeclarationTester (org.eclipse.persistence.jpa.tests.jpql.parser.JPQLParserTest.RangeVariableDeclarationTester)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 JPQLQueryDeclaration (org.eclipse.persistence.jpa.jpql.JPQLQueryDeclaration)1 AbstractPathExpression (org.eclipse.persistence.jpa.jpql.parser.AbstractPathExpression)1 CastExpression (org.eclipse.persistence.jpa.jpql.parser.CastExpression)1 CollectionExpression (org.eclipse.persistence.jpa.jpql.parser.CollectionExpression)1 ExtractExpression (org.eclipse.persistence.jpa.jpql.parser.ExtractExpression)1 IdentificationVariable (org.eclipse.persistence.jpa.jpql.parser.IdentificationVariable)1 Join (org.eclipse.persistence.jpa.jpql.parser.Join)1 RegexpExpression (org.eclipse.persistence.jpa.jpql.parser.RegexpExpression)1 TableExpression (org.eclipse.persistence.jpa.jpql.parser.TableExpression)1 TableVariableDeclaration (org.eclipse.persistence.jpa.jpql.parser.TableVariableDeclaration)1 JPQLQueryContext (org.eclipse.persistence.jpa.jpql.tools.JPQLQueryContext)1 DeclarationResolver (org.eclipse.persistence.jpa.jpql.tools.resolver.DeclarationResolver)1