List of usage examples for org.hibernate Query setParameterList
Query<R> setParameterList(int position, Object[] values);
From source file:com.duroty.application.mail.manager.MailManager.java
License:Open Source License
/** * DOCUMENT ME!/*from w w w .j a v a2s. c o m*/ * * @param hsession DOCUMENT ME! * @param repositoryName DOCUMENT ME! * @param mids DOCUMENT ME! * @param flag DOCUMENT ME! * * @throws MailException DOCUMENT ME! */ public void flagMessages(Session hsession, String repositoryName, String[] mids, String flag) throws MailException { if ((mids == null) || (mids.length == 0)) { throw new MailException("ErrorMessages.messages.selection.null"); } try { Query query = null; if (flag.equals("RECENT")) { query = hsession.getNamedQuery("recent-messages-by-mid"); } else if (flag.equals("FLAGGED")) { query = hsession.getNamedQuery("flagged-messages-by-mid"); } query.setParameterList("mids", mids); query.setString("username", repositoryName); query.executeUpdate(); hsession.flush(); } catch (Exception e) { throw new MailException(e); } finally { GeneralOperations.closeHibernateSession(hsession); } }
From source file:com.dz.module.contract.ContractDaoImpl.java
@Override public int selectAllByStatesCount(Contract contract, Vehicle vehicle, Driver driver, Date beginDate, Date endDate, Short[] states) { Session session = null;/*from ww w .j a v a 2 s .c o m*/ try { session = HibernateSessionFactory.getSession(); String hql = "select count(*) from Contract c where c.state in (:states)"; if (beginDate != null) { hql += " and c.contractBeginDate >= :beginDate"; } if (endDate != null) { hql += " and c.contractBeginDate <= :endDate"; } if (contract != null) { if (!StringUtils.isEmpty(contract.getIdNum())) { hql += " and c.idNum like :idNum"; } if (!StringUtils.isEmpty(contract.getCarNum())) { hql += " and c.carNum like :carNum"; } } Query query = session.createQuery(hql); if (beginDate != null) { query.setDate("beginDate", beginDate); } if (endDate != null) { query.setDate("endDate", endDate); } if (contract != null) { if (!StringUtils.isEmpty(contract.getIdNum())) { query.setString("idNum", "%" + contract.getIdNum() + "%"); } if (!StringUtils.isEmpty(contract.getCarNum())) { query.setString("carNum", "%" + contract.getCarNum() + "%"); } } query.setParameterList("states", states); return Integer.parseInt(query.uniqueResult().toString()); } catch (HibernateException e) { throw e; } finally { HibernateSessionFactory.closeSession(); } }
From source file:com.dz.module.contract.ContractDaoImpl.java
@SuppressWarnings("unchecked") @Override//w w w . ja v a 2 s .c o m public List<Contract> selectAllByStates(Page page, Contract contract, Vehicle vehicle, Driver driver, Date beginDate, Date endDate, Short[] states) { Session session = null; try { session = HibernateSessionFactory.getSession(); String hql = "from Contract c where c.state in (:states)"; if (beginDate != null) { hql += " and c.contractBeginDate >= :beginDate"; } if (endDate != null) { hql += " and c.contractBeginDate <= :endDate"; } if (contract != null) { if (!StringUtils.isEmpty(contract.getIdNum())) { hql += " and c.idNum like :idNum"; } if (!StringUtils.isEmpty(contract.getCarNum())) { hql += " and c.carNum like :carNum"; } } Query query = session.createQuery(hql); if (beginDate != null) { query.setDate("beginDate", beginDate); } if (endDate != null) { query.setDate("endDate", endDate); } if (contract != null) { if (!StringUtils.isEmpty(contract.getIdNum())) { query.setString("idNum", "%" + contract.getIdNum() + "%"); } if (!StringUtils.isEmpty(contract.getCarNum())) { query.setString("carNum", "%" + contract.getCarNum() + "%"); } } query.setParameterList("states", states); if (page != null) { query.setMaxResults(page.getEveryPage()); query.setFirstResult(page.getBeginIndex()); } return query.list(); } catch (HibernateException e) { throw e; } finally { HibernateSessionFactory.closeSession(); } }
From source file:com.dz.module.driver.complain.ComplainDaoImpl.java
@Override public int selectAllByStatesCount(Complain complain, Date beginDate, Date endDate, String dept, Short[] states) {//from w w w . j a v a 2 s . c o m // System.out.println("ComplainDaoImpl.selectAllByStatesCount(),"+complain); Session session = null; try { session = HibernateSessionFactory.getSession(); String hql = "select count(*) from Complain c where c.state in (:states)"; if (beginDate != null) { hql += " and c.complainTime >= :beginDate"; } if (endDate != null) { hql += " and c.complainTime <= :endDate"; } if (!StringUtils.isEmpty(dept)) { hql += " and c.vehicleId in (select carframeNum from Vehicle where dept like :dept) "; } if (complain != null) { if (!StringUtils.isEmpty(complain.getComplainClass())) { hql += " and c.complainClass like :complainClass"; } if (!StringUtils.isEmpty(complain.getComplainObject())) { hql += " and c.complainObject like :complainObject"; } } System.out.println(hql); Query query = session.createQuery(hql); if (beginDate != null) { query.setDate("beginDate", beginDate); } if (endDate != null) { query.setDate("endDate", endDate); } if (!StringUtils.isEmpty(dept)) { query.setString("dept", "%" + dept + "%"); } query.setParameterList("states", states); if (complain != null) { if (!StringUtils.isEmpty(complain.getComplainClass())) { query.setString("complainClass", "%" + complain.getComplainClass() + "%"); } if (!StringUtils.isEmpty(complain.getComplainObject())) { query.setString("complainObject", "%" + complain.getComplainObject() + "%"); } } //Query query = session.createQuery("select count(*) from Complain c where c.alreadyDeal is null or alreadyDeal = '?'"); return Integer.parseInt(query.uniqueResult().toString()); } catch (HibernateException e) { throw e; } finally { HibernateSessionFactory.closeSession(); } }
From source file:com.dz.module.driver.complain.ComplainDaoImpl.java
@SuppressWarnings("unchecked") @Override//from ww w .j a v a 2 s . com public List<Complain> selectAllByStates(Complain complain, Page page, Date beginDate, Date endDate, String dept, Short[] states, String order) { Session session = null; try { session = HibernateSessionFactory.getSession(); String hql = "select c from Complain c,Vehicle v where c.state in (:states)"; if (beginDate != null) { hql += " and c.complainTime >= :beginDate"; } if (endDate != null) { hql += " and c.complainTime <= :endDate"; } if (!StringUtils.isEmpty(dept)) { hql += " and c.vehicleId in (select carframeNum from Vehicle where dept like :dept) "; } if (complain != null) { if (StringUtils.isNotEmpty(complain.getComplainClass())) { hql += " and c.complainClass like :complainClass"; } if (StringUtils.isNotEmpty(complain.getComplainObject())) { hql += " and c.complainObject like :complainObject"; } } hql += " and c.vehicleId=v.carframeNum "; if (StringUtils.equals(order, "complainTime")) { hql += " order by c.complainTime "; } else { hql += " order by v.licenseNum "; } Query query = session.createQuery(hql); if (beginDate != null) { query.setDate("beginDate", beginDate); } if (endDate != null) { query.setDate("endDate", endDate); } if (!StringUtils.isEmpty(dept)) { query.setString("dept", "%" + dept + "%"); } query.setParameterList("states", states); if (complain != null) { if (StringUtils.isNotEmpty(complain.getComplainClass())) { query.setString("complainClass", "%" + complain.getComplainClass() + "%"); } if (StringUtils.isNotEmpty(complain.getComplainObject())) { query.setString("complainObject", "%" + complain.getComplainObject() + "%"); } } //Query query = session.createQuery("from Complain c where c.alreadyDeal is null or alreadyDeal = '?'"); query.setMaxResults(page.getEveryPage()); query.setFirstResult(page.getBeginIndex()); return query.list(); } catch (HibernateException e) { throw e; } finally { HibernateSessionFactory.closeSession(); } }
From source file:com.edgenius.core.dao.hibernate.BaseDAOHibernate.java
License:Open Source License
protected void applyNamedParameterToQuery(Query queryObject, String paramName, Object value) throws HibernateException { if (value instanceof Collection) { queryObject.setParameterList(paramName, (Collection) value); } else if (value instanceof Object[]) { queryObject.setParameterList(paramName, (Object[]) value); } else {//from ww w.ja va 2 s .c o m queryObject.setParameter(paramName, value); } }
From source file:com.ejushang.steward.common.genericdao.search.hibernate.HibernateSearchProcessor.java
License:Apache License
@SuppressWarnings("unchecked") private void addParams(Query query, List<Object> params) { StringBuilder debug = null;/* w w w . j a v a 2s . com*/ int i = 1; for (Object o : params) { if (logger.isDebugEnabled()) { if (debug == null) debug = new StringBuilder(); else debug.append("\n\t"); debug.append("p"); debug.append(i); debug.append(": "); debug.append(InternalUtil.paramDisplayString(o)); } if (o instanceof Collection) { query.setParameterList("p" + Integer.toString(i++), (Collection) o); } else if (o instanceof Object[]) { query.setParameterList("p" + Integer.toString(i++), (Object[]) o); } else { query.setParameter("p" + Integer.toString(i++), o); } } if (debug != null && debug.length() != 0) { logger.debug(debug.toString()); } }
From source file:com.enonic.cms.store.dao.AbstractBaseEntityDao.java
License:Open Source License
public int deleteByNamedQuery(final String queryName, final String[] paramNames, final Object[][] paramValues) { return ((Number) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Query query = session.getNamedQuery(queryName); if (paramNames != null) { for (int i = 0; i < paramNames.length; i++) { query.setParameterList(paramNames[i], paramValues[i]); }// w w w.j a v a 2 s . c o m } return query.executeUpdate(); } })).intValue(); }
From source file:com.ephesoft.dcma.performance.reporting.service.ReportDataServiceImpl.java
License:Open Source License
/** * Method to get System Level Statistics for a specified time. * /*from ww w .j a v a 2s . c o m*/ * @param endTime {@link Date} upto which the reporting data needs to be fetched * @param startTime {@link Date}Starting Date from which the reporting data needs to be fetched * @param batchClassIdList List<String> * @return List<{@link Integer}> list of integers specifying the system statistics * @throws DCMAException if error occurs in database creation */ public List<Integer> getSystemStatistics(Date endTime, Date startTime, List<String> batchClassIdList) throws DCMAException { LOGGER.info("Inside getSystemStatistics.. "); Connection connection = null; List<Integer> finalResult = new ArrayList<Integer>(); try { connection = dynamicHibernateDao.getConnectionProvider().getConnection(); StatelessSession session = dynamicHibernateDao.getStatelessSession(connection); Query qry = session.getNamedQuery(ReportingConstants.GET_SYSTEM_STATISTICS); // Adding 1 Day in the End Time to show all the records for that Day Calendar calendar = Calendar.getInstance(); calendar.setTime(endTime); calendar.add(Calendar.DATE, 1); LOGGER.info("batchClassIdList::" + batchClassIdList); qry.setParameter(ReportingConstants.END_TIME, new java.sql.Date(calendar.getTimeInMillis())); qry.setParameter(ReportingConstants.START_TIME, new java.sql.Date(startTime.getTime())); qry.setParameterList(ReportingConstants.GET_SYSTEM_STATISTICS_BATCH_CLASS_ID_LIST, batchClassIdList); List<?> results = qry.list(); Object[] object = (Object[]) results.get(0); for (int i = 0; i < object.length; i++) { if (object[i] != null) { finalResult.add(Integer.parseInt(object[i].toString())); } } } catch (SQLException e) { LOGGER.error(ERROR_CREATING_DATABASE_CONNECTION + e.getMessage(), e); } finally { if (connection != null) { try { connection.close(); } catch (SQLException e) { LOGGER.error(ERROR_CLOSING_DATABASE_CONNECTION + e.getMessage(), e); } } } return finalResult; }
From source file:com.ephesoft.dcma.performance.reporting.service.ReportDataServiceImpl.java
License:Open Source License
/** * Method to get Reports Per page for a WorkflowType for a specified time. * // w ww . j av a 2 s . c o m * @param batchClassIds List<{@link String}> Batch Class Ids for which the report data needs to be fetched * @param workflowType {@link WorkflowType}, One of Module , Plugin or Workflow specifying the type of filter * @param endTime {@link Date} upto which the reporting data needs to be fetched * @param startTime {@link Date} Starting Date from which the reporting data needs to be fetched * @param StartIndex int, Start Index for pagination * @param range int Number of records per page * @param order {@link Order} By field * @return List<{@link ReportDisplayData}> List of RepoertDisplayData DTOs * @throws DCMAException if error occurs in database creation */ @SuppressWarnings("unchecked") public List<ReportDisplayData> getReportByWorkflow(List<String> batchClassIds, WorkflowType workflowType, Date endTime, Date startTime, int StartIndex, int range, Order order) throws DCMAException { Connection connection = null; Query qry = null; List<ReportDisplayData> displayDatas = null; try { connection = dynamicHibernateDao.getConnectionProvider().getConnection(); StatelessSession session = dynamicHibernateDao.getStatelessSession(connection); qry = session.getNamedQuery(ReportingConstants.GET_REPORT_BY_WORKFLOW); qry.setResultTransformer(Transformers.aliasToBean(ReportDisplayData.class)); // Adding 1 Day in the End Time to show all the records for that Day Calendar calendar = Calendar.getInstance(); calendar.setTime(endTime); calendar.add(Calendar.DATE, 1); qry.setParameter(ReportingConstants.END_TIME, new java.sql.Date(calendar.getTimeInMillis())); qry.setParameter(ReportingConstants.START_TIME, new java.sql.Date(startTime.getTime())); qry.setParameter(ReportingConstants.START_INDEX, StartIndex); qry.setParameter(ReportingConstants.RANGE, range); qry.setParameter(ReportingConstants.WORK_FLOW_TYPE, workflowType.name()); qry.setParameterList(ReportingConstants.BATCH_CLASS_ID_LIST, batchClassIds); displayDatas = qry.list(); } catch (SQLException e) { LOGGER.error(ERROR_CREATING_DATABASE_CONNECTION + e.getMessage(), e); } finally { if (connection != null) { try { connection.close(); } catch (SQLException e) { LOGGER.error(ERROR_CLOSING_DATABASE_CONNECTION + e.getMessage(), e); } } } return displayDatas; }