use of org.eclipse.persistence.jpa.jpql.parser.SelectStatement in project eclipselink by eclipse-ee4j.
the class AbstractActualJPQLQueryFormatter method visit.
@Override
public void visit(SelectStatementStateObject stateObject) {
if (stateObject.isDecorated()) {
toText(stateObject);
} else {
boolean endWithSpace = toStringSelectStatement(stateObject);
SelectStatement expression = stateObject.getExpression();
// If no ORDER BY clause was parsed but was added later, make sure a space is added
if (exactMatch && (expression != null) && expression.hasSpaceBeforeOrderBy() || stateObject.hasOrderByClause()) {
if (!endWithSpace) {
writer.append(SPACE);
}
}
// ORDER BY clause
if (stateObject.hasOrderByClause()) {
stateObject.getOrderByClause().accept(this);
}
}
}
use of org.eclipse.persistence.jpa.jpql.parser.SelectStatement in project eclipselink by eclipse-ee4j.
the class JPQLExpressionTest1_0 method testGetExpression_2.
@Test
public void testGetExpression_2() {
String query = "SELECT OBJECT(e), COUNT(DISTINCT e) FROM Employee e";
JPQLExpression jpqlExpression = JPQLQueryBuilder.buildQuery(query, getGrammar(), true);
Expression expression = jpqlExpression.getExpression(query, 0);
assertNotNull(expression);
assertTrue("The expression was " + expression.getClass().getSimpleName(), expression instanceof JPQLExpression);
expression = jpqlExpression.getExpression(query, 14);
assertNotNull(expression);
assertTrue("The expression was " + expression.getClass().getSimpleName(), expression instanceof ObjectExpression);
// In 'SELECT'
for (int index = 1; index < 8; index++) {
expression = jpqlExpression.getExpression(query, index);
assertNotNull(expression);
assertTrue("The expression was " + expression.getClass().getSimpleName(), expression instanceof SelectClause);
}
// In 'OBJECT('
for (int index = 8; index < 15; index++) {
expression = jpqlExpression.getExpression(query, index);
assertNotNull(expression);
assertTrue("The expression was " + expression.getClass().getSimpleName(), expression instanceof ObjectExpression);
}
// In 'e' of 'OBJECT(e)'
expression = jpqlExpression.getExpression(query, 15);
assertNotNull(expression);
assertTrue("The expression was " + expression.getClass().getSimpleName(), expression instanceof IdentificationVariable);
expression = jpqlExpression.getExpression(query, 17);
assertNotNull(expression);
assertTrue("The expression was " + expression.getClass().getSimpleName(), expression instanceof CollectionExpression);
expression = jpqlExpression.getExpression(query, 18);
assertNotNull(expression);
assertTrue("The expression was " + expression.getClass().getSimpleName(), expression instanceof CollectionExpression);
expression = jpqlExpression.getExpression(query, 24);
assertNotNull(expression);
assertTrue("The expression was " + expression.getClass().getSimpleName(), expression instanceof CountFunction);
expression = jpqlExpression.getExpression(query, 35);
assertNotNull(expression);
assertTrue("The expression was " + expression.getClass().getSimpleName(), expression instanceof CountFunction);
expression = jpqlExpression.getExpression(query, 36);
assertNotNull(expression);
assertTrue("The expression was " + expression.getClass().getSimpleName(), expression instanceof SelectStatement);
}
use of org.eclipse.persistence.jpa.jpql.parser.SelectStatement in project eclipselink by eclipse-ee4j.
the class JPQLExpressionTest1_0 method testGetExpression_1.
@Test
public void testGetExpression_1() {
String actualQuery = " SELECT AVG ( mag ) FROM Magazine mag";
JPQLExpression jpqlExpression = JPQLQueryBuilder.buildQuery(actualQuery, getGrammar(), true);
Expression expression = jpqlExpression.getExpression(actualQuery, 0);
assertNotNull(expression);
assertTrue("The expression was " + expression.getClass().getSimpleName(), expression instanceof JPQLExpression);
expression = jpqlExpression.getExpression(actualQuery, 2);
assertNotNull(expression);
assertTrue("The expression was " + expression.getClass().getSimpleName(), expression instanceof JPQLExpression);
expression = jpqlExpression.getExpression(actualQuery, 4);
assertNotNull(expression);
assertTrue("The expression was " + expression.getClass().getSimpleName(), expression instanceof SelectClause);
expression = jpqlExpression.getExpression(actualQuery, 10);
assertNotNull(expression);
assertTrue("The expression was " + expression.getClass().getSimpleName(), expression instanceof SelectClause);
expression = jpqlExpression.getExpression(actualQuery, 25);
assertNotNull(expression);
assertTrue("The expression was " + expression.getClass().getSimpleName(), expression instanceof SelectStatement);
expression = jpqlExpression.getExpression(actualQuery, 30);
assertNotNull(expression);
assertTrue("The expression was " + expression.getClass().getSimpleName(), expression instanceof FromClause);
}
Aggregations