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);
}
}
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);
}
}
}
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);
}
}
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);
}
}
}
}
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;
}
Aggregations