private < T , Y extends Number > TypedQuery < T > createTypedQuery ( Class < T > entityCls , SingularAttribute < T , Y > attribute , SqlComparator comparator , Y value ) { EntityManager entityManager = this . entityManagerProvider . get ( ) ; CriteriaBuilder builder = entityManager . getCriteriaBuilder ( ) ; CriteriaQuery < T > criteriaQuery = builder . createQuery ( entityCls ) ; Root < T > root = criteriaQuery . from ( entityCls ) ; Path < Y > path = root . get ( attribute ) ; Predicate pred ; switch ( comparator ) { case LESS_THAN : pred = builder . lt ( path , value ) ; break ; case LESS_THAN_OR_EQUAL_TO : pred = builder . le ( path , value ) ; break ; case EQUAL_TO : pred = builder . equal ( path , value ) ; break ; case NOT_EQUAL_TO : pred = builder . notEqual ( path , value ) ; break ; case GREATER_THAN_OR_EQUAL_TO : pred = builder . ge ( path , value ) ; break ; case GREATER_THAN : pred = builder . gt ( path , value ) ; break ; default : throw new AssertionError ( "Invalid SQLComparator: " + comparator ) ; } return entityManager . createQuery ( criteriaQuery . where ( pred ) ) ; }
Creates a typed query for entities with the given numerical attribute value .