List of usage examples for org.hibernate Query setFirstResult
@Override
Query<R> setFirstResult(int startPosition);
From source file:com.dungnv.vfw5.base.dao.BaseFWDAOImpl.java
License:Open Source License
public List<T> findSession(String boName, List<ConditionBean> lstCondition, String order, int start, int maxResult, String logic, Session session) { // if (logic == null) { // logic = ParamUtils.LOGIC_AND; // }//from w w w. ja v a 2 s. c om try { StringBuilder sql = new StringBuilder(); sql.append(" from "); sql.append(boName); sql.append(" where 1=1 "); if (lstCondition != null && !lstCondition.isEmpty()) { buildConditionQuery(sql, lstCondition); } if (order != null && !order.equals("")) { sql.append(" order by "); sql.append(order); } Query query = session.createQuery(sql.toString()); if (maxResult != 0) { query.setFirstResult(start); query.setMaxResults(maxResult); } fillConditionQuery(query, lstCondition); return query.list(); } catch (HibernateException he) { log.error(he.getMessage(), he); return null; } }
From source file:com.dz.module.contract.BankCardAction.java
public String searchCard() { int currentPage = 0; if (request.getParameter("currentPage") != null && !(request.getParameter("currentPage")).isEmpty()) { currentPage = Integer.parseInt(request.getParameter("currentPage")); System.out.println(request.getParameter("currentPage")); } else {//from ww w .j a v a 2 s.co m currentPage = 1; } if (bankCard == null) { bankCard = new BankCard(); } String hql = "from BankCard where 1=1 "; if (!StringUtils.isEmpty(dept) && !dept.startsWith("all")) { hql += String.format("and carNum in (select licenseNum from Vehicle where dept='%s') ", dept); } if (!StringUtils.isEmpty(bankCard.getIdNumber())) { hql += String.format("and idNumber like '%%%s%%' ", bankCard.getIdNumber()); } if (!StringUtils.isEmpty(bankCard.getCardNumber())) { hql += String.format("and cardNumber like '%%%s%%' ", bankCard.getCardNumber()); } if (!StringUtils.isEmpty(bankCard.getCarNum())) { hql += String.format("and carNum in(select carframeNum from Vehicle where licenseNum like '%%%s%%') ", bankCard.getCarNum()); } hql += " order by " + order; if (BooleanUtils.isFalse(rank)) { hql += " desc "; } Session session = HibernateSessionFactory.getSession(); Query query = session.createQuery(hql); Query query2 = session.createQuery("select count(*) " + hql); long count = (long) query2.uniqueResult(); Page page = PageUtil.createPage(30, (int) count, currentPage); query.setFirstResult(page.getBeginIndex()); query.setMaxResults(page.getEveryPage()); List<BankCard> cardList = query.list(); HibernateSessionFactory.closeSession(); request.setAttribute("list", cardList); request.setAttribute("page", page); return SUCCESS; }
From source file:com.dz.module.contract.ContractDaoImpl.java
@SuppressWarnings("unchecked") @Override/* w ww . jav a 2 s. c o m*/ public List<Contract> contractSearch(Page page) throws HibernateException { List<Contract> l = new ArrayList<Contract>(); Session session = null; Transaction tx = null; try { session = HibernateSessionFactory.getSession(); tx = (Transaction) session.beginTransaction(); Query query = session.createQuery("from Contract"); query.setMaxResults(15); query.setFirstResult(page.getBeginIndex()); l = query.list(); query = null; tx.commit(); } catch (HibernateException e) { if (tx != null) { tx.rollback(); } throw e; } finally { HibernateSessionFactory.closeSession(); } return l; }
From source file:com.dz.module.contract.ContractDaoImpl.java
@SuppressWarnings("unchecked") @Override/*from w ww.j ava 2s.c o m*/ public List<Contract> contractSearchAvilable(Page page) throws HibernateException { List<Contract> l = new ArrayList<Contract>(); Session session = null; Transaction tx = null; try { session = HibernateSessionFactory.getSession(); tx = (Transaction) session.beginTransaction(); Query query = session.createQuery("from Contract where state in (0,1)"); query.setMaxResults(15); query.setFirstResult(page.getBeginIndex()); l = query.list(); query = null; tx.commit(); } catch (HibernateException e) { if (tx != null) { tx.rollback(); } throw e; } finally { HibernateSessionFactory.closeSession(); } return l; }
From source file:com.dz.module.contract.ContractDaoImpl.java
/** * / ???,/*from ww w . jav a 2s. co m*/ * @param currentClearTime * @param dept * @param page ,null,???. * @return ??. */ @Override public List<Contract> contractSearchAllAvilable(Date currentClearTime, String dept, Page page) { List<Contract> l = new ArrayList<Contract>(); Session session = null; Transaction tx = null; try { session = HibernateSessionFactory.getSession(); tx = (Transaction) session.beginTransaction(); Query query = null; if ("".equals(dept)) { query = session.createQuery("from Contract where state in (0,-1,1,4)"); } else { query = session.createQuery("from Contract where state in (0,-1,1,4) and branchFirm = :dept"); query.setString("dept", dept); } if (page != null) { query.setFirstResult(page.getBeginIndex()); query.setMaxResults(page.getEveryPage()); } l = query.list(); Iterator<Contract> iterators = l.iterator(); filterContractThatStateEq1Charge(currentClearTime, iterators); tx.commit(); } catch (HibernateException e) { if (tx != null) { tx.rollback(); } throw e; } finally { HibernateSessionFactory.closeSession(); } return l; }
From source file:com.dz.module.contract.ContractDaoImpl.java
@SuppressWarnings("unchecked") @Override/*from w w w .j a v a2 s . co m*/ public List<Contract> contractSearchAbandoned(Page page) throws HibernateException { List<Contract> l = new ArrayList<Contract>(); Session session = null; Transaction tx = null; try { session = HibernateSessionFactory.getSession(); tx = (Transaction) session.beginTransaction(); Query query = session.createQuery("from Contract where state not in (0,-1)"); query.setMaxResults(15); query.setFirstResult(page.getBeginIndex()); l = query.list(); query = null; tx.commit(); } catch (HibernateException e) { if (tx != null) { tx.rollback(); } throw e; } finally { HibernateSessionFactory.closeSession(); } return l; }
From source file:com.dz.module.contract.ContractDaoImpl.java
@SuppressWarnings("unchecked") @Override/* ww w . j av a 2 s . c om*/ public List<Contract> contractSearchCondition(Page page, Integer contractid, String contractor, Long rent, Boolean isabandoned, String sort, String desc) throws HibernateException { List<Contract> l = new ArrayList<Contract>(); Session session = null; Transaction tx = null; try { session = HibernateSessionFactory.getSession(); tx = (Transaction) session.beginTransaction(); String sql = "from Contract"; if (contractid == null && StringUtils.isEmpty(contractor) && rent == null) { sql += " where 1=1"; } else { sql += " where 0=1"; } if (contractid != null) { sql += " or contractId=" + contractid; } if (!StringUtils.isEmpty(contractor)) { sql += " or contractorName=" + contractor; } if (rent != null) { sql += " or rent=" + rent; } sql += " and isAbandoned=: isabandoned"; if (sort.equals("0")) { sql += " order by contractId"; } else if (sort.equals("1")) { sql += " order by rent"; } if (desc.equals("0")) { } else if (desc.equals("1")) { sql += " desc"; } System.out.println(sql); Query query = session.createQuery(sql); query.setBoolean("isabandoned", isabandoned); query.setMaxResults(15); query.setFirstResult(page.getBeginIndex()); l = query.list(); query = null; tx.commit(); } catch (HibernateException e) { if (tx != null) { tx.rollback(); } throw e; } finally { HibernateSessionFactory.closeSession(); } return l; }
From source file:com.dz.module.contract.ContractDaoImpl.java
@SuppressWarnings("unchecked") @Override// w w w . ja va 2 s .com 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
@SuppressWarnings("unchecked") @Override//from ww w . ja v a 2 s .c om public List<Complain> selectAll(Page page, Date beginDate, Date endDate) throws HibernateException { Session session = null; try { session = HibernateSessionFactory.getSession(); String hql = "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); } 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
/** * ?//from w ww.j av a2 s .co 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(); } }