List of usage examples for javax.persistence.criteria CriteriaBuilder sumAsLong
Expression<Long> sumAsLong(Expression<Integer> x);
From source file:org.egov.tl.repository.DCBReportRepositoryImpl.java
@Override public Object[] findByBaseRegisterRequest(final DCBReportSearchRequest dCBReportSearchRequest) { final CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); final CriteriaQuery<Object[]> criteriaQuery = criteriaBuilder.createQuery(Object[].class); final Root<DCBReportResult> root = criteriaQuery.from(DCBReportResult.class); final List<Predicate> predicates = new ArrayList<>(); if (isNotBlank(dCBReportSearchRequest.getLicenseNumber())) predicates.add(/*from w w w. ja v a2 s . c o m*/ criteriaBuilder.equal(root.get("licenseNumber"), dCBReportSearchRequest.getLicenseNumber())); if (dCBReportSearchRequest.getActiveLicense() > 0) predicates .add(criteriaBuilder.equal(root.get("active"), dCBReportSearchRequest.getActiveLicense() == 1)); if (dCBReportSearchRequest.getWardId() != null && !dCBReportSearchRequest.getWardId().isEmpty()) predicates.add(root.get("wardId").in(dCBReportSearchRequest.getWardId())); if (dCBReportSearchRequest.getAdminWardId() != null && !dCBReportSearchRequest.getAdminWardId().isEmpty()) predicates.add(root.get("adminWard").in(dCBReportSearchRequest.getAdminWardId())); criteriaQuery .multiselect(criteriaBuilder.sumAsLong(root.get("arrearDemand")), criteriaBuilder.sumAsLong(root.get("currentDemand")), criteriaBuilder.sumAsLong( criteriaBuilder.sum(root.get("arrearDemand"), root.get("currentDemand"))), criteriaBuilder.sumAsLong(root.get("arrearCollection")), criteriaBuilder.sumAsLong(root.get("currentCollection")), criteriaBuilder.sumAsLong( criteriaBuilder.sum(root.get("arrearCollection"), root.get("currentCollection"))), criteriaBuilder.sumAsLong(root.get("arrearBalance")), criteriaBuilder.sumAsLong(root.get("currentBalance")), criteriaBuilder.sumAsLong( criteriaBuilder.sum(root.get("arrearBalance"), root.get("currentBalance")))) .where(predicates.toArray(new Predicate[] {})); return entityManager.createQuery(criteriaQuery).getSingleResult(); }