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