use of org.eclipse.persistence.jpa.jpql.parser.SelectClause in project eclipselink by eclipse-ee4j.
the class AbstractActualJPQLQueryFormatter method visit.
@Override
public void visit(SelectClauseStateObject stateObject) {
if (stateObject.isDecorated()) {
toText(stateObject);
} else {
SelectClause expression = stateObject.getExpression();
// SELECT
appendIdentifier((expression != null) ? expression.getActualIdentifier() : SELECT, SELECT);
if (shouldOutput(expression) || expression.hasSpaceAfterSelect()) {
writer.append(SPACE);
}
// DISTINCT
if (stateObject.hasDistinct()) {
appendIdentifier((expression != null) ? expression.getActualDistinctIdentifier() : DISTINCT, DISTINCT);
if (shouldOutput(expression) || expression.hasSpaceAfterDistinct()) {
writer.append(SPACE);
}
}
// Select expressions
if (stateObject.hasItems()) {
toStringChildren(stateObject, true);
}
}
}
use of org.eclipse.persistence.jpa.jpql.parser.SelectClause 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.SelectClause 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);
}
use of org.eclipse.persistence.jpa.jpql.parser.SelectClause in project eclipselink by eclipse-ee4j.
the class JPQLExpressionTest1_0 method testGetExpression_5.
@Test
public void testGetExpression_5() {
String query = "SELECT ";
JPQLExpression jpqlExpression = JPQLQueryBuilder.buildQuery(query, getGrammar(), true);
Expression expression = jpqlExpression.getExpression(query, 7);
assertNotNull(expression);
assertTrue("The expression was " + expression.getClass().getSimpleName(), expression instanceof SelectClause);
}
use of org.eclipse.persistence.jpa.jpql.parser.SelectClause in project eclipselink by eclipse-ee4j.
the class JPQLExpressionTest1_0 method testGetExpression_3.
@Test
public void testGetExpression_3() {
String query = "SELECT e FROM Employee e";
JPQLExpression jpqlExpression = JPQLQueryBuilder.buildQuery(query, getGrammar(), true);
Expression expression = jpqlExpression.getExpression(query, 8);
assertNotNull(expression);
assertTrue("The expression was " + expression.getClass().getSimpleName(), expression instanceof IdentificationVariable);
expression = jpqlExpression.getExpression(query, 6);
assertNotNull(expression);
assertTrue("The expression was " + expression.getClass().getSimpleName(), expression instanceof SelectClause);
}
Aggregations