List of usage examples for org.hibernate Query setResultTransformer
@Deprecated Query<R> setResultTransformer(ResultTransformer transformer);
From source file:com.nkapps.billing.dao.BankStatementDaoImpl.java
@Override public List<PrintClaimRegisterPojo> getPrintClaimRegisterList(Date periodStart, Date periodEnd) throws Exception { Session session = getSession();/*from www.ja v a2 s .co m*/ String q = " SELECT da.id as invoiceNum, p.paymentNum as paymentNum," + " p.paymentDate as paymentDate, p.tin as tin, da.name as name," + " p.paymentSum as paymentSum " + " FROM Payment p, DsApplication da" + " WHERE p.tin = da.tin AND p.claim = 1 AND p.sourceCode = 1" + " AND p.paymentDate BETWEEN :periodStart AND :periodEnd" + " ORDER BY p.paymentDate, p.paymentSum"; Query query = session.createQuery(q); query.setParameter("periodStart", periodStart); query.setParameter("periodEnd", periodEnd); query.setResultTransformer(Transformers.aliasToBean(PrintClaimRegisterPojo.class)); List<PrintClaimRegisterPojo> listPojo = query.list(); session.close(); return listPojo; }
From source file:com.nkapps.billing.dao.OverpaymentDaoImpl.java
@Override public List<OverpaymentListPojo> getList(Map parameters) throws Exception { List<OverpaymentListPojo> listPojos; Session session = getSession();//from ww w.jav a2 s .com String whereStr = ""; if (parameters.get("searchBy") != null && !"".equals(parameters.get("searchBy"))) { whereStr += " AND (bs.tin LIKE :searchBy OR bs.name LIKE :searchBy OR bs.mfo LIKE :searchBy" + " OR bs.chet LIKE :searchBy OR bs.paymentNum LIKE :searchBy OR bs.paymentDetails LIKE :searchBy ) "; } if (parameters.get("searchWithinDate") != null && "true".equals(parameters.get("searchWithinDate"))) { whereStr += " AND bs.paymentDate = :searchByDate"; } if (!"".equals(whereStr)) { whereStr = " WHERE " + whereStr.substring(whereStr.indexOf("AND") + 3); } String q = " SELECT bs.id AS id,bs.tin AS tin,bs.name as name," + " bs.paymentNum AS paymentNum, bs.paymentDate AS paymentDate, bs.paymentSum AS paymentSum," + " bs.paymentDetails AS paymentDetails," + " bs.transfered AS transfered," + " bs.dateUpdated AS dateUpdated," + " COALESCE(bs.paymentSum,0) - COALESCE(bs.returnSum,0) - (SELECT COALESCE(SUM(kp.paidSum),0) FROM bs.bankStatementPayments bsp JOIN bsp.id.payment p JOIN p.keyPayments kp WHERE p.claim = 0) AS overpaymentSum," + " bs.returnState as returnState, bs.returnSum as returnSum," + " bs.returnNum as returnNum, bs.returnDate as returnDate" + " FROM BankStatement bs" + whereStr + " ORDER BY bs.paymentDate, bs.paymentSum "; Query query = session.createQuery(q); query.setResultTransformer(Transformers.aliasToBean(OverpaymentListPojo.class)); if (parameters.get("searchBy") != null && !"".equals(parameters.get("searchBy"))) { query.setString("searchBy", ("%" + (String) parameters.get("searchBy") + "%").toUpperCase()); } if (parameters.get("searchWithinDate") != null && "true".equals(parameters.get("searchWithinDate"))) { query.setParameter("searchByDate", new SimpleDateFormat("dd.MM.yyyy").parse((String) parameters.get("searchByDate"))); } Integer start = "".equals((String) parameters.get("start")) ? 0 : Integer.parseInt((String) parameters.get("start")); Integer length = "".equals((String) parameters.get("length")) ? 0 : Integer.parseInt((String) parameters.get("length")); query.setFirstResult(start).setMaxResults(length); listPojos = query.list(); session.close(); return listPojos; }
From source file:com.nkapps.billing.dao.OverpaymentDaoImpl.java
@Override public void returnStateCommit(Session session, BankStatement bs, BigDecimal returnSum, Long issuerSerialNumber, String issuerIp, LocalDateTime dateTime) throws Exception { if (!bs.getBankStatementPayments().isEmpty()) { // if bankstatement has payments String q = " SELECT p.id AS id, p.tin AS tin, p.paymentNum AS paymentNum, p.paymentDate AS paymentDate," + " p.paymentSum AS paymentSum, p.sourceCode AS sourceCode," + " p.state AS state, p.tinDebtor as tinDebtor,p.claim as claim, p.issuerSerialNumber as issuerSerialNumber," + " p.issuerIp as issuerIp,p.dateCreated AS dateCreated, p.dateUpdated as dateUpdated, " + " p.paymentSum - COALESCE((SELECT SUM(paidSum) FROM KeyPayment kp WHERE kp.payment = p),0) AS overSum " + " FROM Payment p JOIN p.bankStatementPayment bsp " + " WHERE p.state IN (1,2) AND p.claim = 0 " + " AND bsp.id.bankStatement = :bs" + " ORDER BY p.paymentDate, p.paymentNum "; Query query = session.createQuery(q); query.setParameter("bs", bs); query.setResultTransformer(Transformers.aliasToBean(Payment.class)); List<Payment> paymentList = query.list(); for (Payment payment : paymentList) { if (payment.getOverSum().compareTo(returnSum) <= 0) { payment.setPaymentSum(payment.getPaymentSum().subtract(payment.getOverSum())); payment.setState((short) 3); // payment.setIssuerSerialNumber(issuerSerialNumber); payment.setIssuerIp(issuerIp); payment.setDateUpdated(dateTime); session.update(payment); returnSum = returnSum.subtract(payment.getOverSum()); } else { payment.setPaymentSum(payment.getPaymentSum().subtract(returnSum)); payment.setIssuerSerialNumber(issuerSerialNumber); payment.setIssuerIp(issuerIp); payment.setDateUpdated(dateTime); session.update(payment); returnSum = BigDecimal.ZERO; }/* w w w .j a v a 2 s .c o m*/ if (returnSum.compareTo(BigDecimal.ZERO) <= 0) { break; } } } }
From source file:com.nkapps.billing.dao.OverpaymentDaoImpl.java
private void returnStateRevert(Session session, BankStatement bs, BigDecimal overpaymentSum, Long issuerSerialNumber, String issuerIp, LocalDateTime dateTime) throws Exception { if (!bs.getBankStatementPayments().isEmpty()) { // if bankstatement has payments String q = " SELECT p.id AS id, p.tin AS tin, p.paymentNum AS paymentNum, p.paymentDate AS paymentDate," + " p.paymentSum AS paymentSum, p.sourceCode AS sourceCode," + " p.state AS state, p.tinDebtor as tinDebtor,p.claim as claim, p.issuerSerialNumber as issuerSerialNumber," + " p.issuerIp as issuerIp,p.dateCreated AS dateCreated, p.dateUpdated as dateUpdated, " + " p.paymentSum - COALESCE((SELECT SUM(paidSum) FROM KeyPayment kp WHERE kp.payment = p),0) AS overSum " + " FROM Payment p JOIN p.bankStatementPayment bsp " + " WHERE p.claim = 0 " + " AND bsp.id.bankStatement = :bs" + " ORDER BY p.paymentDate, p.paymentNum "; Query query = session.createQuery(q); query.setParameter("bs", bs); query.setResultTransformer(Transformers.aliasToBean(Payment.class)); List<Payment> paymentList = query.list(); int listSize = paymentList.size(); int currentIndex = 0; BigDecimal keyCost = new BigDecimal(bankStatementDao.getKeyCost()); for (Payment payment : paymentList) { currentIndex++;/*w w w .j a va 2 s . c o m*/ overpaymentSum = overpaymentSum.subtract(payment.getOverSum()); if (currentIndex == listSize) { if (payment.getState() == 3) { if (payment.getPaymentSum().compareTo(BigDecimal.ZERO) > 0) { payment.setState((short) 2); } else { payment.setState((short) 1); } } payment.setPaymentSum(payment.getPaymentSum().add(overpaymentSum)); payment.setIssuerSerialNumber(issuerSerialNumber); payment.setIssuerIp(issuerIp); payment.setDateUpdated(dateTime); session.update(payment); overpaymentSum = BigDecimal.ZERO; } else { if (payment.getPaymentSum().compareTo(keyCost) < 0) { BigDecimal paymentSum = payment.getPaymentSum(); if (overpaymentSum.add(paymentSum).compareTo(keyCost) <= 0) { if (payment.getState() == 3) { if (payment.getPaymentSum().compareTo(BigDecimal.ZERO) > 0) { payment.setState((short) 2); } else { payment.setState((short) 1); } } payment.setPaymentSum(overpaymentSum.add(paymentSum)); payment.setIssuerSerialNumber(issuerSerialNumber); payment.setIssuerIp(issuerIp); payment.setDateUpdated(dateTime); session.update(payment); overpaymentSum = BigDecimal.ZERO; } else { if (payment.getState() == 3) { if (payment.getPaymentSum().compareTo(BigDecimal.ZERO) > 0) { payment.setState((short) 2); } else { payment.setState((short) 1); } } payment.setPaymentSum(keyCost); payment.setIssuerSerialNumber(issuerSerialNumber); payment.setIssuerIp(issuerIp); payment.setDateUpdated(dateTime); session.update(payment); overpaymentSum = overpaymentSum.add(paymentSum).subtract(keyCost); } } } if (overpaymentSum.compareTo(BigDecimal.ZERO) <= 0) { break; } } } }
From source file:com.nkapps.billing.dao.PaymentDaoImpl.java
@Override public void saveKeyPaymentAndTransaction(BigDecimal keyTransactionId, BigDecimal keyCost) throws Exception { Session session = getSession();/*from w w w . j av a 2s.c o m*/ Transaction transaction = session.beginTransaction(); LocalDateTime dateTime = LocalDateTime.now(); KeyTransaction ktr = (KeyTransaction) session.get(KeyTransaction.class, keyTransactionId); String q = " SELECT p.id AS id, p.tin AS tin, p.paymentNum AS paymentNum, p.paymentDate AS paymentDate," + " p.paymentSum AS paymentSum, p.sourceCode AS sourceCode," + " p.state AS state, p.tinDebtor as tinDebtor,p.claim as claim, p.issuerSerialNumber as issuerSerialNumber," + " p.issuerIp as issuerIp,p.dateCreated AS dateCreated, p.dateUpdated as dateUpdated, " + " p.paymentSum - COALESCE((SELECT SUM(paidSum) FROM KeyPayment kp WHERE kp.payment = p),0) AS overSum " + " FROM Payment p " + " WHERE p.tin = :tin AND p.state IN (1,2) AND p.claim = 0" + " ORDER BY p.paymentDate, p.paymentNum "; Query query = session.createQuery(q); query.setParameter("tin", ktr.getTin()); query.setResultTransformer(Transformers.aliasToBean(Payment.class)); List<Payment> paymentList = query.list(); for (Payment payment : paymentList) { if (payment.getOverSum().compareTo(keyCost) <= 0) { KeyPayment kp = new KeyPayment(); kp.setSerialNumber(ktr.getSerialNumber()); kp.setPayment(payment); kp.setPaidSum(payment.getOverSum()); kp.setDateCreated(dateTime); kp.setDateUpdated(dateTime); session.save(kp); payment.setState((short) 3); payment.setDateUpdated(dateTime); session.update(payment); keyCost = keyCost.subtract(payment.getOverSum()); } else { KeyPayment kp = new KeyPayment(); kp.setSerialNumber(ktr.getSerialNumber()); kp.setPayment(payment); kp.setPaidSum(keyCost); kp.setDateCreated(dateTime); kp.setDateUpdated(dateTime); session.save(kp); payment.setState((short) 2); payment.setDateUpdated(dateTime); session.update(payment); keyCost = BigDecimal.ZERO; } if (keyCost.compareTo(BigDecimal.ZERO) <= 0) { break; } } ktr.setCommitted((short) 1); ktr.setDateUpdated(dateTime); session.update(ktr); transaction.commit(); session.close(); }
From source file:com.nkapps.billing.dao.PaymentDaoImpl.java
@Override public List<PaymentListPojo> getPaymentList(Map parameters) throws Exception { List<PaymentListPojo> listPojos; Session session = getSession();//from w ww .j a va2 s. c o m String whereStr = ""; if (parameters.get("searchBy") != null && !"".equals(parameters.get("searchBy"))) { whereStr += " AND (p.tin LIKE :searchBy OR p.tinDebtor LIKE :searchBy OR p.paymentNum LIKE :searchBy) "; } if (parameters.get("searchWithinDate") != null && "true".equals(parameters.get("searchWithinDate"))) { whereStr += " AND p.paymentDate = :searchByDate"; } // if (!"".equals(whereStr)) { // whereStr = " WHERE " + whereStr.substring(whereStr.indexOf("AND") + 3); // } String q = " SELECT p.id as paymentId, p.tin as tin, p.paymentNum as paymentNum, " + " p.paymentDate as paymentDate, p.paymentSum as paymentSum, " + " CASE WHEN p.state = 1 THEN '" + messageSource.getMessage("payment.state_1", null, LocaleContextHolder.getLocale()) + "' " + " ELSE CASE WHEN p.state = 2 THEN '" + messageSource.getMessage("payment.state_2", null, LocaleContextHolder.getLocale()) + "' " + " ELSE '" + messageSource.getMessage("payment.state_3", null, LocaleContextHolder.getLocale()) + "' END END as state," // + " COALESCE(p.paymentSum,0) - (SELECT COALESCE(SUM(kp.paidSum),0) FROM p.keyPayments kp WHERE p.claim = 0) AS overSum," + " s.code as sourceCode,s.name as source, p.tinDebtor as tinDebtor," + " CASE WHEN p.claim = 0 THEN '" + messageSource.getMessage("payment.claim_0", null, LocaleContextHolder.getLocale()) + "'" + " ELSE '" + messageSource.getMessage("payment.claim_1", null, LocaleContextHolder.getLocale()) + "' END as claim " + " FROM Payment p, Source s" + " WHERE p.sourceCode = s.code " + whereStr + " ORDER BY p.paymentDate, p.paymentSum "; Query query = session.createQuery(q); query.setResultTransformer(Transformers.aliasToBean(PaymentListPojo.class)); if (parameters.get("searchBy") != null && !"".equals(parameters.get("searchBy"))) { query.setString("searchBy", ("%" + (String) parameters.get("searchBy") + "%").toUpperCase()); } if (parameters.get("searchWithinDate") != null && "true".equals(parameters.get("searchWithinDate"))) { query.setParameter("searchByDate", new SimpleDateFormat("dd.MM.yyyy").parse((String) parameters.get("searchByDate"))); } Integer start = "".equals((String) parameters.get("start")) ? 0 : Integer.parseInt((String) parameters.get("start")); Integer length = "".equals((String) parameters.get("length")) ? 0 : Integer.parseInt((String) parameters.get("length")); query.setFirstResult(start).setMaxResults(length); listPojos = query.list(); session.close(); return listPojos; }
From source file:com.nkapps.billing.dao.PaymentDaoImpl.java
@Override public List<KeyPaymentListPojo> getKeyPaymentList(Map parameters) throws Exception { List<KeyPaymentListPojo> listPojos; Session session = getSession();//from w w w. j ava 2 s .co m BigDecimal paymentId = new BigDecimal((String) parameters.get("paymentId")); String q = " SELECT kp.id as keyPaymentId, kp.serialNumber as serialNumber," + " kp.paidSum as paidSum, kp.dateUpdated as dateUpdated " + " FROM KeyPayment kp JOIN kp.payment p" + " WHERE p.id = :paymentId " + " ORDER BY kp.dateUpdated DESC "; Query query = session.createQuery(q); query.setParameter("paymentId", paymentId); query.setResultTransformer(Transformers.aliasToBean(KeyPaymentListPojo.class)); Integer start = "".equals((String) parameters.get("start")) ? 0 : Integer.parseInt((String) parameters.get("start")); Integer length = "".equals((String) parameters.get("length")) ? 0 : Integer.parseInt((String) parameters.get("length")); query.setFirstResult(start).setMaxResults(length); listPojos = query.list(); session.close(); return listPojos; }
From source file:com.nkapps.billing.dao.PaymentDaoImpl.java
@Override public void updatePaymentManual(BigDecimal paymentId, String tin, String paymentNum, Date paymentDate, BigDecimal paymentSum, String tinDebtor, Long issuerSerialNumber, String issuerIp) throws Exception { Session session = getSession();//from w w w . j a v a 2s. c o m Transaction transaction = session.beginTransaction(); String q = " SELECT p.id AS id, p.tin AS tin, p.paymentNum AS paymentNum, p.paymentDate AS paymentDate," + " p.paymentSum AS paymentSum, p.sourceCode AS sourceCode," + " p.state AS state, p.tinDebtor as tinDebtor,p.claim as claim, p.issuerSerialNumber as issuerSerialNumber," + " p.issuerIp as issuerIp,p.dateCreated AS dateCreated, p.dateUpdated as dateUpdated, " + " p.paymentSum - COALESCE((SELECT SUM(paidSum) FROM KeyPayment kp WHERE kp.payment = p),0) AS overSum " + " FROM Payment p " + " WHERE p.id = :paymentId "; Query query = session.createQuery(q); query.setParameter("paymentId", paymentId); query.setResultTransformer(Transformers.aliasToBean(Payment.class)); Payment payment = (Payment) query.uniqueResult(); // checking paymentsum >= key sum - (payment.payment_sum - payment.over_sum) short state; if (paymentSum.compareTo(payment.getPaymentSum().subtract(payment.getOverSum())) <= 0) { paymentSum = payment.getPaymentSum().subtract(payment.getOverSum()); state = 3; } else { if (payment.getPaymentSum().compareTo(payment.getOverSum()) == 0) { state = 1; } else { state = 2; } } payment.setTin(tin); payment.setPaymentNum(paymentNum); payment.setPaymentDate(paymentDate); payment.setPaymentSum(paymentSum); payment.setState(state); payment.setTinDebtor(tinDebtor); payment.setIssuerSerialNumber(issuerSerialNumber); payment.setIssuerIp(issuerIp); LocalDateTime dateTime = LocalDateTime.now(); payment.setDateUpdated(dateTime); session.update(payment); transaction.commit(); session.close(); }
From source file:com.nkapps.billing.dao.PaymentDaoImpl.java
@Override public List<ClaimListPojo> getClaimList(Map parameters) throws Exception { List<ClaimListPojo> listPojos; Session session = getSession();//from w ww . j a v a2s .c o m String searchBy = (String) parameters.get("searchBy"); Query query = session.createQuery( "SELECT da.id, da.tin, da.name, da.sendDate, da.summa FROM DsApplication da WHERE da.tin LIKE :searchBy"); query.setParameter("searchBy", "%" + searchBy + "%"); query.setResultTransformer(Transformers.aliasToBean(ClaimListPojo.class)); listPojos = query.list(); session.close(); return listPojos; }
From source file:com.nkapps.billing.dao.ReportDaoImpl.java
@Override public List<ReportClickListPojo> getClickList(Map parameters) throws Exception { List<ReportClickListPojo> listPojos; Session session = getSession();/*from w w w . j a va 2 s . c o m*/ String whereStr = ""; if (parameters.get("searchWithinDate") != null && "true".equals(parameters.get("searchWithinDate"))) { whereStr += " AND rc.operationDate = :searchByDate"; } if (!"".equals(whereStr)) { whereStr = " WHERE " + whereStr.substring(whereStr.indexOf("AND") + 3); } String q = " SELECT rc.operationDate as operationDate, bs.paymentDate as bsPaymentDate," + " bs.paymentNum as bsPaymentNum, bs.paymentSum as bsPaymentSum,rc.clickPaymentSum as clickPaymentSum," + " COALESCE(bs.paymentSum,0) - COALESCE(rc.clickPaymentSum,0) as diffSum" + " FROM ReportClick rc JOIN rc.reportClickBankStatements rcbs JOIN rcbs.id.bankStatement bs" + whereStr + " ORDER BY rc.operationDate DESC "; Query query = session.createQuery(q); query.setResultTransformer(Transformers.aliasToBean(ReportClickListPojo.class)); if (parameters.get("searchWithinDate") != null && "true".equals(parameters.get("searchWithinDate"))) { query.setParameter("searchByDate", new SimpleDateFormat("dd.MM.yyyy").parse((String) parameters.get("searchByDate"))); } Integer start = "".equals((String) parameters.get("start")) ? 0 : Integer.parseInt((String) parameters.get("start")); Integer length = "".equals((String) parameters.get("length")) ? 0 : Integer.parseInt((String) parameters.get("length")); query.setFirstResult(start).setMaxResults(length); listPojos = query.list(); session.close(); return listPojos; }