Search in sources :

Example 1 with SqmCollectionSize

use of org.hibernate.query.sqm.tree.expression.SqmCollectionSize in project hibernate-orm by hibernate.

the class WhereClauseTests method testCollectionSizeFunction.

@Test
public void testCollectionSizeFunction() {
    SqmSelectStatement<?> statement = interpretSelect("SELECT t FROM EntityOfSets t WHERE SIZE( t.setOfBasics ) = 311");
    SqmPredicate predicate = statement.getQuerySpec().getWhereClause().getPredicate();
    assertThat(predicate, instanceOf(SqmComparisonPredicate.class));
    SqmComparisonPredicate relationalPredicate = ((SqmComparisonPredicate) predicate);
    assertThat(relationalPredicate.getSqmOperator(), is(ComparisonOperator.EQUAL));
    assertThat(relationalPredicate.getRightHandExpression(), instanceOf(SqmLiteral.class));
    assertThat(((SqmLiteral<?>) relationalPredicate.getRightHandExpression()).getLiteralValue(), is(311));
    assertThat(relationalPredicate.getLeftHandExpression(), instanceOf(SqmCollectionSize.class));
    final SqmCollectionSize func = (SqmCollectionSize) relationalPredicate.getLeftHandExpression();
    assertThat(func.getPluralPath().getLhs().getExplicitAlias(), is("t"));
    assertThat(func.getPluralPath().getReferencedPathSource().getPathName(), is("setOfBasics"));
}
Also used : SqmPredicate(org.hibernate.query.sqm.tree.predicate.SqmPredicate) SqmComparisonPredicate(org.hibernate.query.sqm.tree.predicate.SqmComparisonPredicate) SqmLiteral(org.hibernate.query.sqm.tree.expression.SqmLiteral) SqmCollectionSize(org.hibernate.query.sqm.tree.expression.SqmCollectionSize) BaseSqmUnitTest(org.hibernate.orm.test.query.sqm.BaseSqmUnitTest) Test(org.junit.jupiter.api.Test)

Aggregations

BaseSqmUnitTest (org.hibernate.orm.test.query.sqm.BaseSqmUnitTest)1 SqmCollectionSize (org.hibernate.query.sqm.tree.expression.SqmCollectionSize)1 SqmLiteral (org.hibernate.query.sqm.tree.expression.SqmLiteral)1 SqmComparisonPredicate (org.hibernate.query.sqm.tree.predicate.SqmComparisonPredicate)1 SqmPredicate (org.hibernate.query.sqm.tree.predicate.SqmPredicate)1 Test (org.junit.jupiter.api.Test)1