Example usage for javax.persistence.criteria CriteriaBuilder quot

List of usage examples for javax.persistence.criteria CriteriaBuilder quot

Introduction

In this page you can find the example usage for javax.persistence.criteria CriteriaBuilder quot.

Prototype

Expression<Number> quot(Number x, Expression<? extends Number> y);

Source Link

Document

Create an expression that returns the quotient of its arguments.

Usage

From source file:net.dontdrinkandroot.persistence.dao.NumericEntityDaoTest.java

@Test
@Transactional/*from www  .ja  v a 2  s.c o  m*/
public void testQuot() {
    NumericEntity entity2 = new NumericEntity();
    entity2.setLongField(2L);
    entity2.setIntField(3);
    entity2 = this.save(entity2);

    final CriteriaBuilder builder = this.getCriteriaBuilder();
    final CriteriaQuery<Number> criteriaQuery = builder.createQuery(Number.class);
    final Root<NumericEntity> root = criteriaQuery.from(NumericEntity.class);
    final Expression<Number> quot = builder.quot(
            builder.prod(builder.literal(1f), root.get(NumericEntity_.intField)),
            root.get(NumericEntity_.longField));
    criteriaQuery.select(quot);

    final Number result = this.findSingle(criteriaQuery);
    Assert.assertEquals(Float.class, result.getClass());
    Assert.assertEquals(3 / 2f, result);
}