use of org.eclipse.persistence.jpa.jpql.parser.CollectionMemberExpression in project eclipselink by eclipse-ee4j.
the class AbstractActualJPQLQueryFormatter method visit.
@Override
public void visit(CollectionMemberExpressionStateObject stateObject) {
if (stateObject.isDecorated()) {
toText(stateObject);
} else {
CollectionMemberExpression expression = stateObject.getExpression();
// Entity or value expression
if (stateObject.hasEntityStateObject()) {
stateObject.getEntityStateObject().accept(this);
writer.append(SPACE);
}
// 'NOT'
if (stateObject.hasNot()) {
appendIdentifier((expression != null) ? expression.getActualNotIdentifier() : NOT, NOT);
writer.append(SPACE);
}
// 'MEMBER'
appendIdentifier((expression != null) ? expression.getActualMemberIdentifier() : MEMBER, MEMBER);
if (shouldOutput(expression) || expression.hasSpaceAfterMember()) {
writer.append(SPACE);
}
// 'OF'
if (stateObject.hasOf()) {
appendIdentifier((expression != null) ? expression.getActualOfIdentifier() : OF, OF);
if (shouldOutput(expression) || expression.hasSpaceAfterOf()) {
writer.append(SPACE);
}
}
// Collection-valued path expression
stateObject.getCollectionValuedPath().accept(this);
}
}
use of org.eclipse.persistence.jpa.jpql.parser.CollectionMemberExpression in project eclipselink by eclipse-ee4j.
the class AbstractSemanticValidator method validateCollectionMemberExpression.
/**
* Validates the given {@link CollectionMemberExpression}. Only the collection-valued path
* expression is validated.
*
* @param expression The {@link CollectionMemberExpression} to validate
* @return A number indicating the validation result. {@link #isValid(int, int)} can be used to
* determine the validation status of an expression based on its position
*/
protected int validateCollectionMemberExpression(CollectionMemberExpression expression) {
int result = 0;
// Validate the entity expression
if (expression.hasEntityExpression()) {
Expression entityExpression = expression.getEntityExpression();
// Special case for state field path expression, association field is allowed
StateFieldPathExpression pathExpression = getStateFieldPathExpression(entityExpression);
if (pathExpression != null) {
boolean valid = validateStateFieldPathExpression(pathExpression, PathType.ASSOCIATION_FIELD_ONLY);
updateStatus(result, 0, valid);
} else {
entityExpression.accept(this);
}
}
// Validate the collection-valued path expression
boolean valid = validateCollectionValuedPathExpression(expression.getCollectionValuedPathExpression(), true);
updateStatus(result, 1, valid);
return result;
}
use of org.eclipse.persistence.jpa.jpql.parser.CollectionMemberExpression in project eclipselink by eclipse-ee4j.
the class ExpressionBuilderVisitor method visit.
@Override
public void visit(CollectionMemberExpression expression) {
// Create the expression for the entity expression
expression.getEntityExpression().accept(this);
Expression entityExpression = queryExpression;
if (expression.hasNot()) {
CollectionValuedPathExpression pathExpression = (CollectionValuedPathExpression) expression.getCollectionValuedPathExpression();
// Retrieve the ExpressionBuilder from the collection-valued path expression's
// identification variable and the variable name
pathExpression.getIdentificationVariable().accept(this);
Expression parentExpression = queryExpression;
// Now create the actual expression
Expression newBuilder = new ExpressionBuilder();
Expression collectionBase = newBuilder;
for (int i = 1; i < pathExpression.pathSize() - 1; i++) {
// nested paths must be single valued.
collectionBase = collectionBase.get(pathExpression.getPath(i));
}
String lastPath = pathExpression.getPath(pathExpression.pathSize() - 1);
// The following code is copied from Expression.noneOf and altered a bit
Expression criteria = newBuilder.equal(parentExpression).and(collectionBase.anyOf(lastPath).equal(entityExpression));
ReportQuery subQuery = new ReportQuery();
subQuery.setShouldRetrieveFirstPrimaryKey(true);
subQuery.setSelectionCriteria(criteria);
// subQuery has the same reference class as parentExpression (which is an ExpressionBuilder).
subQuery.setReferenceClass(((ExpressionBuilder) parentExpression).getQueryClass());
queryExpression = parentExpression.notExists(subQuery);
} else {
// Create the expression for the collection-valued path expression
expression.getCollectionValuedPathExpression().accept(this);
// Create the MEMBER OF expression
queryExpression = queryExpression.equal(entityExpression);
}
}
use of org.eclipse.persistence.jpa.jpql.parser.CollectionMemberExpression in project eclipselink by eclipse-ee4j.
the class AbstractGrammarValidator method visit.
@Override
public void visit(CollectionMemberExpression expression) {
// Missing entity expression
if (!expression.hasEntityExpression()) {
int startPosition = position(expression);
addProblem(expression, startPosition, CollectionMemberExpression_MissingEntityExpression);
}
// Missing collection valued path expression
if (!expression.hasCollectionValuedPathExpression()) {
int startPosition = position(expression) + length(expression.getEntityExpression()) + (expression.hasEntityExpression() ? 1 : 0) + (expression.hasNot() ? 4 : /* NOT + whitespace */
0) + 6 + /* MEMBER */
(expression.hasSpaceAfterMember() ? 1 : 0) + (expression.hasOf() ? 2 : 0) + (expression.hasSpaceAfterOf() ? 1 : 0);
addProblem(expression, startPosition, CollectionMemberExpression_MissingCollectionValuedPathExpression);
} else {
Expression pathExpression = expression.getCollectionValuedPathExpression();
// The expression is not a path expression
if (!isValid(pathExpression, CollectionValuedPathExpressionBNF.ID)) {
int startPosition = position(expression) + length(expression.getEntityExpression()) + (expression.hasEntityExpression() ? 1 : 0) + (expression.hasNot() ? 4 : /* NOT + whitespace */
0) + 6 + /* MEMBER */
(expression.hasSpaceAfterMember() ? 1 : 0) + (expression.hasOf() ? 2 : 0) + (expression.hasSpaceAfterOf() ? 1 : 0);
int endPosition = startPosition + length(pathExpression);
addProblem(expression, startPosition, endPosition, CollectionValuedPathExpression_NotCollectionType, expression.toParsedText());
}
}
super.visit(expression);
}
use of org.eclipse.persistence.jpa.jpql.parser.CollectionMemberExpression in project eclipselink by eclipse-ee4j.
the class DefaultSemanticValidator method validateCollectionMemberExpression.
@Override
protected int validateCollectionMemberExpression(CollectionMemberExpression expression) {
int result = super.validateCollectionMemberExpression(expression);
if (isValid(result, 0) && expression.hasEntityExpression()) {
Expression entityExpression = expression.getEntityExpression();
// Check for embeddable type
Object type = helper.getType(entityExpression);
if (helper.getEmbeddable(type) != null) {
addProblem(entityExpression, CollectionMemberExpression_Embeddable);
updateStatus(result, 0, false);
}
}
return result;
}
Aggregations