Search in sources :

Example 11 with SqmComparisonPredicate

use of org.hibernate.query.sqm.tree.predicate.SqmComparisonPredicate 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)

Example 12 with SqmComparisonPredicate

use of org.hibernate.query.sqm.tree.predicate.SqmComparisonPredicate in project hibernate-orm by hibernate.

the class WhereClauseTests method testListIndexFunction.

@Test
public void testListIndexFunction() {
    SqmSelectStatement<?> statement = interpretSelect("select l from EntityOfLists t join t.listOfBasics l where index(l) > 2");
    SqmPredicate predicate = statement.getQuerySpec().getWhereClause().getPredicate();
    assertThat(predicate, instanceOf(SqmComparisonPredicate.class));
    SqmComparisonPredicate relationalPredicate = ((SqmComparisonPredicate) predicate);
    assertThat(relationalPredicate.getSqmOperator(), is(ComparisonOperator.GREATER_THAN));
    assertThat(relationalPredicate.getRightHandExpression(), instanceOf(SqmLiteral.class));
    assertThat(((SqmLiteral<?>) relationalPredicate.getRightHandExpression()).getLiteralValue(), is(2));
    assertThat(relationalPredicate.getLeftHandExpression(), instanceOf(SqmPath.class));
    final SqmPath<?> indexPath = (SqmPath<?>) relationalPredicate.getLeftHandExpression();
    assertThat(indexPath.getLhs(), notNullValue());
    assertThat(indexPath.getLhs().getExplicitAlias(), is("l"));
}
Also used : SqmPredicate(org.hibernate.query.sqm.tree.predicate.SqmPredicate) SqmComparisonPredicate(org.hibernate.query.sqm.tree.predicate.SqmComparisonPredicate) SqmPath(org.hibernate.query.sqm.tree.domain.SqmPath) SqmLiteral(org.hibernate.query.sqm.tree.expression.SqmLiteral) BaseSqmUnitTest(org.hibernate.orm.test.query.sqm.BaseSqmUnitTest) Test(org.junit.jupiter.api.Test)

Aggregations

SqmComparisonPredicate (org.hibernate.query.sqm.tree.predicate.SqmComparisonPredicate)12 Test (org.junit.jupiter.api.Test)8 BaseSqmUnitTest (org.hibernate.orm.test.query.sqm.BaseSqmUnitTest)7 SqmLiteral (org.hibernate.query.sqm.tree.expression.SqmLiteral)5 SqmPath (org.hibernate.query.sqm.tree.domain.SqmPath)3 SqmExpression (org.hibernate.query.sqm.tree.expression.SqmExpression)3 CriteriaBuilder (jakarta.persistence.criteria.CriteriaBuilder)2 ComparisonOperator (org.hibernate.query.sqm.ComparisonOperator)2 SqmPredicate (org.hibernate.query.sqm.tree.predicate.SqmPredicate)2 SqmSelection (org.hibernate.query.sqm.tree.select.SqmSelection)2 EntityManager (jakarta.persistence.EntityManager)1 Expression (jakarta.persistence.criteria.Expression)1 Metamodel (jakarta.persistence.metamodel.Metamodel)1 BigInteger (java.math.BigInteger)1 Map (java.util.Map)1 HqlParser (org.hibernate.grammars.hql.HqlParser)1 EntityDomainType (org.hibernate.metamodel.model.domain.EntityDomainType)1 JpaMetamodel (org.hibernate.metamodel.model.domain.JpaMetamodel)1 Product (org.hibernate.orm.test.jpa.metamodel.Product)1 AbstractSqmFunctionDescriptor (org.hibernate.query.sqm.function.AbstractSqmFunctionDescriptor)1