List of usage examples for org.hibernate Query setString
@Deprecated @SuppressWarnings("unchecked") default Query<R> setString(String name, String val)
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 www. j av a2s . c om*/ // 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/* w w w . j av a 2 s . c om*/ 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
@Override public boolean driverUpdate(Driver driver, List<Families> families) throws HibernateException { boolean flag = false; Session session = null;/*from w w w .j ava2 s . co m*/ Transaction tx = null; try { session = HibernateSessionFactory.getSession(); tx = (Transaction) session.beginTransaction(); session.update(driver); Query query = session.createQuery("from Families f where f.idNum = :driver_id"); query.setString("driver_id", driver.getIdNum()); @SuppressWarnings("unchecked") List<Families> oldFamilies = query.list(); if (oldFamilies != null) { for (int i = 0; i < oldFamilies.size(); i++) session.delete(oldFamilies.get(i)); } if (families != null) { for (int i = 0; i < families.size(); i++) session.save(families.get(i)); } tx.commit(); flag = true; } catch (HibernateException e) { if (tx != null) { tx.rollback(); } throw e; } finally { HibernateSessionFactory.closeSession(); } return flag; }
From source file:com.dz.module.driver.DriverDaoImpl.java
@Override public Driver selectByName(String name) { Session session = null;/*w w w. ja va 2 s.co m*/ try { session = HibernateSessionFactory.getSession(); String str = "from Driver where name = :name "; Query query = session.createQuery(str); query.setString("name", name); return (Driver) query.uniqueResult(); } catch (HibernateException he) { he.printStackTrace(); } return null; }
From source file:com.dz.module.driver.DriverDaoImpl.java
@SuppressWarnings("unchecked") @Override// w w w .j a va 2s . c om public List<Families> selectFamily(Driver driver) { Session session = null; try { session = HibernateSessionFactory.getSession(); Query query = session.createQuery("from Families where idNum=:idNum"); query.setString("idNum", driver.getIdNum()); 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 w ww . j av a2 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;// w w w . ja v a2s . 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 www. j av a2 s . c o m 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 www. j av a 2 s. c o m*/ 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/*from w w w. j ava2 s. 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(); } }