List of usage examples for org.hibernate Query setParameterList
Query<R> setParameterList(int position, Object[] values);
From source file:com.nec.harvest.service.impl.BudgetPerformanceServiceImpl.java
License:Open Source License
/** {@inheritDoc} */ @Override/*from w w w . j ava2 s . c om*/ public boolean checkAvailableByOrgCodesAndMonthlyAndKmkCodeJs(List<String> orgCodes, String monthly, String... kmkCodeJs) throws ServiceException { if (CollectionUtils.isEmpty(orgCodes)) { throw new IllegalArgumentException( "Organization codes or current month in acton must not be null or empty"); } if (StringUtils.isEmpty(monthly)) { throw new IllegalArgumentException("A month must not be null or empty"); } if (ArrayUtils.isEmpty(kmkCodeJs)) { throw new IllegalArgumentException("KmkCodeJs must not be null"); } final Session session = HibernateSessionManager.getSession(); Transaction tx = null; boolean isAvailable = Boolean.FALSE; try { tx = session.beginTransaction(); StringBuilder sql = new StringBuilder("SELECT count(strcode) "); sql.append(" FROM " + TblConstants.TBL_BUDGET_PERFORMANCE); sql.append(" WHERE strcode IN (:orgCodes) "); sql.append(" AND GetSudo = (:month) "); sql.append(" AND KmkCodeJ IN (:kmkCodeJs) "); sql.append(" AND DelKbn = 2 "); Query query = repository.getSQLQuery(session, sql.toString()); query.setParameterList("orgCodes", orgCodes); query.setParameter("month", monthly); query.setParameterList("kmkCodeJs", kmkCodeJs); Object count = query.uniqueResult(); if (count != null) { isAvailable = Long.parseLong(count.toString()) > 0; } tx.commit(); } catch (SQLGrammarException | GenericJDBCException ex) { if (tx != null) { tx.rollback(); } throw new ServiceException("An exception occured while checking data for budgetperformance", ex); } finally { HibernateSessionManager.closeSession(session); } return isAvailable; }
From source file:com.nec.harvest.service.impl.BudgetPerformanceServiceImpl.java
License:Open Source License
/** {@inheritDoc} */ @Override//from www. j a v a 2 s . co m public boolean checkAvailableByOrgCodeAndMonthlyAndKmkCodeJs(String orgCode, String monthly, String... kmkCodeJs) throws ServiceException { if (StringUtils.isEmpty(orgCode)) { throw new IllegalArgumentException( "Organization code or current month in acton must not be null or empty"); } if (StringUtils.isEmpty(monthly)) { throw new IllegalArgumentException("Month must not be null or empty"); } if (ArrayUtils.isEmpty(kmkCodeJs)) { throw new IllegalArgumentException("KmkCodeJs must not be null"); } final Session session = HibernateSessionManager.getSession(); Transaction tx = null; boolean isAvailable = Boolean.FALSE; try { tx = session.beginTransaction(); StringBuilder sql = new StringBuilder("SELECT count(strcode) "); sql.append(" FROM " + TblConstants.TBL_BUDGET_PERFORMANCE); sql.append(" WHERE strcode = (:orgCodes) "); sql.append(" AND GetSudo = (:month) "); sql.append(" AND KmkCodeJ IN (:kmkCodeJs) "); sql.append(" AND DelKbn = 2 "); Query query = repository.getSQLQuery(session, sql.toString()); query.setParameter("orgCodes", orgCode); query.setParameter("month", monthly); query.setParameterList("kmkCodeJs", kmkCodeJs); Object count = query.uniqueResult(); if (count != null) { isAvailable = Long.parseLong(count.toString()) > 0; } tx.commit(); } catch (SQLGrammarException | GenericJDBCException ex) { if (tx != null) { tx.rollback(); } throw new ServiceException("An exception occured while checking data for budgetperformance", ex); } finally { HibernateSessionManager.closeSession(session); } return isAvailable; }
From source file:com.nec.harvest.service.impl.InventoryServiceImpl.java
License:Open Source License
/** {@inheritDoc} */ @Override//from w w w . ja va2 s . c o m public double calculateInventoryByOrgCodesAndMonth(String month, String... orgCodes) throws ServiceException { if (ArrayUtils.isEmpty(orgCodes)) { throw new IllegalArgumentException( "Calculation inventory price cannot implement with organization code null"); } if (StringUtils.isEmpty(month)) { throw new IllegalArgumentException( "Calculation inventory amount cannot implement with current month null"); } final Session session = HibernateSessionManager.getSession(); Transaction tx = null; double amountOfInventory = 0; try { tx = session.beginTransaction(); StringBuffer sql = new StringBuffer(" SELECT TRUNCATE(SUM(Kingaku)/1000, 0) "); sql.append(" FROM " + TblConstants.TBL_INVENTORY); sql.append(" WHERE StrCode IN (:orgCodes) AND GetSudo=:month AND DelKbn=2"); Query query = repository.getSQLQuery(session, sql.toString()); query.setParameterList("orgCodes", orgCodes); query.setString("month", month); Object amount = query.uniqueResult(); // Release transaction tx.commit(); if (amount == null) { throw new ObjectNotFoundException( "Could not find any object in monthly " + month + " for the organization " + orgCodes); } amountOfInventory = Double.valueOf(amount.toString()); } catch (SQLGrammarException | GenericJDBCException ex) { if (tx != null) { tx.rollback(); } throw new ServiceException( "Runtime exception occur when calculate inventory price for multi-organization in a month"); } finally { HibernateSessionManager.closeSession(session); } return amountOfInventory; }
From source file:com.nec.harvest.service.impl.InventoryServiceImpl.java
License:Open Source License
/** {@inheritDoc} */ @Override/*from w w w. ja v 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.netsteadfast.greenstep.base.dao.BaseDAO.java
License:Apache License
@SuppressWarnings({ "unchecked", "rawtypes" }) private void setQueryParamsOfList(Query query, String position, List listParams) { if (listParams == null || listParams.size() < 1) { return;/*w w w .j a va 2 s . c o m*/ } if (listParams.get(0) instanceof String) { query.setParameterList(position, (List<String>) listParams); return; } if (listParams.get(0) instanceof Character) { query.setParameterList(position, (List<Character>) listParams); return; } if (listParams.get(0) instanceof BigDecimal) { query.setParameterList(position, (List<BigDecimal>) listParams); return; } if (listParams.get(0) instanceof Integer) { query.setParameterList(position, (List<Integer>) listParams); return; } if (listParams.get(0) instanceof Long) { query.setParameterList(position, (List<Long>) listParams); return; } }
From source file:com.netsteadfast.greenstep.bsc.dao.impl.KpiDAOImpl.java
License:Apache License
private void setQueryMixDataParameter(Query query, Map<String, Object> paramMap) { for (Map.Entry<String, Object> entry : paramMap.entrySet()) { if (entry.getValue() != null && entry.getValue() instanceof String) { query.setString(entry.getKey(), String.valueOf(entry.getValue())); }/*from w ww.j a v a 2 s. c o m*/ if (entry.getValue() != null && entry.getValue() instanceof List) { query.setParameterList(entry.getKey(), (List<?>) entry.getValue()); } } }
From source file:com.neu.web.phmis.dao.ResourceDao.java
public List<SurgeryRequestBean> getSurgeryRequests(EnterpriseBean enterpriseBean, RoleBean roleBean) { List<SurgeryRequestBean> surgeryRequestList = null; try {//from w w w . ja v a 2 s . c o m session = HibernateUtil.getSessionFactory().openSession(); Query query = session .createQuery("from UserBean where enterpriseBean = :enterpriseBean and roleBean = :roleBean"); query.setEntity("enterpriseBean", enterpriseBean); query.setEntity("roleBean", roleBean); List<UserBean> userList = query.list(); query = session.createQuery("from SurgeryRequestBean where createdBy IN (:list)"); query.setParameterList("list", userList); surgeryRequestList = query.list(); } catch (HibernateException e) { surgeryRequestList = null; e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { session.close(); return surgeryRequestList; } }
From source file:com.nominanuda.hibernate.AbstractHibernateStructStore.java
License:Apache License
protected void bind(Query q, String k, Object v) { DataType t = struct.getDataType(v);//from w ww . jav a 2 s. co m switch (t) { case array: q.setParameterList(k, struct.toMapsAndSetLists((DataArray) v)); break; case object: q.setEntity(k, struct.toMapsAndSetLists((DataObject) v)); break; case string: q.setString(k, (String) v); break; case bool: q.setBoolean(k, (Boolean) v); break; case number: Double d = ((Number) v).doubleValue(); if (Maths.isInteger(d)) { q.setLong(k, d.longValue()); } else { q.setDouble(k, d); } break; default: throw new IllegalArgumentException(t.name()); } }
From source file:com.oracle.coherence.hibernate.cachestore.HibernateCacheLoader.java
License:CDDL license
/** * Load a collection of Hibernate entities given a set of ids (keys) * * @param keys the cache keys; specifically, the entity ids * * @return the corresponding Hibernate entity instances *//*from w ww . jav a 2 s . co m*/ public Map loadAll(Collection keys) { ensureInitialized(); Map results = new HashMap(); Transaction tx = null; Session session = openSession(); SessionImplementor sessionImplementor = (SessionImplementor) session; try { tx = session.beginTransaction(); // Create the query String sQuery = getLoadAllQuery(); Query query = session.createQuery(sQuery); // Prevent Hibernate from caching the results query.setCacheMode(CacheMode.IGNORE); query.setCacheable(false); query.setReadOnly(true); // Parameterize the query (where :keys = keys) query.setParameterList(PARAM_IDS, keys); // Need a way to extract the key from an entity that we know // nothing about. ClassMetadata classMetaData = getEntityClassMetadata(); // Iterate through the results and place into the return map for (Iterator iter = query.list().iterator(); iter.hasNext();) { Object entity = iter.next(); Object id = classMetaData.getIdentifier(entity, sessionImplementor); results.put(id, entity); } tx.commit(); } catch (Exception e) { if (tx != null) { tx.rollback(); } throw ensureRuntimeException(e); } finally { closeSession(session); } return results; }
From source file:com.project.framework.dao.GenericDao.java
License:Apache License
/** * id?//from www . j a v a 2 s . c o m * * @param ids id */ public void deleteById(final List<ID> ids) { Assert.notNull(ids, "ids Can not NULL"); final String queryString = "delete from " + entityClass.getSimpleName() + " as model where model." + getIdName() + " in(:ids)"; Query query = createQuery(queryString); query.setParameterList("ids", ids); int result = query.executeUpdate(); logger.debug("batch delete {}, number of rows affected: {}", entityClass.getSimpleName(), result); }