Package javax.persistence.criteria

Examples of javax.persistence.criteria.CriteriaBuilder.avg()


    private CriteriaQuery<Double> buildAvgCriteriaQuery(EntityManager em,
            Class<Double> type, SingularAttribute<AggEntity, Double> sa) {
        CriteriaBuilder cb = em.getCriteriaBuilder();
        CriteriaQuery<Double> cq = cb.createQuery(type);
        Root<AggEntity> aer = cq.from(AggEntity.class);
        return cq.select(cb.avg(aer.get(sa)));
    }

    private void verifyResult(EntityManager em, String[] aggregates,
            String[] attributes, boolean expectNull) {
        verifyResult(em, aggregates, attributes, expectNull, false);
View Full Code Here


    public int averageRating(final int metadataId) {
        final CriteriaBuilder cb = _entityManager.getCriteriaBuilder();
        CriteriaQuery<Double> cbQuery = cb.createQuery(Double.class);
        Root<MetadataRatingByIp> root = cbQuery.from(MetadataRatingByIp.class);

        Expression<Double> mean = cb.avg(root.get(MetadataRatingByIp_.rating));
        cbQuery.select(mean);
        cbQuery.where(cb.equal(root.get(MetadataRatingByIp_.id).get(MetadataRatingByIpId_.metadataId), metadataId));
        return _entityManager.createQuery(cbQuery).getSingleResult().intValue();
    }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.