Search in sources :

Example 1 with SelectClause

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

Example 2 with SelectClause

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);
}
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 SelectClause

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);
}
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)

Example 4 with SelectClause

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);
}
Also used : SelectClause(org.eclipse.persistence.jpa.jpql.parser.SelectClause) 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) JPQLExpression(org.eclipse.persistence.jpa.jpql.parser.JPQLExpression) Test(org.junit.Test)

Example 5 with 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);
}
Also used : IdentificationVariable(org.eclipse.persistence.jpa.jpql.parser.IdentificationVariable) SelectClause(org.eclipse.persistence.jpa.jpql.parser.SelectClause) 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) JPQLExpression(org.eclipse.persistence.jpa.jpql.parser.JPQLExpression) Test(org.junit.Test)

Aggregations

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