List of usage examples for org.hibernate Query setDate
@Deprecated @SuppressWarnings("unchecked") default Query<R> setDate(String name, Date val)
From source file:com.dz.module.driver.DriverDaoImpl.java
@Override public int driverSearchConditionTotal(Date beginDate, Date endDate, Driver driver) throws HibernateException { Session session = null;//from www . j a va 2 s . c o m try { session = HibernateSessionFactory.getSession(); String sql = "select count(*) from Driver where 1=1 "; if (!StringUtils.isEmpty(driver.getIdNum())) { sql += "and idNum like :idNum "; } if (!StringUtils.isEmpty(driver.getDept())) { sql += "and dept like :dept "; } if (!StringUtils.isEmpty(driver.getTeam())) { sql += "and team like :team "; } if (beginDate != null) { sql += "and applyTime>:beginDate "; } if (endDate != null) { sql += "and applyTime<:endDate "; } if (driver.getIsInCar() != null) sql += "and isInCar=:isInCar"; Query query = session.createQuery(sql); if (!StringUtils.isEmpty(driver.getIdNum())) { query.setString("idNum", "%" + driver.getIdNum() + "%"); } if (beginDate != null) { query.setDate("beginDate", beginDate); } if (endDate != null) { query.setDate("endDate", endDate); } if (!StringUtils.isEmpty(driver.getDept())) { query.setString("dept", "%" + driver.getDept() + "%"); sql += "and dept like :dept "; } if (!StringUtils.isEmpty(driver.getTeam())) { query.setString("team", "%" + driver.getTeam() + "%"); sql += "and team like :team "; } if (driver.getIsInCar() != null) query.setBoolean("isInCar", driver.getIsInCar()); return Integer.parseInt(query.uniqueResult().toString()); } catch (HibernateException e) { throw e; } finally { HibernateSessionFactory.closeSession(); } }
From source file:com.dz.module.driver.DriverDaoImpl.java
@Override public int selectDriverLeaveByConditionCount(Date beginDate, Date endDate, Vehicle vehicle, Driver driver, Boolean finished, String operation) { Session session = null;/*from www . j av a 2 s .c o m*/ try { session = HibernateSessionFactory.getSession(); String sql = "select count(*) from Driverleave where finished=:finished "; if (beginDate != null) { sql += "and opeTime>:beginDate "; } if (endDate != null) { sql += "and opeTime<:endDate "; } if (!StringUtils.isEmpty(vehicle.getCarframeNum())) { sql += "and carframeNum like :carframeNum "; } if (!StringUtils.isEmpty(driver.getIdNum())) { sql += "and idNumber like :idNum "; } if (!StringUtils.isEmpty(operation)) { sql += "and operation like :operation "; } Query query = session.createQuery(sql); query.setBoolean("finished", finished); if (!StringUtils.isEmpty(vehicle.getCarframeNum())) { query.setString("carframeNum", "%" + vehicle.getCarframeNum() + "%"); } if (!StringUtils.isEmpty(driver.getIdNum())) { query.setString("idNum", "%" + driver.getIdNum() + "%"); } if (beginDate != null) { query.setDate("beginDate", beginDate); } if (endDate != null) { query.setDate("endDate", endDate); } if (!StringUtils.isEmpty(operation)) { query.setString("operation", "%" + operation + "%"); } return Integer.parseInt(query.uniqueResult().toString()); } catch (HibernateException e) { throw e; } finally { HibernateSessionFactory.closeSession(); } }
From source file:com.dz.module.driver.DriverDaoImpl.java
@SuppressWarnings("unchecked") @Override//from www. j av a2 s . c o m public List<Driverleave> selectDriverLeaveByCondition(Page page, Date beginDate, Date endDate, Vehicle vehicle, Driver driver, Boolean finished, String operation) { Session session = null; try { session = HibernateSessionFactory.getSession(); String sql = "from Driverleave where finished=:finished "; if (beginDate != null) { sql += "and opeTime>:beginDate "; } if (endDate != null) { sql += "and opeTime<:endDate "; } if (!StringUtils.isEmpty(vehicle.getCarframeNum())) { sql += "and carframeNum like :carframeNum "; } if (!StringUtils.isEmpty(driver.getIdNum())) { sql += "and idNumber like :idNum "; } if (!StringUtils.isEmpty(operation)) { sql += "and operation like :operation "; } Query query = session.createQuery(sql); query.setBoolean("finished", finished); if (!StringUtils.isEmpty(vehicle.getCarframeNum())) { query.setString("carframeNum", "%" + vehicle.getCarframeNum() + "%"); } if (!StringUtils.isEmpty(driver.getIdNum())) { query.setString("idNum", "%" + driver.getIdNum() + "%"); } if (beginDate != null) { query.setDate("beginDate", beginDate); } if (endDate != null) { query.setDate("endDate", endDate); } if (!StringUtils.isEmpty(operation)) { query.setString("operation", "%" + operation + "%"); } 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.vehicle.electric.ElectricAnaylseService.java
public int createAnaylse(Date beginDate, Date endDate) { Session session = HibernateSessionFactory.getSession(); Transaction tx = null;// ww w . j a v a 2 s .co m int ea_id = 0; try { tx = session.beginTransaction(); ElectricAnaylse ea = new ElectricAnaylse(); Query query = session.createQuery("select count(*),sum(cast(money as integer)) " + "from ElectricHistory " + "where STR_TO_DATE(date,'%Y-%m-%d %H:%i:%s')>=:beginDate " + "and STR_TO_DATE(date,'%Y-%m-%d %H:%i:%s')<=:endDate"); Query query_dept = session.createQuery("select count(*),sum(cast(money as integer)) " + "from ElectricHistory " + "where STR_TO_DATE(date,'%Y-%m-%d %H:%i:%s')>=:beginDate " + "and STR_TO_DATE(date,'%Y-%m-%d %H:%i:%s')<=:endDate " + "and carframeNum in (select carframeNum from Vehicle where dept=:dept)"); query.setDate("beginDate", beginDate); query.setDate("endDate", endDate); query_dept.setDate("beginDate", beginDate); query_dept.setDate("endDate", endDate); Object[] oarr = (Object[]) query.uniqueResult(); ea.setBeginDate(beginDate); ea.setEndDate(endDate); ea.setAllTimes((int) (long) oarr[0]); ea.setAllMoney((long) oarr[1]); query_dept.setString("dept", ""); oarr = (Object[]) query_dept.uniqueResult(); ea.setTime1((int) (long) oarr[0]); ea.setMoney1((long) oarr[1]); query_dept.setString("dept", ""); oarr = (Object[]) query_dept.uniqueResult(); ea.setTime2((int) (long) oarr[0]); ea.setMoney2((long) oarr[1]); query_dept.setString("dept", ""); oarr = (Object[]) query_dept.uniqueResult(); ea.setTime3((int) (long) oarr[0]); ea.setMoney3((long) oarr[1]); session.save(ea); // System.out.println("ElectricAnaylseService.createAnaylse(),line 76,ElectricAnaylse:\t"+ea); ea_id = ea.getId(); Query query_vehicle = session.createQuery( "insert into ElectricAnaylseVehicle(anaylseId,carframeNum,licenseNum,times,moneys) " + "select " + ea.getId() + ",carframeNum,licenseNum,cast(count(*) as integer),sum(cast(money as integer)) from ElectricHistory " + "where STR_TO_DATE(date,'%Y-%m-%d %H:%i:%s')>=:beginDate " + "and STR_TO_DATE(date,'%Y-%m-%d %H:%i:%s')<=:endDate " + "group by carframeNum"); query_vehicle.setDate("beginDate", beginDate); query_vehicle.setDate("endDate", endDate); query_vehicle.executeUpdate(); Query query_act = session.createQuery( "insert into ElectricAnaylseAct(anaylseId,act,times,moneys) " + "select " + ea.getId() + ",act,cast(count(*) as integer),sum(cast(money as integer)) from ElectricHistory " + "where STR_TO_DATE(date,'%Y-%m-%d %H:%i:%s')>=:beginDate " + "and STR_TO_DATE(date,'%Y-%m-%d %H:%i:%s')<=:endDate " + "group by act"); query_act.setDate("beginDate", beginDate); query_act.setDate("endDate", endDate); query_act.executeUpdate(); Query query_act_area = session .createQuery("insert into ElectricAnaylseActArea(anaylseActId,area,times) " + "select eaa.id,eh.area,cast(count(*) as integer) " + "from ElectricHistory eh,ElectricAnaylseAct eaa " + "where eaa.anaylseId=:aid " + "and eaa.act=eh.act " + "and STR_TO_DATE(eh.date,'%Y-%m-%d %H:%i:%s')>=:beginDate " + "and STR_TO_DATE(eh.date,'%Y-%m-%d %H:%i:%s')<=:endDate " + "group by eh.act,eh.area"); query_act_area.setInteger("aid", ea.getId()); query_act_area.setDate("beginDate", beginDate); query_act_area.setDate("endDate", endDate); query_act_area.executeUpdate(); tx.commit(); } catch (HibernateException ex) { if (tx != null) { tx.rollback(); } ex.printStackTrace(); return 0; } finally { HibernateSessionFactory.closeSession(); } return ea_id; }
From source file:com.edgenius.wiki.dao.hibernate.HistoryDAOHibernate.java
License:Open Source License
@SuppressWarnings("unchecked") public List<History> getByUuid(final String uuid, final int startVer, final int returnCount, final Date touchedDate) { Query query; if (touchedDate == null) { query = getCurrentSesssion().createQuery(GET_HISTORY_BY_UUID); query.setString(0, uuid);/*www.j a v a 2s .co m*/ query.setInteger(1, startVer <= 0 ? Integer.MAX_VALUE : startVer); } else { query = getCurrentSesssion().createQuery(GET_HISTORY_BY_UUID_OLDER_DATE); query.setString(0, uuid); query.setDate(1, touchedDate); query.setInteger(2, startVer <= 0 ? Integer.MAX_VALUE : startVer); } if (returnCount > 0) { query.setMaxResults(returnCount); } return query.list(); }
From source file:com.edgenius.wiki.ext.calendar.dao.hibernate.CalendarEventDAOHibernate.java
License:Open Source License
@SuppressWarnings("unchecked") public List<CalendarEvent> getEvents(final String calName, final String pageUuid, final Date start, final Date end) { Query query = getCurrentSesssion().createQuery(GET_CALENDAR); query.setString("name", calName); query.setString("pageUuid", pageUuid); query.setDate("start", start); query.setDate("end", end); return query.list(); }
From source file:com.enonic.cms.store.dao.LogEntryEntityDao.java
License:Open Source License
@SuppressWarnings({ "unchecked" }) public List<LogEntryKey> findBySpecification(LogEntrySpecification specification, final String orderBy) { final String logEntryKeysHQL = getLogEntryKeysHQL(specification, orderBy); Query compiled = getHibernateTemplate().getSessionFactory().getCurrentSession() .createQuery(logEntryKeysHQL); if (specification.getDateFilter() != null) { compiled.setDate("dateFilter", specification.getDateFilter()); }/* w w w.ja va2 s . c o m*/ if (specification.isDateSpanSet()) { specification.setDateSpanParameters(compiled); } compiled.setCacheable(true); @SuppressWarnings({ "unchecked" }) LogEntryResultTransformer transformer = new LogEntryResultTransformer( specification.isAllowDuplicateEntries()); return transformer.transformList(compiled.list()); }
From source file:com.exilant.eGov.src.common.EGovernCommon.java
License:Open Source License
public BigDecimal getAccountBalance(final String recDate, final String bankAccountId) throws TaskFailedException { BigDecimal opeAvailable = BigDecimal.ZERO; BigDecimal totalAvailable = BigDecimal.ZERO; Query pst = null; List<Object[]> resultset = null; List<Object[]> resultset1 = null; try {/*from ww w. j a va 2 s . c o m*/ final String str = "SELECT case when sum(openingDebitBalance) is null then 0 else sum(openingDebitBalance) end - case when sum(openingCreditBalance) is null then 0 else sum(openingCreditBalance) end AS \"openingBalance\" " + " FROM transactionSummary WHERE financialYearId=( SELECT id FROM financialYear WHERE startingDate <=? " + " AND endingDate >=? ) AND glCodeId =(select glcodeid from bankaccount where id=? )"; if (LOGGER.isDebugEnabled()) LOGGER.debug("getAccountBalance(EGovernCommon.java): " + str); pst = persistenceService.getSession().createSQLQuery(str); SimpleDateFormat dtSlashFormat = new SimpleDateFormat("dd/MMM/yyyy"); Date reconDate = dtSlashFormat.parse(recDate); java.sql.Date sDate = new java.sql.Date(reconDate.getTime()); pst.setDate(0, sDate); pst.setDate(1, sDate); pst.setInteger(2, Integer.valueOf(bankAccountId)); List list = pst.list(); if (list == null || list.size() == 0) if (LOGGER.isDebugEnabled()) LOGGER.debug("Else resultset in getAccountBalance..."); if (list != null || list.size() > 0) { opeAvailable = new BigDecimal(list.get(0).toString()); } /* for (final Object[] element : resultset) { if(element[0]!=null) opeAvailable = new BigDecimal(element[0].toString()); }*/ if (LOGGER.isDebugEnabled()) LOGGER.debug("opening balance " + opeAvailable); final String str1 = "SELECT (case when sum(gl.debitAmount) is null then 0 else sum(gl.debitAmount) end - case when sum(gl.creditAmount) is null then 0 else sum(gl.creditAmount) end ) + " + opeAvailable + " as \"totalAmount\" FROM generalLedger gl, voucherHeader vh WHERE vh.id = gl.voucherHeaderId and gl.glCodeid = (select glcodeid from bankaccount where id=?) AND " + " vh.voucherDate >=( SELECT startingDate FROM financialYear WHERE startingDate <= ? AND endingDate >= ?) AND vh.voucherDate <= ? and vh.status!=4"; if (LOGGER.isDebugEnabled()) LOGGER.debug("Curr Yr Bal: " + str1); pst = persistenceService.getSession().createSQLQuery(str1); pst.setInteger(0, Integer.valueOf(bankAccountId)); pst.setDate(1, reconDate); pst.setDate(2, reconDate); pst.setDate(3, reconDate); List list2 = pst.list(); if (list2 != null) totalAvailable = new BigDecimal(list2.get(0).toString()); if (LOGGER.isDebugEnabled()) LOGGER.debug("total balance " + totalAvailable); if (resultset1 == null || resultset1.size() == 0) if (LOGGER.isDebugEnabled()) LOGGER.debug("Else resultset in getAccountBalance..."); totalAvailable = totalAvailable.setScale(2, BigDecimal.ROUND_HALF_UP); if (LOGGER.isDebugEnabled()) LOGGER.debug("total balance before return " + totalAvailable); return totalAvailable; } catch (final Exception e) { LOGGER.error(e.getMessage(), e); throw taskExc; } }
From source file:com.glaf.jbpm.util.HibernateUtils.java
License:Apache License
public static void fillParameters(Query query, List<Object> values) { if (values == null || values.size() == 0) { return;/*ww w .j ava2s. c om*/ } for (int i = 0; i < values.size(); i++) { Object object = values.get(i); int index = i; if (object != null) { if (object instanceof java.sql.Date) { java.sql.Date sqlDate = (java.sql.Date) object; query.setDate(index, sqlDate); } else if (object instanceof java.sql.Time) { java.sql.Time sqlTime = (java.sql.Time) object; query.setTime(index, sqlTime); } else if (object instanceof java.sql.Timestamp) { Timestamp datetime = (Timestamp) object; query.setTimestamp(index, datetime); } else if (object instanceof java.util.Date) { Timestamp datetime = DateUtils.toTimestamp((java.util.Date) object); query.setTimestamp(index, datetime); } else { query.setParameter(index, object); } } else { query.setParameter(index, null); } } }
From source file:com.google.code.mymon3y.persistencia.dao.hibernate.TransacaoDAOHibernate.java
License:Open Source License
/** * @see com.google.code.mymon3y.persistencia.dao.TransacaoDAO#getTransacoes(java.lang.String, java.util.Date, * java.util.Date)/*from w ww . j ava2 s. c o m*/ */ @SuppressWarnings("unchecked") public List<Transacao> getTransacoes(final String login, final Date inicio, final Date fim) throws PersistenciaMyMon3yException { List<Transacao> result = null; result = (List<Transacao>) executarOperacao(new Comando() { public Object executar() { Query q = getSession().getNamedQuery("transacao.transacoes"); q.setString("loginDoUsuario", login); q.setDate("dataInicio", inicio); q.setDate("dataFim", fim); return q.list(); } }); return result; }