Search in sources :

Example 1 with Join

use of org.eclipse.persistence.jpa.jpql.parser.Join in project eclipselink by eclipse-ee4j.

the class AbstractActualJPQLQueryFormatter method visit.

@Override
public void visit(JoinStateObject stateObject) {
    if (stateObject.isDecorated()) {
        toText(stateObject);
    } else {
        Join expression = stateObject.getExpression();
        // JOIN
        appendIdentifier((expression != null) ? expression.getActualIdentifier() : stateObject.getJoinType(), stateObject.getJoinType());
        if (shouldOutput(expression) || expression.hasSpaceAfterJoin()) {
            writer.append(SPACE);
        }
        // Join association path
        stateObject.getJoinAssociationPathStateObject().accept(this);
        // Check first if the JOIN FETCH is allowed to have an identification variable
        if (stateObject.hasFetch()) {
            if (expression.hasAs()) {
                writer.append(SPACE);
            }
        } else // JOIN always needs a whitespace
        {
            if (shouldOutput(expression) || expression.hasSpaceAfterJoinAssociation()) {
                writer.append(SPACE);
            }
        }
        // AS
        if (stateObject.hasAs()) {
            appendIdentifier((expression != null) ? expression.getActualAsIdentifier() : AS, AS);
            if (shouldOutput(expression) || expression.hasSpaceAfterAs()) {
                writer.append(SPACE);
            }
        }
        // Identification variable
        stateObject.getIdentificationVariableStateObject().accept(this);
    }
}
Also used : Join(org.eclipse.persistence.jpa.jpql.parser.Join)

Example 2 with Join

use of org.eclipse.persistence.jpa.jpql.parser.Join 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 Join

use of org.eclipse.persistence.jpa.jpql.parser.Join in project eclipselink by eclipse-ee4j.

the class ReportItemBuilder method visit.

@Override
public void visit(IdentificationVariable expression) {
    String variableName = expression.getVariableName();
    // Retrieve the FETCH JOIN expressions using the identification variable
    List<org.eclipse.persistence.expressions.Expression> joinFetchExpressions = null;
    // Retrieve the join fetches that were defined in the same identification variable
    // declaration, if the identification variable is mapped to a join, then there will
    // not be any join fetch associated with it
    Collection<Join> joinFetches = queryContext.getJoinFetches(variableName);
    if (joinFetches != null) {
        for (Join joinFetch : joinFetches) {
            // Retrieve the join association path expression's identification variable
            String joinFetchVariableName = queryContext.literal(joinFetch, PATH_EXPRESSION_IDENTIFICATION_VARIABLE);
            if (variableName.equals(joinFetchVariableName)) {
                if (joinFetchExpressions == null) {
                    joinFetchExpressions = new ArrayList<>();
                }
                joinFetchExpressions.add(queryContext.buildExpression(joinFetch, type));
            }
        }
    }
    Expression queryExpression = queryContext.buildExpression(expression, type);
    // Add the attribute without any JOIN FETCH
    if (joinFetchExpressions == null) {
        query.addAttribute(expression.getText(), queryExpression);
    } else // Add the attribute with the JOIN FETCH expressions
    {
        query.addItem(expression.getText(), queryExpression, joinFetchExpressions);
    }
}
Also used : TrimExpression(org.eclipse.persistence.jpa.jpql.parser.TrimExpression) AbsExpression(org.eclipse.persistence.jpa.jpql.parser.AbsExpression) ValueExpression(org.eclipse.persistence.jpa.jpql.parser.ValueExpression) CoalesceExpression(org.eclipse.persistence.jpa.jpql.parser.CoalesceExpression) ConcatExpression(org.eclipse.persistence.jpa.jpql.parser.ConcatExpression) SubstringExpression(org.eclipse.persistence.jpa.jpql.parser.SubstringExpression) SizeExpression(org.eclipse.persistence.jpa.jpql.parser.SizeExpression) CastExpression(org.eclipse.persistence.jpa.jpql.parser.CastExpression) SqrtExpression(org.eclipse.persistence.jpa.jpql.parser.SqrtExpression) SubExpression(org.eclipse.persistence.jpa.jpql.parser.SubExpression) FunctionExpression(org.eclipse.persistence.jpa.jpql.parser.FunctionExpression) ExtractExpression(org.eclipse.persistence.jpa.jpql.parser.ExtractExpression) ConstructorExpression(org.eclipse.persistence.jpa.jpql.parser.ConstructorExpression) NullIfExpression(org.eclipse.persistence.jpa.jpql.parser.NullIfExpression) IndexExpression(org.eclipse.persistence.jpa.jpql.parser.IndexExpression) CollectionValuedPathExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionValuedPathExpression) LocateExpression(org.eclipse.persistence.jpa.jpql.parser.LocateExpression) StateFieldPathExpression(org.eclipse.persistence.jpa.jpql.parser.StateFieldPathExpression) UpperExpression(org.eclipse.persistence.jpa.jpql.parser.UpperExpression) AdditionExpression(org.eclipse.persistence.jpa.jpql.parser.AdditionExpression) ObjectExpression(org.eclipse.persistence.jpa.jpql.parser.ObjectExpression) CollectionExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionExpression) KeyExpression(org.eclipse.persistence.jpa.jpql.parser.KeyExpression) LowerExpression(org.eclipse.persistence.jpa.jpql.parser.LowerExpression) TreatExpression(org.eclipse.persistence.jpa.jpql.parser.TreatExpression) ModExpression(org.eclipse.persistence.jpa.jpql.parser.ModExpression) TypeExpression(org.eclipse.persistence.jpa.jpql.parser.TypeExpression) Expression(org.eclipse.persistence.expressions.Expression) SubtractionExpression(org.eclipse.persistence.jpa.jpql.parser.SubtractionExpression) EntryExpression(org.eclipse.persistence.jpa.jpql.parser.EntryExpression) CaseExpression(org.eclipse.persistence.jpa.jpql.parser.CaseExpression) LengthExpression(org.eclipse.persistence.jpa.jpql.parser.LengthExpression) MultiplicationExpression(org.eclipse.persistence.jpa.jpql.parser.MultiplicationExpression) DivisionExpression(org.eclipse.persistence.jpa.jpql.parser.DivisionExpression) KeywordExpression(org.eclipse.persistence.jpa.jpql.parser.KeywordExpression) Join(org.eclipse.persistence.jpa.jpql.parser.Join)

Example 4 with Join

use of org.eclipse.persistence.jpa.jpql.parser.Join in project eclipselink by eclipse-ee4j.

the class AbstractObjectLevelReadQueryVisitor method visitIdentificationVariable.

void visitIdentificationVariable(IdentificationVariable expression) {
    String variableName = expression.getVariableName();
    // Retrieve the join fetches that were defined in the same identification variable
    // declaration, if the identification variable is mapped to a join, then there will
    // not be any join fetch associated with it
    Collection<Join> joinFetches = queryContext.getJoinFetches(variableName);
    if (joinFetches != null) {
        for (Join joinFetch : joinFetches) {
            // Retrieve the join association path expression's identification variable
            String joinFetchVariableName = queryContext.literal(joinFetch, LiteralType.PATH_EXPRESSION_IDENTIFICATION_VARIABLE);
            // Example: FROM Employee e JOIN FETCH e.employees
            if (variableName.equals(joinFetchVariableName)) {
                org.eclipse.persistence.expressions.Expression queryExpression = null;
                if (joinFetch.hasIdentificationVariable()) {
                    String identificationVariable = queryContext.literal(joinFetch, LiteralType.IDENTIFICATION_VARIABLE);
                    queryExpression = queryContext.findQueryExpression(identificationVariable);
                // Join expression has identification variable and was processed in the From clause
                }
                if (queryExpression == null) {
                    queryExpression = queryContext.buildExpression(joinFetch);
                }
                query.addJoinedAttribute(queryExpression);
            }
        }
    }
}
Also used : Expression(org.eclipse.persistence.expressions.Expression) Join(org.eclipse.persistence.jpa.jpql.parser.Join)

Example 5 with Join

use of org.eclipse.persistence.jpa.jpql.parser.Join in project eclipselink by eclipse-ee4j.

the class AbstractSemanticValidator method isIdentificationVariableDeclaredAfter.

protected boolean isIdentificationVariableDeclaredAfter(String variableName, int variableNameIndex, int joinIndex, List<? extends JPQLQueryDeclaration> declarations) {
    for (int index = variableNameIndex, declarationCount = declarations.size(); index < declarationCount; index++) {
        JPQLQueryDeclaration declaration = declarations.get(index);
        // Ignore the current declaration since it's the same identification variable
        if (index != variableNameIndex) {
            // Check to make sure the Declaration is a known type
            if (declaration.getType() != Type.UNKNOWN) {
                String nextVariableName = declaration.getVariableName();
                if (variableName.equalsIgnoreCase(nextVariableName)) {
                    return true;
                }
            } else // Some implementation could have a Declaration that is not a range, derived or a
            // collection Declaration, it could represent a JOIN expression
            {
                return false;
            }
        }
        // Scan the JOIN expressions
        if (declaration.hasJoins()) {
            List<Join> joins = declaration.getJoins();
            int endIndex = (index == variableNameIndex) ? joinIndex : joins.size();
            for (int subIndex = joinIndex; subIndex < endIndex; subIndex++) {
                Join join = joins.get(subIndex);
                String joinVariableName = literal(join.getIdentificationVariable(), LiteralType.IDENTIFICATION_VARIABLE);
                if (variableName.equalsIgnoreCase(joinVariableName)) {
                    return true;
                }
            }
        }
    }
    // it was defined before or it was not defined (which is validated by another rule)
    return false;
}
Also used : Join(org.eclipse.persistence.jpa.jpql.parser.Join)

Aggregations

Join (org.eclipse.persistence.jpa.jpql.parser.Join)6 Expression (org.eclipse.persistence.expressions.Expression)2 JPQLQueryDeclaration (org.eclipse.persistence.jpa.jpql.JPQLQueryDeclaration)1 AbsExpression (org.eclipse.persistence.jpa.jpql.parser.AbsExpression)1 AdditionExpression (org.eclipse.persistence.jpa.jpql.parser.AdditionExpression)1 CaseExpression (org.eclipse.persistence.jpa.jpql.parser.CaseExpression)1 CastExpression (org.eclipse.persistence.jpa.jpql.parser.CastExpression)1 CoalesceExpression (org.eclipse.persistence.jpa.jpql.parser.CoalesceExpression)1 CollectionExpression (org.eclipse.persistence.jpa.jpql.parser.CollectionExpression)1 CollectionValuedPathExpression (org.eclipse.persistence.jpa.jpql.parser.CollectionValuedPathExpression)1 ConcatExpression (org.eclipse.persistence.jpa.jpql.parser.ConcatExpression)1 ConstructorExpression (org.eclipse.persistence.jpa.jpql.parser.ConstructorExpression)1 DivisionExpression (org.eclipse.persistence.jpa.jpql.parser.DivisionExpression)1 EntryExpression (org.eclipse.persistence.jpa.jpql.parser.EntryExpression)1 ExtractExpression (org.eclipse.persistence.jpa.jpql.parser.ExtractExpression)1 FunctionExpression (org.eclipse.persistence.jpa.jpql.parser.FunctionExpression)1 IdentificationVariable (org.eclipse.persistence.jpa.jpql.parser.IdentificationVariable)1 IndexExpression (org.eclipse.persistence.jpa.jpql.parser.IndexExpression)1 KeyExpression (org.eclipse.persistence.jpa.jpql.parser.KeyExpression)1 KeywordExpression (org.eclipse.persistence.jpa.jpql.parser.KeywordExpression)1