use of org.eclipse.persistence.jpa.jpql.parser.LikeExpression in project eclipselink by eclipse-ee4j.
the class ExpressionBuilderVisitor method visit.
@Override
public void visit(LikeExpression expression) {
// Create the first expression
expression.getStringExpression().accept(this);
Expression firstExpression = queryExpression;
// Create the expression for the pattern value
expression.getPatternValue().accept(this);
Expression patternValue = queryExpression;
// Create the LIKE expression with the escape character
if (expression.hasEscapeCharacter()) {
expression.getEscapeCharacter().accept(this);
queryExpression = firstExpression.like(patternValue, queryExpression);
} else // Create the LIKE expression with no escape character
{
queryExpression = firstExpression.like(patternValue);
}
// Negate the expression
if (expression.hasNot()) {
queryExpression = queryExpression.not();
}
// Set the expression type
type[0] = Boolean.class;
}
use of org.eclipse.persistence.jpa.jpql.parser.LikeExpression in project eclipselink by eclipse-ee4j.
the class AbstractGrammarValidator method validateLikeExpressionEscapeCharacter.
protected void validateLikeExpressionEscapeCharacter(LikeExpression expression) {
Expression escapeCharacter = expression.getEscapeCharacter();
// Check for a string literal (single quoted character)
String character = literal(escapeCharacter, LiteralType.STRING_LITERAL);
// Check for a single character
if ((character.length() > 0) && ExpressionTools.isQuote(character.charAt(0))) {
// Unquote the literal first
character = ExpressionTools.unquote(character);
// The escape character is not a single character literal
if (character.length() != 1) {
int startPosition = position(expression) + length(expression.getStringExpression()) + (expression.hasSpaceAfterStringExpression() ? 1 : 0) + (expression.hasNot() ? 4 : 0) + 4 + /* LIKE */
(expression.hasSpaceAfterLike() ? 1 : 0) + length(expression.getPatternValue()) + (expression.hasSpaceAfterPatternValue() ? 1 : 0) + 6 + /* ESCAPE */
+(expression.hasSpaceAfterEscape() ? 1 : 0);
int endPosition = startPosition + length(escapeCharacter);
addProblem(expression, startPosition, endPosition, LikeExpression_InvalidEscapeCharacter, escapeCharacter.toActualText());
}
} else {
// Check for an input parameter
character = literal(escapeCharacter, LiteralType.INPUT_PARAMETER);
if ((character.length() == 0) && !isValid(escapeCharacter, LikeExpressionEscapeCharacterBNF.ID)) {
int startPosition = position(expression) + length(expression.getStringExpression()) + 4 + /* LIKE */
(expression.hasSpaceAfterStringExpression() ? 1 : 0) + (expression.hasNot() ? 1 : 0) + (expression.hasSpaceAfterLike() ? 1 : 0) + length(expression.getPatternValue()) + (expression.hasSpaceAfterPatternValue() ? 1 : 0) + 6 + /* ESCAPE */
+(expression.hasSpaceAfterEscape() ? 1 : 0);
int endPosition = startPosition + length(escapeCharacter);
addProblem(expression, startPosition, endPosition, LikeExpression_InvalidEscapeCharacter, escapeCharacter.toActualText());
}
}
}
use of org.eclipse.persistence.jpa.jpql.parser.LikeExpression in project eclipselink by eclipse-ee4j.
the class AbstractSemanticValidator method validateLikeExpression.
/**
* Validates the string expression of the given <code><b>LIKE</b></code> expression. The test to
* perform is:
* <ul>
* <li>If the string 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 LengthExpression} to validate by validating its string 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 validateLikeExpression(LikeExpression expression) {
int result = 0;
// Validate the "first" expression
if (expression.hasStringExpression()) {
Expression stringExpression = expression.getStringExpression();
// Special case for state field path expression, association field is not allowed
StateFieldPathExpression pathExpression = getStateFieldPathExpression(stringExpression);
if (pathExpression != null) {
boolean valid = validateStateFieldPathExpression(pathExpression, validPathExpressionTypeForStringExpression());
updateStatus(result, 0, valid);
} else {
stringExpression.accept(this);
}
}
// Validate the pattern value
expression.getPatternValue().accept(this);
// Validate the escape character
expression.getEscapeCharacter().accept(this);
return result;
}
use of org.eclipse.persistence.jpa.jpql.parser.LikeExpression in project eclipselink by eclipse-ee4j.
the class ParameterTypeVisitor method visit.
@Override
public void visit(LikeExpression expression) {
Expression stringExpression = expression.getStringExpression();
Expression patternValue = expression.getPatternValue();
Expression escapeCharacter = expression.getEscapeCharacter();
if (stringExpression.isAncestor(inputParameter)) {
this.type = String.class;
} else if (patternValue.isAncestor(inputParameter)) {
this.type = String.class;
} else if (escapeCharacter.isAncestor(inputParameter)) {
this.type = Character.class;
} else {
// Shouldnt go in here?
this.type = boolean.class;
}
}
use of org.eclipse.persistence.jpa.jpql.parser.LikeExpression in project eclipselink by eclipse-ee4j.
the class JPQLExpressionTest1_0 method testGetExpression_6.
@Test
public void testGetExpression_6() {
String query = "SELECT e " + "FROM Employee e " + "HAVING e.department.name LIKE 'Sales%' ";
JPQLExpression jpqlExpression = JPQLQueryBuilder.buildQuery(query, getGrammar(), true);
int position = query.length();
Expression expression = jpqlExpression.getExpression(query, position);
assertNotNull(expression);
assertTrue("The expression was " + expression.getClass().getSimpleName(), expression instanceof LikeExpression);
}
Aggregations