In here I'm trying to return two results as one response and not sure what option may good with it. In here it return as a list,
List<FixedDeposit> fdList = em.createQuery(sb.toString())
.setParameter("start", dateFrom)
.setParameter("end", dateTo)
.setFirstResult(start).setMaxResults(limit)
.getResultList();
so I have got it as
List<FDSearchResult> searchList = getSearchResult(fdList);
response.setData(searchList);
return response;
And now again I want to return another response. And this is the calculation,
Double sum = 0.0;
sum = (Double) em.createQuery("SELECT SUM(deposit_amount)FROM fd_fixed_deposit where fd.status in ('ACT','REN','WDR') and fd.maturityDate between :start and :end ")
.setParameter("start", dateFrom)
.setParameter("end", dateTo).getSingleResult();
So how can I return the result through response for the sum? Please Help
I will post the full method,
public Response<List<FDSearchResult>> loadMaturedFDByRange(String fromDate, String toDate, final Integer start,
final Integer limit) {
final Response<List<FDSearchResult>> response = new Response<List<FDSearchResult>>();
Date dateFrom = DateUtils.parseDate("dd/MM/yyyy", fromDate, null);
Date dateTo = DateUtils.parseDate("dd/MM/yyyy", toDate, null);
Long count = 0L;
Double sum = 0.0;
try {
count = (Long) em.createQuery("SELECT COUNT(fd) FROM FixedDeposit fd where fd.status in ('ACT','REN','WDR') "
+ "and fd.maturityDate between :start and :end ")
.setParameter("start", dateFrom)
.setParameter("end", dateTo).getSingleResult();
} catch (NoResultException nre) {
count = 0L;
}
StringBuilder sb = new StringBuilder();
sb.append("SELECT fd FROM FixedDeposit fd where fd.status in ('ACT','REN','WDR') and fd.maturityDate between :start and :end ");
List<FixedDeposit> fdList = em.createQuery(sb.toString())
.setParameter("start", dateFrom)
.setParameter("end", dateTo)
.setFirstResult(start).setMaxResults(limit)
.getResultList();
sum = (Double) em.createQuery("SELECT SUM(deposit_amount)FROM fd_fixed_deposit where fd.status in ('ACT','REN','WDR') and fd.maturityDate between :start and :end ")
.setParameter("start", dateFrom)
.setParameter("end", dateTo).getSingleResult();
List<FDSearchResult> searchList = getSearchResult(fdList);
response.setData(searchList);
response.setPagination(new Response().new PaginationInfo(count));
return response;
}