List of usage examples for org.hibernate Query setMaxResults
@Override
Query<R> setMaxResults(int maxResult);
From source file:com.dz.module.driver.DriverDaoImpl.java
@SuppressWarnings("unchecked") @Override/*w ww . j a v a 2 s .com*/ public List<Driver> search(Page page, Triplet<String, String, Object>... conditions) { Session session = null; try { session = HibernateSessionFactory.getSession(); String sql = "from Driver where 1=1 "; if (conditions != null) for (Triplet<String, String, Object> condition : conditions) { if (condition != null) { sql += String.format("and %s %s :%s ", condition.getValue0(), condition.getValue1(), condition.getValue0()); } } Query query = session.createQuery(sql); if (conditions != null) for (Triplet<String, String, Object> condition : conditions) { if (condition != null) { query.setParameter(condition.getValue0(), condition.getValue2()); } } 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 . jav a 2s . c o m*/ public List<Driver> driverSearch(Page page) throws HibernateException { List<Driver> l = new ArrayList<Driver>(); Session session = null; try { session = HibernateSessionFactory.getSession(); Query query = session.createQuery("from Driver"); query.setMaxResults(15); query.setFirstResult(page.getBeginIndex()); l = query.list(); // for(Driver driver : l){ // System.out.println(driver.getApplyMatter()); // } query = null; } catch (HibernateException e) { throw e; } finally { HibernateSessionFactory.closeSession(); } return l; }
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;// ww w.j ava2s. c o m 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
@SuppressWarnings("unchecked") @Override/*ww w.ja va2s . co m*/ public List<Vehicle> driverCarSearch(Page page, String idName, String idNum, String linence_num) { Session session = null; List<Vehicle> list = null; try { session = HibernateSessionFactory.getSession(); String str = "from Vehicle v where v.licenseNum like '%" + linence_num + "%' &&" + " v.driverId in (select d.driverId from Driver d where d.idNum like '%" + idNum + "%' &&" + " d.name like '%" + idName + "%')"; Query query = session.createQuery(str); query.setMaxResults(page.getEveryPage()); query.setFirstResult(page.getBeginIndex()); list = (List<Vehicle>) query.list(); } catch (HibernateException he) { he.printStackTrace(); list = new ArrayList<Vehicle>(); } return list; }
From source file:com.dz.module.driver.DriverDaoImpl.java
@SuppressWarnings("unchecked") @Override/*ww w . jav a 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//from www. ja va 2s . 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(); } }
From source file:com.dz.module.driver.DriverDaoImpl.java
@SuppressWarnings("unchecked") @Override//ww w. j av a 2 s .co 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.InsuranceDaoImpl.java
@SuppressWarnings("unchecked") @Override/*from ww w . ja v a 2 s . co m*/ public List<Insurance> selectByCondition(Page page, Insurance insurance, Vehicle vehicle) { Session session = null; try { session = HibernateSessionFactory.getSession(); String sql = "from Insurance where state>0 "; if (!StringUtils.isEmpty(insurance.getCarframeNum())) { sql += "and carframeNum like :carframeNum "; } if (!StringUtils.isEmpty(insurance.getInsuranceNum())) { sql += "and insuranceNum like :insuranceNum "; } if (!StringUtils.isEmpty(insurance.getInsuranceClass())) { sql += "and insuranceClass like :insuranceClass "; } if (vehicle != null) { if (!StringUtils.isEmpty(vehicle.getLicenseNum())) { sql += "and carframeNum in (select carframeNum from Vehicle where licenseNum like :licenseNum ) "; } } Query query = session.createQuery(sql); if (!StringUtils.isEmpty(insurance.getCarframeNum())) { query.setString("carframeNum", "%" + insurance.getCarframeNum() + "%"); } if (!StringUtils.isEmpty(insurance.getInsuranceNum())) { query.setString("insuranceNum", "%" + insurance.getInsuranceNum() + "%"); } if (!StringUtils.isEmpty(insurance.getInsuranceClass())) { query.setString("insuranceClass", "%" + insurance.getInsuranceClass() + "%"); } if (vehicle != null) { if (!StringUtils.isEmpty(vehicle.getLicenseNum())) { query.setString("licenseNum", "%" + vehicle.getLicenseNum() + "%"); } } query.setFirstResult(page.getBeginIndex()); query.setMaxResults(page.getEveryPage()); return query.list(); } catch (HibernateException e) { throw e; } finally { HibernateSessionFactory.closeSession(); } }
From source file:com.dz.module.vehicle.VehicleAction.java
public String relookLicence() { Session s = null;// w ww .j ava 2 s . com Transaction tx = null; try { s = HibernateSessionFactory.getSession(); tx = s.beginTransaction(); Query query = s.createQuery("from License where state=0"); List<License> is = query.list(); for (License i : is) { Vehicle v = (Vehicle) s.get(Vehicle.class, i.getCarframeNum()); BeanUtils.copyProperties(i, v, new String[] { "state" }); s.update(v); i.setState(1); s.update(i); Query q_c = s.createQuery( "select c from Contract c where c.state in (2,3) and c.idNum=:idNum and c.carframeNum=:carframeNum "); q_c.setString("idNum", v.getDriverId()); q_c.setString("carframeNum", v.getCarframeNum()); q_c.setMaxResults(1); Contract c = (Contract) q_c.uniqueResult(); if (c != null) { c.setCarNum(v.getLicenseNum()); s.saveOrUpdate(c); Query q_va = s.createQuery("from VehicleApproval c where c.contractId=:cid and c.checkType=0 "); q_va.setInteger("cid", c.getId()); q_va.setMaxResults(1); VehicleApproval approval = (VehicleApproval) q_va.uniqueResult(); approval.setLicenseRegisterDate(v.getLicenseNumRegDate()); approval.setOperateApplyDate(new Date()); s.saveOrUpdate(approval); } Message msg = new Message(); User u = (User) s.get(User.class, v.getLicenseRegister()); msg.setFromUser(v.getLicenseRegister()); msg.setTime(new Date()); msg.setCarframeNum(v.getCarframeNum()); msg.setType(""); msg.setMsg(String.format( "%tF %s?\n" + "%s(%s) ??", msg.getTime(), u.getUname(), v.getLicenseNum(), v.getCarframeNum())); s.saveOrUpdate(msg); Query q_us = s.createQuery( "from RelationUr where rid in (select rid from Role where rname = '')"); List<RelationUr> users = q_us.list(); for (RelationUr relationUr : users) { MessageToUser mu = new MessageToUser(); mu.setUid(relationUr.getUid()); mu.setMid(msg.getId()); mu.setAlreadyRead(false); s.saveOrUpdate(mu); } } tx.commit(); } catch (HibernateException e) { e.printStackTrace(); if (tx != null) { tx.rollback(); } request.setAttribute("msgStr", "" + e.getMessage()); return SUCCESS; } finally { HibernateSessionFactory.closeSession(); } request.setAttribute("msgStr", "??"); return SUCCESS; }
From source file:com.dz.module.vehicle.VehicleAction.java
public String revokeLicence() { Session s = null;/* w w w . ja v a 2 s. c o m*/ Transaction tx = null; try { s = HibernateSessionFactory.getSession(); tx = s.beginTransaction(); License i = (License) s.get(License.class, vehicle.getCarframeNum()); if (i == null || i.getState() != 1) { request.setAttribute("msgStr", ""); return SUCCESS; } Vehicle v = (Vehicle) s.get(Vehicle.class, i.getCarframeNum()); Query q_c = s.createQuery( "select c from Contract c where c.state=0 and c.idNum=:idNum and c.carframeNum=:carframeNum "); q_c.setString("idNum", v.getDriverId()); q_c.setString("carframeNum", v.getCarframeNum()); q_c.setMaxResults(1); Contract c = (Contract) q_c.uniqueResult(); if (c != null) { request.setAttribute("msgStr", "????"); return SUCCESS; } License ispace = new License(); ispace.setCarframeNum(v.getCarframeNum()); BeanUtils.copyProperties(ispace, v, new String[] { "state" }); i.setState(0); s.saveOrUpdate(i); s.saveOrUpdate(v); tx.commit(); } catch (HibernateException e) { e.printStackTrace(); if (tx != null) { tx.rollback(); } request.setAttribute("msgStr", "" + e.getMessage()); return SUCCESS; } finally { HibernateSessionFactory.closeSession(); } request.setAttribute("msgStr", "??"); return SUCCESS; }