use of org.eclipse.persistence.jpa.jpql.parser.StateFieldPathExpression in project eclipselink by eclipse-ee4j.
the class DefaultSemanticValidator method validateUpdateItem.
@Override
@SuppressWarnings("null")
protected boolean validateUpdateItem(UpdateItem expression) {
// First validate the path expression
boolean valid = super.validateUpdateItem(expression);
if (valid) {
// Retrieve the entity to make sure the state field is part of it
AbstractSchemaName abstractSchemaName = findAbstractSchemaName(expression);
String entityName = (abstractSchemaName != null) ? abstractSchemaName.getText() : null;
if (ExpressionTools.stringIsNotEmpty(entityName)) {
Object entity = helper.getEntityNamed(entityName);
// Check the existence of the state field on the entity
if ((entity != null) && expression.hasSpaceAfterStateFieldPathExpression()) {
StateFieldPathExpression pathExpression = getStateFieldPathExpression(expression.getStateFieldPathExpression());
String stateFieldValue = (pathExpression != null) ? pathExpression.toParsedText() : null;
if (ExpressionTools.stringIsNotEmpty(stateFieldValue)) {
// State field without a dot
if (stateFieldValue.indexOf('.') == -1) {
Object mapping = helper.getMappingNamed(entity, stateFieldValue);
if (mapping == null) {
addProblem(pathExpression, UpdateItem_NotResolvable, stateFieldValue);
} else {
validateUpdateItemTypes(expression, helper.getMappingType(mapping));
}
} else {
Object type = helper.getType(pathExpression);
if (!helper.isTypeResolvable(type)) {
addProblem(pathExpression, UpdateItem_NotResolvable, stateFieldValue);
} else {
validateUpdateItemTypes(expression, type);
}
}
}
}
}
}
return valid;
}
use of org.eclipse.persistence.jpa.jpql.parser.StateFieldPathExpression in project eclipselink by eclipse-ee4j.
the class DefaultSemanticValidator method validateNullComparisonExpression.
@Override
protected void validateNullComparisonExpression(NullComparisonExpression expression) {
super.validateNullComparisonExpression(expression);
// Null comparisons over instances of embeddable class types are not supported
StateFieldPathExpression pathExpression = getStateFieldPathExpression(expression.getExpression());
if (pathExpression != null) {
Object type = helper.getType(pathExpression);
if (helper.getEmbeddable(type) != null) {
addProblem(pathExpression, NullComparisonExpression_InvalidType, pathExpression.toParsedText());
}
}
}
use of org.eclipse.persistence.jpa.jpql.parser.StateFieldPathExpression 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.StateFieldPathExpression in project eclipselink by eclipse-ee4j.
the class AbstractSemanticValidator method validateUpdateItem.
/**
* Validates the given {@link UpdateItem} by validating the traversability of the path
* expression. The path expression is valid if it follows one of the following rules:
* <ul>
* <li>The identification variable is omitted if it's not defined in the <b>FROM</b> clause;
* <li>The last path is a state field;
* <li>Only embedded field can be traversed.
* </ul>
*
* @param expression {@link UpdateItem} to validate its path expression
* @return <code>true</code> if the path expression is valid; <code>false</code> otherwise
*/
protected boolean validateUpdateItem(UpdateItem expression) {
boolean valid = true;
if (expression.hasStateFieldPathExpression()) {
// Retrieve the state field path expression
StateFieldPathExpression pathExpression = getStateFieldPathExpression(expression.getStateFieldPathExpression());
if ((pathExpression != null) && (pathExpression.hasIdentificationVariable() || pathExpression.hasVirtualIdentificationVariable())) {
// Start traversing the path expression by first retrieving the managed type
Object managedType = helper.getManagedType(pathExpression.getIdentificationVariable());
if (managedType != null) {
// Continue to traverse the path expression
for (int index = pathExpression.hasVirtualIdentificationVariable() ? 0 : 1, count = pathExpression.pathSize(); index < count; index++) {
// Retrieve the mapping
String path = pathExpression.getPath(index);
Object mapping = helper.getMappingNamed(managedType, path);
// Not resolvable
if (mapping == null) {
addProblem(pathExpression, UpdateItem_NotResolvable, pathExpression.toParsedText());
valid = false;
break;
} else // A collection mapping cannot be traversed or a value cannot be assigned to it
if (helper.isCollectionMapping(mapping)) {
addProblem(pathExpression, UpdateItem_RelationshipPathExpression);
valid = false;
break;
} else // Validate an intermediate path (n + 1, ..., n - 2)
if (index + 1 < count) {
// A relationship mapping cannot be traversed
if (helper.isRelationshipMapping(mapping)) {
addProblem(pathExpression, UpdateItem_RelationshipPathExpression);
valid = false;
break;
} else // A basic mapping cannot be traversed
if (helper.isPropertyMapping(mapping)) {
addProblem(pathExpression, UpdateItem_RelationshipPathExpression);
valid = false;
break;
} else // Retrieve the embeddable mapping's reference managed type
{
managedType = helper.getReferenceManagedType(mapping);
if (managedType == null) {
addProblem(pathExpression, UpdateItem_NotResolvable, pathExpression.toParsedText());
valid = false;
break;
}
}
}
}
} else {
addProblem(pathExpression, UpdateItem_NotResolvable, pathExpression.toParsedText());
valid = false;
}
} else {
addProblem(pathExpression, UpdateItem_NotResolvable, expression.getStateFieldPathExpression().toParsedText());
valid = false;
}
}
return valid;
}
use of org.eclipse.persistence.jpa.jpql.parser.StateFieldPathExpression in project eclipselink by eclipse-ee4j.
the class AbstractSemanticValidator method validateLocateExpression.
/**
* Validates the encapsulated expression of the given <code><b>LOCATE</b></code> expression. The
* test to perform is:
* <ul>
* <li>If the encapsulated expression is a path expression, validation makes sure it is a basic
* mapping, an association field is not allowed.</li>
* <li>If the encapsulated expression is not a path expression, validation will be redirected to
* that expression but the returned status will not be changed.</li>
* </ul>
*
* @param expression The {@link LocateExpression} to validate by validating its encapsulated expression
* @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 validateLocateExpression(LocateExpression expression) {
int result = 0;
// Validate the first expression
if (expression.hasFirstExpression()) {
Expression firstExpression = expression.getFirstExpression();
// Special case for state field path expression, association field is not allowed
StateFieldPathExpression pathExpression = getStateFieldPathExpression(firstExpression);
if (pathExpression != null) {
boolean valid = validateStateFieldPathExpression(pathExpression, PathType.BASIC_FIELD_ONLY);
updateStatus(result, 0, valid);
} else {
firstExpression.accept(this);
}
}
// Validate the second expression
expression.getSecondExpression().accept(this);
// Validate the third expression
expression.getThirdExpression().accept(this);
return result;
}
Aggregations