Search in sources :

Example 1 with ObjectExpression

use of org.eclipse.persistence.jpa.jpql.parser.ObjectExpression 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)

Aggregations

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