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.complain.ComplainDaoImpl.java
@Override public int selectAllCount(Date beginDate, Date endDate) throws HibernateException { Session session = null;/*from w w w .j a va 2 s. co m*/ try { session = HibernateSessionFactory.getSession(); String hql = "select count(*) from Complain c where 1=1"; if (beginDate != null) { hql += " and c.complainTime >= :beginDate"; } if (endDate != null) { hql += " and c.complainTime <= :endDate"; } Query query = session.createQuery(hql); if (beginDate != null) { query.setDate("beginDate", beginDate); } if (endDate != null) { query.setDate("endDate", endDate); } return Integer.parseInt(query.uniqueResult().toString()); } catch (HibernateException e) { throw e; } finally { HibernateSessionFactory.closeSession(); } }
From source file:com.dz.module.driver.complain.ComplainDaoImpl.java
/** * ?//from w w w . j ava 2 s . c o m * @return * @throws HibernateException */ @SuppressWarnings("unchecked") @Override public List<Complain> selectAllByState(Page page, Date beginDate, Date endDate, int state) throws HibernateException { Session session = null; try { session = HibernateSessionFactory.getSession(); String hql = "from Complain c where c.state=:state"; if (beginDate != null) { hql += " and c.complainTime >= :beginDate"; } if (endDate != null) { hql += " and c.complainTime <= :endDate"; } Query query = session.createQuery(hql); if (beginDate != null) { query.setDate("beginDate", beginDate); } if (endDate != null) { query.setDate("endDate", endDate); } query.setInteger("state", state); //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.dz.module.driver.complain.ComplainDaoImpl.java
@Override public int selectAllByStateCount(Date beginDate, Date endDate, int state) throws HibernateException { Session session = null;//from w w w .j ava 2s . c o m try { session = HibernateSessionFactory.getSession(); String hql = "select count(*) from Complain c where c.state=:state"; if (beginDate != null) { hql += " and c.complainTime >= :beginDate"; } if (endDate != null) { hql += " and c.complainTime <= :endDate"; } Query query = session.createQuery(hql); if (beginDate != null) { query.setDate("beginDate", beginDate); } if (endDate != null) { query.setDate("endDate", endDate); } query.setInteger("state", state); //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
@Override public int selectAllByStatesCount(Complain complain, Date beginDate, Date endDate, String dept, Short[] states) {//from w w w . jav a2 s . co 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 w w w . j ava2 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.dz.module.driver.DriverDaoImpl.java
@SuppressWarnings("unchecked") public List<Driver> driverSearchCondition(Page page, String idNum, Date beginDate, Date endDate, Boolean isInCar, Triplet<String, String, Object>... conditions) throws HibernateException { List<Driver> l = new ArrayList<Driver>(); Session session = null;/*from ww w. j a v a 2 s .c om*/ try { session = HibernateSessionFactory.getSession(); String sql = "from Driver where 1=1 "; if (!StringUtils.isEmpty(idNum)) { sql += "and idNum like :idNum "; } if (beginDate != null) { sql += "and applyTime>:beginDate "; } if (endDate != null) { sql += "and applyTime<:endDate "; } if (isInCar != null) sql += "and isInCar=:isInCar"; for (Triplet<String, String, Object> condition : conditions) { if (condition != null) { sql += String.format("and %s %s :%s ", condition.getValue0(), condition.getValue1(), condition.getValue0()); } } System.out.println(sql); Query query = session.createQuery(sql); for (Triplet<String, String, Object> condition : conditions) { if (condition != null) { query.setParameter(condition.getValue0(), condition.getValue2()); } } if (!StringUtils.isEmpty(idNum)) { query.setString("idNum", "%" + idNum + "%"); } if (beginDate != null) { query.setDate("beginDate", beginDate); } if (endDate != null) { query.setDate("endDate", endDate); } if (isInCar != null) query.setBoolean("isInCar", isInCar); if (page != null) { query.setMaxResults(page.getEveryPage()); query.setFirstResult(page.getBeginIndex()); } l = query.list(); query = null; } catch (HibernateException e) { throw e; } finally { HibernateSessionFactory.closeSession(); } return l; }
From source file:com.dz.module.driver.DriverDaoImpl.java
public int driverSearchConditionTotal(String idNum, Date beginDate, Date endDate, Boolean isInCar, Triplet<String, String, Object>... conditions) throws HibernateException { Session session = null;//from ww w . j av a2 s .c o m int c = 0; try { session = HibernateSessionFactory.getSession(); String sql = "select count(*) from Driver where 1=1 "; if (!StringUtils.isEmpty(idNum)) { sql += "and idNum like :idNum "; } if (beginDate != null) { sql += "and applyTime>:beginDate "; } if (endDate != null) { sql += "and applyTime<:endDate "; } if ((isInCar) != null) sql += "and isInCar=:isInCar"; for (Triplet<String, String, Object> condition : conditions) { if (condition != null) { sql += String.format("and %s %s :%s ", condition.getValue0(), condition.getValue1(), condition.getValue0()); } } System.out.println(sql); Query query = session.createQuery(sql); for (Triplet<String, String, Object> condition : conditions) { if (condition != null) { query.setParameter(condition.getValue0(), condition.getValue2()); } } if (!StringUtils.isEmpty(idNum)) { query.setString("idNum", "%" + idNum + "%"); } if (beginDate != null) { query.setDate("beginDate", beginDate); } if (endDate != null) { query.setDate("endDate", endDate); } if (isInCar != null) query.setBoolean("isInCar", isInCar); c = Integer.parseInt(query.uniqueResult().toString()); query = null; } catch (HibernateException e) { throw e; } finally { HibernateSessionFactory.closeSession(); } return c; }
From source file:com.dz.module.driver.DriverDaoImpl.java
@Override public int selectDriverInCarByConditionCount(Date beginDate, Date endDate, Vehicle vehicle, Driver driver, String operation, Boolean finished) { Session session = null;//from w w w. j a v a2 s . c om try { session = HibernateSessionFactory.getSession(); String sql = "select count(*) from Driverincar where 1=1 "; 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(vehicle.getLicenseNum())) { sql += "and carframeNum in (select carframeNum from Vehicle where licenseNum like :licenseNum ) "; } if (!StringUtils.isEmpty(driver.getIdNum())) { sql += "and idNumber like :idNum "; } if (!StringUtils.isEmpty(operation)) { sql += "and operation like :operation "; } if (finished != null) { sql += "and finished = :finished "; } Query query = session.createQuery(sql); if (!StringUtils.isEmpty(vehicle.getCarframeNum())) { query.setString("carframeNum", "%" + vehicle.getCarframeNum() + "%"); } if (!StringUtils.isEmpty(vehicle.getLicenseNum())) { query.setString("licenseNum", "%" + vehicle.getLicenseNum() + "%"); } 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 (finished != null) { query.setBoolean("finished", finished); sql += "and finished = :finished "; } 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 w w w . j a va 2 s. c om public List<Driverincar> selectDriverInCarByCondition(Page page, Date beginDate, Date endDate, Vehicle vehicle, Driver driver, String operation, Boolean finished) { Session session = null; try { session = HibernateSessionFactory.getSession(); String sql = "from Driverincar where 1=1 "; 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(vehicle.getLicenseNum())) { sql += "and carframeNum in (select carframeNum from Vehicle where licenseNum like :licenseNum ) "; } if (!StringUtils.isEmpty(driver.getIdNum())) { sql += "and idNumber like :idNum "; } if (!StringUtils.isEmpty(operation)) { sql += "and operation like :operation "; } if (finished != null) { sql += "and finished = :finished "; } Query query = session.createQuery(sql); if (!StringUtils.isEmpty(vehicle.getCarframeNum())) { query.setString("carframeNum", "%" + vehicle.getCarframeNum() + "%"); } if (!StringUtils.isEmpty(vehicle.getLicenseNum())) { query.setString("licenseNum", "%" + vehicle.getLicenseNum() + "%"); } 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 (finished != null) { query.setBoolean("finished", finished); sql += "and finished = :finished "; } 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.DriverDaoImpl.java
@SuppressWarnings("unchecked") @Override//w w w . jav a2s .c om public List<Driver> driverSearchCondition(Page page, Date beginDate, Date endDate, Driver driver) throws HibernateException { Session session = null; try { session = HibernateSessionFactory.getSession(); String sql = "from Driver where 1=1 "; if (!StringUtils.isEmpty(driver.getIdNum())) { sql += "and idNum like :idNum "; } if (!StringUtils.isEmpty(driver.getName())) { sql += "and name like :name "; } 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 (!StringUtils.isEmpty(driver.getName())) { query.setString("name", "%" + driver.getName() + "%"); } 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()); if (page != null) { query.setMaxResults(page.getEveryPage()); query.setFirstResult(page.getBeginIndex()); } return query.list(); } catch (HibernateException e) { throw e; } finally { HibernateSessionFactory.closeSession(); } }