use of org.eclipse.persistence.jpa.jpql.parser.TrimExpression in project eclipselink by eclipse-ee4j.
the class AbstractGrammarValidator method visit.
@Override
public void visit(TrimExpression expression) {
validateAbstractSingleEncapsulatedExpression(expression, trimExpressionHelper());
// Missing string primary
if (!expression.hasExpression()) {
int startPosition = position(expression) + 4 + /* TRIM */
(expression.hasLeftParenthesis() ? 1 : 0) + expression.getSpecification().getValue().length() + (expression.hasSpaceAfterSpecification() ? 1 : 0) + length(expression.getTrimCharacter()) + (expression.hasSpaceAfterTrimCharacter() ? 1 : 0) + (expression.hasFrom() ? 4 : 0) + (expression.hasSpaceAfterFrom() ? 1 : 0);
addProblem(expression, startPosition, TrimExpression_MissingExpression);
} else // Invalid string primary
if (!isValid(expression.getExpression(), expression.getEncapsulatedExpressionQueryBNFId())) {
int startPosition = position(expression) + 4 + /* TRIM */
(expression.hasLeftParenthesis() ? 1 : 0) + expression.getSpecification().getValue().length() + (expression.hasSpaceAfterSpecification() ? 1 : 0) + length(expression.getTrimCharacter()) + (expression.hasSpaceAfterTrimCharacter() ? 1 : 0) + (expression.hasFrom() ? 4 : 0) + (expression.hasSpaceAfterFrom() ? 1 : 0);
int endPosition = startPosition + length(expression.getExpression());
addProblem(expression, startPosition, endPosition, TrimExpression_InvalidExpression);
}
// Invalid trim character
if (expression.hasTrimCharacter()) {
Expression trimCharacter = expression.getTrimCharacter();
// Make sure it's not an input parameter
String inputParameter = literal(trimCharacter, LiteralType.INPUT_PARAMETER);
if (ExpressionTools.stringIsEmpty(inputParameter)) {
String stringLiteral = literal(trimCharacter, LiteralType.STRING_LITERAL);
int startPosition = position(expression) + 4 + /* TRIM */
(expression.hasLeftParenthesis() ? 1 : 0) + expression.getSpecification().getValue().length() + (expression.hasSpaceAfterSpecification() ? 1 : 0);
int endPosition = startPosition + length(trimCharacter);
if (ExpressionTools.stringIsEmpty(stringLiteral)) {
addProblem(trimCharacter, startPosition, endPosition, TrimExpression_InvalidTrimCharacter);
} else {
stringLiteral = stringLiteral.substring(1, stringLiteral.length() - (stringLiteral.endsWith("'") ? 1 : 0));
if (stringLiteral.length() != 1) {
addProblem(trimCharacter, startPosition, endPosition, TrimExpression_NotSingleStringLiteral);
}
}
}
}
}
use of org.eclipse.persistence.jpa.jpql.parser.TrimExpression in project eclipselink by eclipse-ee4j.
the class ExpressionBuilderVisitor method visit.
@Override
public void visit(TrimExpression expression) {
// Create the TRIM character expression
expression.getTrimCharacter().accept(this);
Expression trimCharacter = queryExpression;
// Create the string to trim
expression.getExpression().accept(this);
Expression stringExpression = queryExpression;
switch(expression.getSpecification()) {
case LEADING:
{
if (trimCharacter != null) {
queryExpression = stringExpression.leftTrim(trimCharacter);
} else {
queryExpression = stringExpression.leftTrim();
}
break;
}
case TRAILING:
{
if (trimCharacter != null) {
queryExpression = stringExpression.rightTrim(trimCharacter);
} else {
queryExpression = stringExpression.rightTrim();
}
break;
}
default:
{
if (trimCharacter != null) {
queryExpression = stringExpression.trim(trimCharacter);
} else {
queryExpression = stringExpression.trim();
}
break;
}
}
// Set the expression type
type[0] = String.class;
}
use of org.eclipse.persistence.jpa.jpql.parser.TrimExpression in project eclipselink by eclipse-ee4j.
the class ReportItemBuilder method visit.
@Override
public void visit(TrimExpression expression) {
Expression queryExpression = queryContext.buildExpression(expression, type);
addAttribute(ExpressionTools.EMPTY_STRING, queryExpression, type[0]);
}
use of org.eclipse.persistence.jpa.jpql.parser.TrimExpression in project eclipselink by eclipse-ee4j.
the class TrimExpressionStateObject method parse.
@Override
public void parse(String jpqlFragment) {
StringBuilder sb = new StringBuilder();
sb.append(TRIM);
sb.append(LEFT_PARENTHESIS);
sb.append(jpqlFragment);
sb.append(RIGHT_PARENTHESIS);
JPQLExpression jpqlExpression = new JPQLExpression(sb, getGrammar(), FunctionsReturningStringsBNF.ID, true);
TrimExpression trimExpression = (TrimExpression) jpqlExpression.getQueryStatement();
setSpecification(trimExpression.getSpecification());
parseTrimCharacter(trimExpression.getTrimCharacter().toParsedText());
super.parse(trimExpression.getExpression().toParsedText());
// The trim character is actually the string primary
if (!hasStateObject() && hasTrimCharacter()) {
setStateObject(new StringLiteralStateObject(this, trimCharacter.toString()));
trimCharacter = null;
}
}
use of org.eclipse.persistence.jpa.jpql.parser.TrimExpression in project eclipselink by eclipse-ee4j.
the class AbstractActualJPQLQueryFormatter method visit.
@Override
public void visit(TrimExpressionStateObject stateObject) {
if (stateObject.isDecorated()) {
toText(stateObject);
} else {
TrimExpression expression = stateObject.getExpression();
// 'TRIM'
appendIdentifier((expression != null) ? expression.getActualIdentifier() : stateObject.getIdentifier(), stateObject.getIdentifier());
// '('
if (shouldOutput(expression) || (expression != null && expression.hasLeftParenthesis())) {
writer.append(LEFT_PARENTHESIS);
} else if ((expression != null) && expression.hasSpaceAfterIdentifier()) {
writer.append(SPACE);
}
// Trim specification
if (stateObject.hasSpecification()) {
String specification = stateObject.getSpecification().name();
String actualSpecification = (expression != null) ? expression.getActualSpecificationIdentifier() : null;
if (!specification.equalsIgnoreCase(actualSpecification)) {
actualSpecification = specification;
}
appendIdentifier(actualSpecification, specification);
}
if (shouldOutput(expression) || expression.hasSpaceAfterSpecification()) {
writer.append(SPACE);
}
// Trim character
if (stateObject.hasTrimCharacter()) {
stateObject.getTrimCharacter().accept(this);
if (shouldOutput(expression) || expression.hasSpaceAfterTrimCharacter()) {
writer.append(SPACE);
}
}
// 'FROM'
if (stateObject.hasSpecification() || stateObject.hasTrimCharacter()) {
appendIdentifier((expression != null) ? expression.getActualFromIdentifier() : FROM, FROM);
if (shouldOutput(expression) || expression.hasSpaceAfterFrom()) {
writer.append(SPACE);
}
}
// String primary
if (stateObject.hasStateObject()) {
stateObject.getStateObject().accept(this);
}
// ')'
if (shouldOutput(expression) || expression.hasRightParenthesis()) {
writer.append(RIGHT_PARENTHESIS);
}
}
}
Aggregations