use of org.eclipse.persistence.jpa.jpql.parser.CollectionValuedPathExpression in project eclipselink by eclipse-ee4j.
the class AbstractSemanticValidator method validateCollectionValuedPathExpression.
/**
* Validates the given {@link Expression} and makes sure it's a valid collection value path expression.
*
* @param expression The {@link Expression} to validate
* @param collectionTypeOnly <code>true</code> to make sure the path expression resolves to a
* collection mapping only; <code>false</code> if it can simply resolves to a relationship mapping
*/
protected boolean validateCollectionValuedPathExpression(Expression expression, boolean collectionTypeOnly) {
boolean valid = true;
// The path expression resolves to a collection-valued path expression
CollectionValuedPathExpression collectionValuedPathExpression = getCollectionValuedPathExpression(expression);
if (collectionValuedPathExpression != null && collectionValuedPathExpression.hasIdentificationVariable() && !collectionValuedPathExpression.endsWithDot()) {
// A collection_valued_field is designated by the name of an association field in a
// one-to-many or a many-to-many relationship or by the name of an element collection field
Object mapping = helper.resolveMapping(expression);
Object type = helper.getMappingType(mapping);
// Does not resolve to a valid path
if (!helper.isTypeResolvable(type) || (mapping == null)) {
int startPosition = position(expression);
int endPosition = startPosition + length(expression);
addProblem(expression, startPosition, endPosition, CollectionValuedPathExpression_NotResolvable, expression.toParsedText());
valid = false;
} else if (collectionTypeOnly && !helper.isCollectionMapping(mapping) || !collectionTypeOnly && !helper.isRelationshipMapping(mapping)) {
int startPosition = position(expression);
int endPosition = startPosition + length(expression);
addProblem(expression, startPosition, endPosition, CollectionValuedPathExpression_NotCollectionType, expression.toParsedText());
valid = false;
}
}
return valid;
}
use of org.eclipse.persistence.jpa.jpql.parser.CollectionValuedPathExpression in project eclipselink by eclipse-ee4j.
the class ExpressionBuilderVisitor method visit.
@Override
public void visit(EmptyCollectionComparisonExpression expression) {
CollectionValuedPathExpression collectionPath = (CollectionValuedPathExpression) expression.getExpression();
int lastPathIndex = collectionPath.pathSize() - 1;
String name = collectionPath.getPath(lastPathIndex);
// Create the expression for the collection-valued path expression (except the last path)
visitPathExpression(collectionPath, false, lastPathIndex);
// Create the IS EMPTY expression
if (expression.hasNot()) {
queryExpression = queryExpression.notEmpty(name);
} else {
queryExpression = queryExpression.isEmpty(name);
}
// Set the expression type
type[0] = Boolean.class;
}
use of org.eclipse.persistence.jpa.jpql.parser.CollectionValuedPathExpression in project eclipselink by eclipse-ee4j.
the class ExpressionBuilderVisitor method visit.
@Override
public void visit(SizeExpression expression) {
CollectionValuedPathExpression pathExpression = (CollectionValuedPathExpression) expression.getExpression();
int lastIndex = pathExpression.pathSize() - 1;
// Create the right chain of expressions
visitPathExpression(pathExpression, false, lastIndex - 1);
// Now create the SIZE expression
String name = pathExpression.getPath(lastIndex);
queryExpression = queryExpression.size(name);
// Set the expression type
type[0] = Integer.class;
}
use of org.eclipse.persistence.jpa.jpql.parser.CollectionValuedPathExpression 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.CollectionValuedPathExpression in project eclipselink by eclipse-ee4j.
the class ReportItemBuilder method visit.
@Override
public void visit(SizeExpression expression) {
// Add the attribute
Expression queryExpression = queryContext.buildExpression(expression.getExpression());
addAttribute("size", queryExpression.count(), Integer.class);
// Now add the GROUP BY expression
CollectionValuedPathExpression pathExpression = (CollectionValuedPathExpression) expression.getExpression();
queryExpression = queryContext.buildGroupByExpression(pathExpression);
query.addGrouping(queryExpression);
}
Aggregations