Example usage for org.hibernate Query setResultTransformer

List of usage examples for org.hibernate Query setResultTransformer

Introduction

In this page you can find the example usage for org.hibernate Query setResultTransformer.

Prototype

@Deprecated
Query<R> setResultTransformer(ResultTransformer transformer);

Source Link

Document

Set a strategy for handling the query results.

Usage

From source file:com.nec.harvest.service.impl.InventoryServiceImpl.java

License:Open Source License

/** {@inheritDoc} */
@Override/*ww  w . j a v a  2s .com*/
public Map<String, Double> findByOrgCodeAndPeriodMonthly(String strCode, String startMonth, String endMonth)
        throws ServiceException {
    if (StringUtils.isEmpty(strCode)) {
        throw new IllegalArgumentException("Organization's code must not be null or empty");
    }
    if (StringUtils.isEmpty(startMonth)) {
        throw new IllegalArgumentException("Year must not be null or empty");
    }
    if (StringUtils.isEmpty(endMonth)) {
        throw new IllegalArgumentException("Year must not be null or empty");
    }

    final Session session = HibernateSessionManager.getSession();
    Transaction tx = null;

    Map<String, Double> mapInventoryes = new HashMap<String, Double>();
    try {
        tx = session.beginTransaction();
        StringBuilder sql = new StringBuilder(" SELECT getSudo, SUM(c.Kingaku) as kingaku FROM AT015 c ");
        sql.append(
                " WHERE c.strCode = :strCode AND c.getSudo >= :startMonth AND c.getSudo <= :endtMonth AND c.delKbn =2 ");
        sql.append(" GROUP BY c.getSudo");

        // create query
        Query query = repository.getSQLQuery(session, sql.toString());
        query.setParameter("strCode", strCode);
        query.setParameter("startMonth", startMonth);
        query.setParameter("endtMonth", endMonth);
        query.setResultTransformer(Transformers.aliasToBean(InventoryBean.class));

        List<InventoryBean> inventories = query.list();
        // Release transaction
        tx.commit();
        if (CollectionUtils.isEmpty(inventories)) {
            throw new ObjectNotFoundException("Could not found any inventory in the DB");
        }

        for (InventoryBean inventoryBean : inventories) {
            mapInventoryes.put(inventoryBean.getGetSudo(), inventoryBean.getKingaku());
        }
    } catch (SQLGrammarException | GenericJDBCException ex) {
        if (tx != null) {
            tx.rollback();
        }
        throw new ServiceException("An exception occured while getting for the given organization " + strCode
                + " startMonth " + startMonth + " endMonth " + endMonth, ex);
    } finally {
        HibernateSessionManager.closeSession(session);
    }
    return mapInventoryes;
}

From source file:com.nec.harvest.service.impl.InventoryServiceImpl.java

License:Open Source License

/** {@inheritDoc} */
@Override// w w w. jav a2 s  . co m
public Map<String, Double> findByPeriodMonthAndOrgCodes(String startMonth, String endMonth,
        List<String> strCodes) throws ServiceException {
    if (CollectionUtils.isEmpty(strCodes)) {
        throw new IllegalArgumentException("Organization's codes must not be null or empty");
    }
    if (StringUtils.isEmpty(startMonth)) {
        throw new IllegalArgumentException("Year must not be null or empty");
    }
    if (StringUtils.isEmpty(endMonth)) {
        throw new IllegalArgumentException("Year must not be null or empty");
    }

    final Session session = HibernateSessionManager.getSession();
    Transaction tx = null;

    Map<String, Double> mapInventoryes = new HashMap<String, Double>();
    try {
        tx = session.beginTransaction();
        StringBuilder sql = new StringBuilder(" SELECT getSudo, SUM(c.Kingaku) as kingaku FROM AT015 c ");
        sql.append(
                " WHERE c.strCode in (:strCode) AND c.getSudo >= :startMonth AND c.getSudo <= :endtMonth AND c.delKbn =2 ");
        sql.append(" GROUP BY c.getSudo");

        // create query
        Query query = repository.getSQLQuery(session, sql.toString());
        query.setParameterList("strCode", strCodes);
        query.setParameter("startMonth", startMonth);
        query.setParameter("endtMonth", endMonth);
        query.setResultTransformer(Transformers.aliasToBean(InventoryBean.class));

        List<InventoryBean> inventories = query.list();
        // Release transaction
        tx.commit();
        if (CollectionUtils.isEmpty(inventories)) {
            throw new ObjectNotFoundException("Could not found any inventory in the DB");
        }

        // put amount in map value and final tighten date is map key
        for (InventoryBean inventoryBean : inventories) {
            mapInventoryes.put(inventoryBean.getGetSudo(), inventoryBean.getKingaku());
        }
    } catch (SQLGrammarException | GenericJDBCException ex) {
        if (tx != null) {
            tx.rollback();
        }
        throw new ServiceException("An exception occured while getting for the given organization "
                + StringUtils.join(strCodes, ",") + " startMonth " + startMonth + " endMonth " + endMonth, ex);
    } finally {
        HibernateSessionManager.closeSession(session);
    }
    return mapInventoryes;
}

From source file:com.nec.harvest.service.impl.InventoryServiceImpl.java

License:Open Source License

/** {@inheritDoc} */
@Override/*from   ww w  .ja  va2s. com*/
public List<ActualViewBean> findDataBeansByOrgCodeAndMonthly(String orgCode, String monthly)
        throws ServiceException {
    if (StringUtils.isEmpty(orgCode)) {
        throw new IllegalArgumentException("Orginazation's code must not be null or empty");
    }
    if (StringUtils.isEmpty(monthly)) {
        throw new IllegalArgumentException("Month must not be null or empty");
    }

    final Session session = HibernateSessionManager.getSession();
    Transaction tx = null;

    List<ActualViewBean> jisekiBeans = new ArrayList<>();
    try {
        tx = session.beginTransaction();
        Query query = repository.getQuery(session, " SELECT "
                + " a.pk.category.ctgCode as ctgCode, a.pk.category.ctgNameR as ctgNameR, a.kingaku as kingaku, a.updNo as updNo "
                + " FROM Inventory a "
                + " WHERE a.delKbn = :delKbn AND a.pk.organization.strCode = :strCode AND a.pk.getSudo = :getSudo ");
        query.setParameter("strCode", orgCode);
        query.setParameter("getSudo", monthly);
        query.setParameter("delKbn", Constants.STATUS_ACTIVE);
        query.setResultTransformer(Transformers.aliasToBean(ActualViewBean.class));

        // 
        jisekiBeans = query.list();
        tx.commit();
    } catch (HibernateException ex) {
        if (tx != null) {
            tx.rollback();
        }
        throw new ServiceException("An error occurred while finding the Inventory Data by organization "
                + orgCode + " and monthly " + monthly);
    } finally {
        HibernateSessionManager.closeSession(session);
    }
    return jisekiBeans;
}

From source file:com.nec.harvest.service.impl.MonthlySalesServiceImpl.java

License:Open Source License

/** {@inheritDoc} */
@Override/*from w w  w.  j  a  v a  2s .  c  o m*/
@SuppressWarnings("unchecked")
public List<ActualViewBean> findDataBeansByOrgCodeAndMonthly(String orgCode, String monthly, String ugKbn)
        throws ServiceException {
    if (StringUtils.isEmpty(orgCode)) {
        throw new IllegalArgumentException("Orginazation's code must not be null or empty");
    }
    if (StringUtils.isEmpty(monthly)) {
        throw new IllegalArgumentException("Month must not be null or empty");
    }

    final Session session = HibernateSessionManager.getSession();
    Transaction tx = null;

    List<ActualViewBean> jisekiBeans = new ArrayList<ActualViewBean>();
    try {
        tx = session.beginTransaction();
        Query query = repository.getQuery(session, " SELECT "
                + " a.pk.category.ctgCode as ctgCode, a.pk.category.ctgNameR as ctgNameR, a.kingaku as kingaku, a.updNo as updNo, a.pk.ugKbn as ugKbn "
                + " FROM MonthlySales a "
                + " WHERE a.delKbn = :delKbn AND a.pk.organization.strCode = :strCode AND a.pk.getSudo = :getSudo AND a.pk.ugKbn = :ugKbn ");
        query.setParameter("strCode", orgCode);
        query.setParameter("getSudo", monthly);
        query.setParameter("ugKbn", ugKbn);
        query.setParameter("delKbn", Constants.STATUS_ACTIVE);
        query.setResultTransformer(Transformers.aliasToBean(ActualViewBean.class));

        jisekiBeans = query.list();
        tx.commit();
    } catch (HibernateException ex) {
        if (tx != null) {
            tx.rollback();
        }
        throw new ServiceException("An error occurred while finding the monthly Sales Data by organization "
                + orgCode + " and monthly " + monthly);
    } finally {
        HibernateSessionManager.closeSession(session);
    }
    return jisekiBeans;
}

From source file:com.nec.harvest.service.impl.OrganizationServiceImpl.java

License:Open Source License

/** {@inheritDoc} */
@Override// w w w.java  2s . c  o m
@SuppressWarnings("unchecked")
public PettyCashBookReport findDistrictByShop(String shopID) throws ServiceException {
    if (StringUtils.isEmpty(shopID)) {
        throw new IllegalArgumentException("ShopID?NULL???????");
    }

    final Session session = HibernateSessionManager.getSession();
    Transaction tx = null;

    PettyCashBookReport organization = null;
    try {
        tx = session.beginTransaction();
        Query query = repository.getSQLQuery(session, SqlConstants.SQL_FIND_ORGANIZATION_BY_SHOP);
        query.setParameter("StrCode", shopID);
        query.setResultTransformer(Transformers.aliasToBean(PettyCashBookReport.class));
        List<PettyCashBookReport> organizations = query.list();
        // Release transaction
        tx.commit();
        if (CollectionUtils.isEmpty(organizations)) {
            throw new ObjectNotFoundException(
                    " " + shopID + "???????? ");
        }
        organization = organizations.get(0);
    } catch (SQLGrammarException | GenericJDBCException ex) {
        if (tx != null) {
            tx.rollback();
        }
        throw new ServiceException("An exception occured while finding Organization list with ShopID " + shopID,
                ex);
    } finally {
        HibernateSessionManager.closeSession(session);
    }
    return organization;
}

From source file:com.nec.harvest.service.impl.PurchaseServiceImlp.java

License:Open Source License

/** {@inheritDoc} */
@Override//from  w  w  w.j ava 2  s. c  om
@SuppressWarnings("unchecked")
public List<ActualViewBean> findDataBeansByOrgCodeAndMonthly(String orgCode, String monthly, String bunruiKbn)
        throws ServiceException {
    if (StringUtils.isEmpty(orgCode)) {
        throw new IllegalArgumentException("Orginazation's code must not be null or empty");
    }

    if (StringUtils.isEmpty(monthly)) {
        throw new IllegalArgumentException("Month must not be null or empty");
    }

    if (StringUtils.isEmpty(bunruiKbn)) {
        throw new IllegalArgumentException("bunruiKbn must not be null or empty");
    }

    final Session session = HibernateSessionManager.getSession();
    Transaction tx = null;

    List<ActualViewBean> jisekiBeans = new ArrayList<ActualViewBean>();
    try {
        tx = session.beginTransaction();
        Query query = repository.getQuery(session, " SELECT "
                + " a.pk.category.ctgCode as ctgCode, a.pk.category.ctgNameR as ctgNameR, a.kingaku as kingaku, a.updNo as updNo, a.pk.vendor.srsCode as srsCode, a.pk.vendor.srsNameR as srsNameR "
                + " FROM MonthlyPurchase a "
                + " WHERE a.delKbn = :delKbn AND a.pk.organization.strCode = :strCode AND a.pk.getSudo = :getSudo "
                + " AND a.pk.category.bunruiKbn = :bunruiKbn ");
        query.setParameter("strCode", orgCode);
        query.setParameter("getSudo", monthly);
        query.setParameter("delKbn", Constants.STATUS_ACTIVE);
        query.setParameter("bunruiKbn", bunruiKbn);
        query.setResultTransformer(Transformers.aliasToBean(ActualViewBean.class));

        // 
        jisekiBeans = query.list();
        tx.commit();
    } catch (HibernateException ex) {
        if (tx != null) {
            tx.rollback();
        }
        throw new ServiceException("An error occurred while finding the Purchase Data by organization "
                + orgCode + " and monthly " + monthly);
    } finally {
        HibernateSessionManager.closeSession(session);
    }
    return jisekiBeans;
}

From source file:com.nec.harvest.service.impl.SmallCategoryServiceImpl.java

License:Open Source License

/** {@inheritDoc} */
@Override//from ww  w.  j  ava2  s  .c  om
public List<SmallCategory> findByClassify(String classifyCategory) throws ServiceException {
    if (StringUtils.isEmpty(classifyCategory)) {
        throw new IllegalArgumentException("The category classify must not be empty");
    }

    final Session session = HibernateSessionManager.getSession();
    Transaction tx = null;

    List<SmallCategory> smallCategories = new ArrayList<SmallCategory>();
    try {
        tx = session.beginTransaction();
        Query query = repository.getNamedQuery(session, SqlConstants.SQL_FIND_SMALL_CATEGORY);
        query.setResultTransformer(Transformers.aliasToBean(SmallCategory.class));
        smallCategories = repository.findByQuery(query);

        // Release transaction
        tx.commit();
    } catch (HibernateException ex) {
        if (tx != null) {
            tx.rollback();
        }
        throw new ServiceException(
                "Hibernate runtime exception occur when get small category with its classify "
                        + classifyCategory,
                ex);
    } finally {
        HibernateSessionManager.closeSession(session);
    }
    return smallCategories;
}

From source file:com.nkapps.billing.dao.BankStatementDaoImpl.java

@Override
public List<BankStatementListPojo> list(HashMap parameters) throws Exception {
    List<BankStatementListPojo> listPojos;
    Session session = getSession();/*from   w  w  w .  j a va  2 s  .  c  o m*/

    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.mfo AS mfo,bs.chet AS chet,"
            + " bs.paymentNum AS paymentNum, bs.paymentDate AS paymentDate, bs.paymentSum AS paymentSum,"
            + " bs.paymentDetails AS paymentDetails," + " bs.transfered AS transfered,"
            + " bs.dateUpdated AS dateUpdated" + " FROM BankStatement bs" + whereStr
            + " ORDER BY bs.paymentDate, bs.paymentSum ";
    Query query = session.createQuery(q);
    query.setResultTransformer(Transformers.aliasToBean(BankStatementListPojo.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.BankStatementDaoImpl.java

@Override
public List<PrintClaimPojo> getPrintClaimList(Date periodStart, Date periodEnd) throws Exception {
    Session session = getSession();/*from w  ww.ja  v a  2 s. c  o  m*/
    String q = " SELECT bs.tin as tin, bs.mfo as mfo," + " bs.chet as chet, bs.paymentNum as paymentNum,"
            + " bs.paymentDate as paymentDate, p.paymentSum as paymentSum,"
            + " bs.paymentDetails as paymentDetails "
            + " FROM BankStatement bs JOIN bs.bankStatementPayments bsp JOIN bsp.id.payment p"
            + " WHERE p.claim = 1 AND bs.paymentDate BETWEEN :periodStart AND :periodEnd "
            + " ORDER BY bs.paymentDate, bs.paymentSum";
    Query query = session.createQuery(q);
    query.setParameter("periodStart", periodStart);
    query.setParameter("periodEnd", periodEnd);
    query.setResultTransformer(Transformers.aliasToBean(PrintClaimPojo.class));
    List<PrintClaimPojo> listPojo = query.list();
    session.close();

    return listPojo;
}

From source file:com.nkapps.billing.dao.BankStatementDaoImpl.java

@Override
public List<PrintRegisterPojo> getPrintRegisterList(Date periodStart, Date periodEnd) throws Exception {
    Session session = getSession();//from   w w  w.  j  a  v a  2  s .  c o  m
    String q = " SELECT bs.invoiceNum as invoiceNum,"
            + " bs.paymentNum as paymentNum, bs.paymentDate as paymentDate,"
            + " bs.tin as tin, bs.name as name, bs.paymentSum as paymentSum " + " FROM BankStatement bs"
            + " WHERE bs.paymentDate BETWEEN :periodStart AND :periodEnd"
            + " AND bs.tin <> '201589463' AND bs.invoiceNum < 1000000" + " ORDER BY bs.invoiceNum";
    Query query = session.createQuery(q);
    query.setParameter("periodStart", periodStart);
    query.setParameter("periodEnd", periodEnd);
    query.setResultTransformer(Transformers.aliasToBean(PrintRegisterPojo.class));
    List<PrintRegisterPojo> listPojo = query.list();
    session.close();

    return listPojo;
}