use of org.eclipse.persistence.jpa.jpql.parser.InExpression in project eclipselink by eclipse-ee4j.
the class AbstractActualJPQLQueryFormatter method visit.
@Override
public void visit(InExpressionStateObject stateObject) {
if (stateObject.isDecorated()) {
toText(stateObject);
} else {
InExpression expression = stateObject.getExpression();
if (stateObject.hasStateObject()) {
stateObject.getStateObject().accept(this);
writer.append(SPACE);
}
// 'NOT'
if (stateObject.hasNot()) {
appendIdentifier((expression != null) ? expression.getActualNotIdentifier() : NOT, NOT);
writer.append(SPACE);
}
// 'IN'
appendIdentifier((expression != null) ? expression.getActualInIdentifier() : IN, IN);
if (!stateObject.isSingleInputParameter()) {
writer.append(LEFT_PARENTHESIS);
} else if (shouldOutput(expression) || expression.hasSpaceAfterIn()) {
writer.append(SPACE);
}
if (stateObject.hasItems()) {
toStringChildren(stateObject, true);
}
if (!stateObject.isSingleInputParameter()) {
writer.append(RIGHT_PARENTHESIS);
}
}
}
use of org.eclipse.persistence.jpa.jpql.parser.InExpression in project eclipselink by eclipse-ee4j.
the class AbstractEclipseLinkSemanticValidator method validateInExpression.
@Override
protected void validateInExpression(InExpression expression) {
super.validateInExpression(expression);
// Make sure the number of items matches if the left expression
// is a nested array and the IN items expression is a subquery
Expression inItems = expression.getInItems();
if (isSubquery(inItems)) {
int nestedArraySize = nestedArraySize(expression.getExpression());
int subquerySelectItemsSize = subquerySelectItemCount(inItems);
if ((nestedArraySize > -1) && (subquerySelectItemsSize != nestedArraySize) || (nestedArraySize == -1) && (subquerySelectItemsSize > 1)) {
addProblem(expression, InExpression_InvalidItemCount);
}
}
}
use of org.eclipse.persistence.jpa.jpql.parser.InExpression in project eclipselink by eclipse-ee4j.
the class AbstractGrammarValidator method visit.
@Override
public void visit(InExpression expression) {
// Missing expression
if (!expression.hasExpression()) {
int startPosition = position(expression);
addProblem(expression, startPosition, InExpression_MissingExpression);
} else {
Expression leftExpression = expression.getExpression();
JPQLQueryBNF queryBNF = getQueryBNF(expression.getExpressionExpressionQueryBNFId());
// First check for nested array support
if (isNestedArray(leftExpression)) {
if (!queryBNF.handlesNestedArray()) {
int startPosition = position(expression);
int endPosition = startPosition + length(leftExpression);
addProblem(expression, startPosition, endPosition, InExpression_InvalidExpression);
} else {
leftExpression.accept(this);
}
} else // Validate the expression
if (!isValid(leftExpression, queryBNF) || isDateTimeConstant(leftExpression)) {
int startPosition = position(expression);
int endPosition = startPosition + length(leftExpression);
addProblem(expression, startPosition, endPosition, InExpression_InvalidExpression);
} else {
leftExpression.accept(this);
}
}
// Check for "IN :input_parameter" defined in JPA 2.0
boolean singleInputParameter = isNewerThanOrEqual(JPAVersion.VERSION_2_0) && expression.isSingleInputParameter();
// Missing '('
if (!expression.hasLeftParenthesis() && !singleInputParameter) {
int startPosition = position(expression) + length(expression.getExpression()) + (expression.hasExpression() ? 1 : 0) + (expression.hasNot() ? 4 : /* NOT + whitespace */
0) + 2;
addProblem(expression, startPosition, InExpression_MissingLeftParenthesis);
} else // defines the set of values for the IN expression.
if (!expression.hasInItems()) {
int startPosition = position(expression) + length(expression.getExpression()) + (expression.hasExpression() ? 1 : 0) + (expression.hasNot() ? 4 : /* NOT + whitespace */
0) + 2 + /* IN */
(expression.hasSpaceAfterIn() ? 1 : 0) + (expression.hasLeftParenthesis() ? 1 : 0);
addProblem(expression, startPosition, InExpression_MissingInItems);
} else // Make sure the IN items are separated by commas
if (!singleInputParameter) {
Expression inItems = expression.getInItems();
CollectionExpression collectionExpression = getCollectionExpression(inItems);
// Validate the collection of items
if (collectionExpression != null) {
validateCollectionSeparatedByComma(inItems, InExpression_ItemEndsWithComma, InExpression_ItemIsMissingComma);
// Validate each item
JPQLQueryBNF queryBNF = getQueryBNF(expression.getExpressionItemQueryBNFId());
int index = 0;
for (Expression child : collectionExpression.children()) {
index++;
// First check for nested array support
if (isNestedArray(child)) {
if (!queryBNF.handlesNestedArray()) {
addProblem(child, InExpression_ItemInvalidExpression, String.valueOf(index));
} else {
child.accept(this);
}
} else // Invalid item
if (!isValid(child, queryBNF)) {
addProblem(child, InExpression_ItemInvalidExpression, String.valueOf(index));
} else // Validate the item
{
child.accept(this);
}
}
} else // The single item is invalid
if (!isValid(inItems, expression.getExpressionItemQueryBNFId())) {
addProblem(inItems, InExpression_ItemInvalidExpression);
} else // Validate the single item
{
inItems.accept(this);
}
}
// Missing ')'
if (!singleInputParameter && expression.hasInItems() && !expression.hasRightParenthesis()) {
int startPosition = position(expression) + length(expression.getExpression()) + (expression.hasExpression() ? 1 : 0) + (expression.hasNot() ? 4 : /* NOT + whitespace */
0) + 2 + /* IN */
(expression.hasSpaceAfterIn() ? 1 : 0) + (expression.hasLeftParenthesis() ? 1 : 0) + length(expression.getInItems());
addProblem(expression, startPosition, InExpression_MissingRightParenthesis);
}
}
use of org.eclipse.persistence.jpa.jpql.parser.InExpression in project eclipselink by eclipse-ee4j.
the class AbstractSemanticValidator method validateInExpression.
/**
* Validates the given {@link InExpression}. The test to perform is:
* <ul>
* <li>If the expression is a path expression, validation makes sure it is an association mapping,
* a basic field is not allowed.</li>
* </ul>
*
* @param expression The {@link InExpression} to validate
*/
protected void validateInExpression(InExpression expression) {
// Validate the left expression
if (expression.hasExpression()) {
Expression stringExpression = expression.getExpression();
// Special case for state field path expression
StateFieldPathExpression pathExpression = getStateFieldPathExpression(stringExpression);
if (pathExpression != null) {
validateStateFieldPathExpression(pathExpression, validPathExpressionTypeForInExpression());
} else {
stringExpression.accept(this);
}
}
// Validate the items
expression.getInItems().accept(getInItemsVisitor());
}
Aggregations