Search in sources :

Example 1 with SelectStatement

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);
        }
    }
}
Also used : AbstractSelectStatement(org.eclipse.persistence.jpa.jpql.parser.AbstractSelectStatement) SelectStatement(org.eclipse.persistence.jpa.jpql.parser.SelectStatement)

Example 2 with SelectStatement

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);
}
Also used : IdentificationVariable(org.eclipse.persistence.jpa.jpql.parser.IdentificationVariable) SelectClause(org.eclipse.persistence.jpa.jpql.parser.SelectClause) SelectStatement(org.eclipse.persistence.jpa.jpql.parser.SelectStatement) Expression(org.eclipse.persistence.jpa.jpql.parser.Expression) StateFieldPathExpression(org.eclipse.persistence.jpa.jpql.parser.StateFieldPathExpression) ObjectExpression(org.eclipse.persistence.jpa.jpql.parser.ObjectExpression) LikeExpression(org.eclipse.persistence.jpa.jpql.parser.LikeExpression) JPQLExpression(org.eclipse.persistence.jpa.jpql.parser.JPQLExpression) CollectionExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionExpression) UnknownExpression(org.eclipse.persistence.jpa.jpql.parser.UnknownExpression) CountFunction(org.eclipse.persistence.jpa.jpql.parser.CountFunction) CollectionExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionExpression) ObjectExpression(org.eclipse.persistence.jpa.jpql.parser.ObjectExpression) JPQLExpression(org.eclipse.persistence.jpa.jpql.parser.JPQLExpression) Test(org.junit.Test)

Example 3 with 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);
}
Also used : SelectClause(org.eclipse.persistence.jpa.jpql.parser.SelectClause) SelectStatement(org.eclipse.persistence.jpa.jpql.parser.SelectStatement) Expression(org.eclipse.persistence.jpa.jpql.parser.Expression) StateFieldPathExpression(org.eclipse.persistence.jpa.jpql.parser.StateFieldPathExpression) ObjectExpression(org.eclipse.persistence.jpa.jpql.parser.ObjectExpression) LikeExpression(org.eclipse.persistence.jpa.jpql.parser.LikeExpression) JPQLExpression(org.eclipse.persistence.jpa.jpql.parser.JPQLExpression) CollectionExpression(org.eclipse.persistence.jpa.jpql.parser.CollectionExpression) UnknownExpression(org.eclipse.persistence.jpa.jpql.parser.UnknownExpression) FromClause(org.eclipse.persistence.jpa.jpql.parser.FromClause) JPQLExpression(org.eclipse.persistence.jpa.jpql.parser.JPQLExpression) Test(org.junit.Test)

Aggregations

SelectStatement (org.eclipse.persistence.jpa.jpql.parser.SelectStatement)3 CollectionExpression (org.eclipse.persistence.jpa.jpql.parser.CollectionExpression)2 Expression (org.eclipse.persistence.jpa.jpql.parser.Expression)2 JPQLExpression (org.eclipse.persistence.jpa.jpql.parser.JPQLExpression)2 LikeExpression (org.eclipse.persistence.jpa.jpql.parser.LikeExpression)2 ObjectExpression (org.eclipse.persistence.jpa.jpql.parser.ObjectExpression)2 SelectClause (org.eclipse.persistence.jpa.jpql.parser.SelectClause)2 StateFieldPathExpression (org.eclipse.persistence.jpa.jpql.parser.StateFieldPathExpression)2 UnknownExpression (org.eclipse.persistence.jpa.jpql.parser.UnknownExpression)2 Test (org.junit.Test)2 AbstractSelectStatement (org.eclipse.persistence.jpa.jpql.parser.AbstractSelectStatement)1 CountFunction (org.eclipse.persistence.jpa.jpql.parser.CountFunction)1 FromClause (org.eclipse.persistence.jpa.jpql.parser.FromClause)1 IdentificationVariable (org.eclipse.persistence.jpa.jpql.parser.IdentificationVariable)1