List of usage examples for org.hibernate.transform Transformers aliasToBean
public static ResultTransformer aliasToBean(Class target)
From source file:com.nec.harvest.service.impl.InventoryServiceImpl.java
License:Open Source License
/** {@inheritDoc} */ @Override// ww w . ja v a2 s . c o m public List<InventoryBean> findByOrgCodeAndMonth(String orgCode, String monthly) throws ServiceException { if (StringUtils.isEmpty(orgCode)) { throw new IllegalArgumentException("Organization's code must not be null or empty"); } if (StringUtils.isEmpty(monthly)) { throw new IllegalArgumentException("Monthly must not be null or empty"); } final Session session = HibernateSessionManager.getSession(); Transaction tx = null; List<InventoryBean> inventories = new ArrayList<>(); try { tx = session.beginTransaction(); StringBuffer sql = new StringBuffer( "SELECT a.CtgCode as ctgCode, a.Kingaku as kingaku, a.UpdNo as updNo, b.CtgNameR as ctgName FROM "); sql.append( " AT015 a, AT114 b WHERE a.Getsudo =:getSudo and a.StrCode =:strCode AND a.CtgCode = b.CtgCode "); sql.append(" AND a.DelKbn = 2 ORDER BY ctgCode ASC"); // Query query = repository.getSQLQuery(session, sql.toString()); query.setParameter("strCode", orgCode); query.setParameter("getSudo", monthly); query.setResultTransformer(Transformers.aliasToBean(InventoryBean.class)); inventories = query.list(); // Release transaction tx.commit(); if (CollectionUtils.isEmpty(inventories)) { throw new ObjectNotFoundException( "Could not find any object in monthly " + monthly + " for the organization " + orgCode); } } catch (SQLGrammarException | GenericJDBCException ex) { if (tx != null) { tx.rollback(); } throw new ServiceException("An exception occured while get inventory data ", ex); } finally { HibernateSessionManager.closeSession(session); } return inventories; }
From source file:com.nec.harvest.service.impl.InventoryServiceImpl.java
License:Open Source License
/** {@inheritDoc} */ @Override/*from w ww . ja va2s . c o m*/ public List<InventoryBean> findByOrgCodeAndMonthAndBunruiKbn(String orgCode, String monthly, String bunruiKbn) throws ServiceException { if (StringUtils.isEmpty(orgCode)) { throw new IllegalArgumentException("Organization's code must not be null or empty"); } if (StringUtils.isEmpty(monthly)) { throw new IllegalArgumentException("Monthly 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<InventoryBean> inventories = new ArrayList<>(); try { tx = session.beginTransaction(); StringBuffer sql = new StringBuffer( "SELECT a.CtgCode as ctgCode, a.Kingaku as kingaku, a.UpdNo as updNo, b.CtgNameR as ctgName FROM "); sql.append( " AT015 a, AT114 b WHERE a.Getsudo =:getSudo and a.StrCode =:strCode AND a.CtgCode = b.CtgCode AND b.BunruiKbn = :bunruiKbn "); sql.append(" AND a.DelKbn = 2 AND b.DelKbn = 2 ORDER BY ctgCode ASC"); // Query query = repository.getSQLQuery(session, sql.toString()); query.setParameter("strCode", orgCode); query.setParameter("getSudo", monthly); query.setParameter("bunruiKbn", bunruiKbn); query.setResultTransformer(Transformers.aliasToBean(InventoryBean.class)); inventories = query.list(); // Release transaction tx.commit(); if (CollectionUtils.isEmpty(inventories)) { throw new ObjectNotFoundException( "Could not find any object in monthly " + monthly + " for the organization " + orgCode); } } catch (SQLGrammarException | GenericJDBCException ex) { if (tx != null) { tx.rollback(); } throw new ServiceException("An exception occured while get inventory data ", ex); } finally { HibernateSessionManager.closeSession(session); } return inventories; }
From source file:com.nec.harvest.service.impl.InventoryServiceImpl.java
License:Open Source License
/** {@inheritDoc} */ @Override/*from w w 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//from www.j a v a 2s .c om 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 w w w . j a v a2 s . c om 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.MenuGroupServiceImpl.java
License:Open Source License
/** {@inheritDoc} */ @Override// www. ja va 2s.c o m @SuppressWarnings("unchecked") public List<ProcessGroupBean> findAllGroups() throws ServiceException { final Session session = HibernateSessionManager.getSession(); Transaction tx = null; List<ProcessGroupBean> processGroupBeans = new ArrayList<>(); try { tx = session.beginTransaction(); Query query = repository .getQuery(session, "SELECT a.proGName FROM AT108 a GROUP BY a.proGName ORDER BY a.proGName DESC") .setResultTransformer(Transformers.aliasToBean(ProcessGroupBean.class)); processGroupBeans = query.list(); tx.commit(); } catch (HibernateException ex) { if (tx != null) { tx.rollback(); } throw new ServiceException("An error occurred when getting all groups", ex); } finally { HibernateSessionManager.closeSession(session); } return processGroupBeans; }
From source file:com.nec.harvest.service.impl.MonthlySalesServiceImpl.java
License:Open Source License
/** {@inheritDoc} */ @Override/*from w w w . j av a 2 s .com*/ @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/*ww w . j a v a 2s. c o m*/ public List<Organization> findByKaisoBango(String kaisoBango) throws ServiceException { if (StringUtils.isEmpty(kaisoBango)) { throw new IllegalArgumentException("The organization's code must not be null or empty"); } final Session session = HibernateSessionManager.getSession(); Transaction tx = null; List<Organization> organizations = new ArrayList<Organization>(); try { tx = session.beginTransaction(); Criteria criteria = repository.getCriteria(session, Organization.class) .setProjection(Projections.projectionList().add(Projections.property("strCode").as("strCode")) .add(Projections.property("strNameR").as("strNameR"))) .add(Restrictions.eq("kaisoBango", kaisoBango)) .add(Restrictions.eq("delKbn", Constants.STATUS_ACTIVE)) .setResultTransformer(Transformers.aliasToBean(Organization.class)); // organizations = repository.findByCriteria(criteria); // Release transaction tx.commit(); if (CollectionUtils.isEmpty(organizations)) { throw new ObjectNotFoundException("Could not find any Organization with kaisoBango " + kaisoBango); } // sort organizations by code value Collections.sort(organizations); } catch (HibernateException ex) { if (tx != null) { tx.rollback(); } throw new ServiceException( "An exception occured while finding Organization list with kaisoBango " + kaisoBango, ex); } finally { HibernateSessionManager.closeSession(session); } return organizations; }
From source file:com.nec.harvest.service.impl.OrganizationServiceImpl.java
License:Open Source License
/** {@inheritDoc} */ @Override//from w w w .jav a 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.PettyCashServiceImpl.java
License:Open Source License
/** {@inheritDoc} */ @Override// www. j a v a 2s. com public List<PettyCash> findByOrgCodeAndBusinessDay(String orgCode, String getSudo) throws ServiceException { if (StringUtils.isEmpty(orgCode)) { throw new IllegalArgumentException("Organization must not be null or empty"); } if (StringUtils.isEmpty(getSudo)) { throw new IllegalArgumentException("Business day must not be null or empty"); } final Session session = HibernateSessionManager.getSession(); Transaction tx = null; List<PettyCash> pettyCashes = new ArrayList<PettyCash>(); try { tx = session.beginTransaction(); Query query = pettyCashRepository .getNamedQuery(session, SqlConstants.SQL_FIND_PETTY_CASH_BY_ORG_CODE_AND_BUSINESS_DAY) .setString("strCode", orgCode).setString("getSudo", getSudo) .setResultTransformer(Transformers.aliasToBean(PettyCash.class)); pettyCashes = pettyCashRepository.findByQuery(query); tx.commit(); } catch (HibernateException ex) { if (tx != null) { tx.rollback(); } throw new ServiceException( "Hibernate runtime exception occur when get petty cashes with organization code..." + orgCode + " and business day " + getSudo, ex); } finally { HibernateSessionManager.closeSession(session); } return pettyCashes; }