use of org.eclipse.persistence.jpa.jpql.parser.ConcatExpression in project eclipselink by eclipse-ee4j.
the class AbstractSemanticValidator method validateComparisonExpression.
/**
* Validates the left and right expressions of the given {@link ComparisonExpression}. The tests
* to perform are:
* <ul>
* <li>If the comparison operator is either '=' or {@literal '<>'}. The expressions can only be
* <ul>
* <li>Two identification variables;</li>
* <li>Two path expressions resolving to an association field;</li>
* <li>One can be a path expression resolving to a basic field and the other one has to
* resolve to a basic value.</li>
* </ul>
* </li>
* <li>If the comparison operator is either {@literal '<', '<=', '>=', '>'}. The expressions cannot be
* <ul>
* <li>Two identification variables;</li>
* <li>Two path expressions resolving to an association field;</li>
* </ul>
* </li>
* </ul>
*
* @param expression The {@link ConcatExpression} to validate by validating its
* left and right expressions
* @return The status of the comparison between the left and right expression: <code>true</code>
* if the two expressions pass the rules defined by this method; <code>false</code> otherwise
*/
protected boolean validateComparisonExpression(ComparisonExpression expression) {
Expression leftExpression = expression.getLeftExpression();
Expression rightExpression = expression.getRightExpression();
boolean valid = true;
// First determine what is being compared and validate them as well
ComparisonExpressionVisitor validator = getComparisonExpressionVisitor();
try {
// Visit the left expression and gather its information
validator.validatingLeftExpression = true;
leftExpression.accept(validator);
// Visit the right expression and gather its information
validator.validatingLeftExpression = false;
rightExpression.accept(validator);
// '<', '<=', '>=', '>'
if (isOrderComparison(expression)) {
// The left expression cannot be an identification variable
if (validator.leftIdentificationVariable && validator.leftIdentificationVariableValid) {
IdentificationVariable variable = (IdentificationVariable) leftExpression;
// maps to a direct collection mapping
if (!isIdentificationVariableValidInComparison(variable)) {
addProblem(leftExpression, ComparisonExpression_IdentificationVariable, leftExpression.toActualText(), expression.getComparisonOperator());
valid = false;
}
} else // The left expression is a path expression
if (validator.leftStateFieldPathExpression && validator.leftStateFieldPathExpressionValid) {
Object mapping = helper.resolveMapping(leftExpression);
// The path expression cannot be a non-basic mapping
if ((mapping != null) && !helper.isPropertyMapping(mapping)) {
addProblem(leftExpression, ComparisonExpression_AssociationField, leftExpression.toActualText(), expression.getComparisonOperator());
valid = false;
}
}
// The right expression cannot be an identification variable
if (validator.rightIdentificationVariable && validator.rightIdentificationVariableValid) {
IdentificationVariable variable = (IdentificationVariable) rightExpression;
// maps to a direct collection mapping
if (!isIdentificationVariableValidInComparison(variable)) {
addProblem(rightExpression, ComparisonExpression_IdentificationVariable, rightExpression.toActualText(), expression.getComparisonOperator());
valid = false;
}
} else // The right expression is a path expression
if (validator.rightStateFieldPathExpression && validator.rightStateFieldPathExpressionValid) {
Object mapping = helper.resolveMapping(rightExpression);
// The path expression cannot be a non-basic mapping
if ((mapping != null) && !helper.isPropertyMapping(mapping)) {
addProblem(rightExpression, ComparisonExpression_AssociationField, rightExpression.toActualText(), expression.getComparisonOperator());
valid = false;
}
}
} else // '=', '<>'
{
// The right expression is a path expression
if (validator.leftIdentificationVariable && validator.leftIdentificationVariableValid && validator.rightStateFieldPathExpression && validator.rightStateFieldPathExpressionValid) {
Object mapping = helper.resolveMapping(rightExpression);
IdentificationVariable variable = (IdentificationVariable) leftExpression;
// maps to a direct collection mapping
if ((mapping != null) && helper.isPropertyMapping(mapping) && !isIdentificationVariableValidInComparison(variable)) {
addProblem(rightExpression, ComparisonExpression_BasicField, rightExpression.toActualText(), expression.getComparisonOperator());
valid = false;
}
} else // The right expression is an identification variable
if (validator.rightIdentificationVariable && validator.rightIdentificationVariableValid && validator.leftStateFieldPathExpression && validator.leftStateFieldPathExpressionValid) {
Object mapping = helper.resolveMapping(leftExpression);
IdentificationVariable variable = (IdentificationVariable) rightExpression;
// maps to a direct collection mapping
if ((mapping != null) && helper.isPropertyMapping(mapping) && !isIdentificationVariableValidInComparison(variable)) {
addProblem(leftExpression, ComparisonExpression_BasicField, leftExpression.toActualText(), expression.getComparisonOperator());
valid = false;
}
}
}
return valid;
} finally {
validator.dispose();
}
}
use of org.eclipse.persistence.jpa.jpql.parser.ConcatExpression in project eclipselink by eclipse-ee4j.
the class ReportItemBuilder method visit.
@Override
public void visit(ConcatExpression expression) {
Expression queryExpression = queryContext.buildExpression(expression, type);
addAttribute(ExpressionTools.EMPTY_STRING, queryExpression, type[0]);
}
use of org.eclipse.persistence.jpa.jpql.parser.ConcatExpression in project eclipselink by eclipse-ee4j.
the class ExpressionBuilderVisitor method visit.
@Override
public void visit(ConcatExpression expression) {
List<org.eclipse.persistence.jpa.jpql.parser.Expression> expressions = children(expression.getExpression());
Expression newExpression = null;
for (org.eclipse.persistence.jpa.jpql.parser.Expression child : expressions) {
child.accept(this);
if (newExpression == null) {
newExpression = queryExpression;
} else {
newExpression = newExpression.concat(queryExpression);
}
}
queryExpression = newExpression;
// Set the expression type
type[0] = String.class;
}
use of org.eclipse.persistence.jpa.jpql.parser.ConcatExpression in project eclipselink by eclipse-ee4j.
the class AbstractActualJPQLQueryFormatter method visit.
@Override
public void visit(ConcatExpressionStateObject stateObject) {
if (stateObject.isDecorated()) {
toText(stateObject);
} else {
ConcatExpression expression = stateObject.getExpression();
// 'CONCAT'
appendIdentifier((expression != null) ? expression.getActualIdentifier() : CONCAT, CONCAT);
// '('
if (shouldOutput(expression) || expression.hasLeftParenthesis()) {
writer.append(LEFT_PARENTHESIS);
}
toStringChildren(stateObject, true);
// ')'
if (shouldOutput(expression) || expression.hasRightParenthesis()) {
writer.append(RIGHT_PARENTHESIS);
}
}
}
Aggregations