List of usage examples for org.hibernate Criteria setFirstResult
public Criteria setFirstResult(int firstResult);
From source file:com.facade.CustomerFacade.java
public void setPagination(Pagination pagination) { Transaction trans = null;//from www . j a v a 2s . c om try { Session session = MyUtils.getSession(); if (session != null) { trans = session.beginTransaction(); Criteria cr = session.createCriteria(Customer.class); cr.setFirstResult(pagination.getFirstResult()); cr.setMaxResults(pagination.getDisplayPerPage()); cr.addOrder(pagination.isAsc() ? Order.asc(pagination.getOrderColmn()) : Order.desc(pagination.getOrderColmn())); pagination.setDisplayList(cr.list()); trans.commit(); } } catch (Exception e) { try { if (trans != null && trans.isActive()) { trans.rollback(); } } catch (Exception ex) { throw ex; } Logger.getLogger(Module.class.getName()).log(Level.SEVERE, null, e); } }
From source file:com.fich.wafproject.dao.UserDaoImpl.java
public List<Users> findAll(int pageNumber, String[] targets, String[] names, String[] values, boolean pagination) { int pageSize = 4; Criteria crit = this.createEntityCriteria(); crit.setProjection(Projections.distinct(Projections.property("id"))); String dateFrom = "", dateTo = "", targetDate = ""; if (names != null) { for (String alias : names) { crit.createAlias(alias, alias); }/*from w w w . j a va 2s. co m*/ } int count = 0; if (values != null) { for (String value : values) { if (!value.equals("") && value != null) { if (targets[count].contains("date")) { if (dateFrom != "") { dateTo = value; } else { dateFrom = value; targetDate = targets[count]; } } else { crit.add(Restrictions.like(targets[count], "%" + value + "%")); } } count++; } if (targetDate != "") { if (dateFrom != "" && dateTo == "") { dateTo = dateFrom; } DateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH); try { Date dateF = format.parse(dateFrom); Date dateT = format.parse(dateTo); crit.add(Restrictions.between(targetDate, dateF, dateT)); } catch (ParseException ex) { Logger.getLogger(UserDaoImpl.class.getName()).log(Level.SEVERE, null, ex); } } } if (pagination) { crit.setFirstResult((pageNumber - 1) * pageSize); crit.setMaxResults(pageSize); } List<Users> users = new ArrayList<Users>(); for (Object idEvent : crit.list()) { // System.out.println(idEvent); users.add(this.findById((Long) idEvent)); } return (List<Users>) users; }
From source file:com.fich.wafproject.dao.UserHistoryDaoImpl.java
@SuppressWarnings("unchecked") public List<UsersHistory> findAll(int pageNumber) { int pageSize = 6; Criteria crit = createEntityCriteria(); crit.setProjection(Projections.distinct(Projections.property("id"))); crit.setFirstResult((pageNumber - 1) * pageSize); crit.setMaxResults(pageSize);/* w ww.j a v a 2 s. c o m*/ List<UsersHistory> events = new ArrayList<UsersHistory>(); for (Object idUsersHistory : crit.list()) { // System.out.println(idUsersHistory); events.add(this.findById((Long) idUsersHistory)); } return events; }
From source file:com.fich.wafproject.dao.UserHistoryDaoImpl.java
public List<UsersHistory> filter(String[] values, String[] names, String[] targets, int pageNumber, String role) {/*from ww w . j av a 2s .c o m*/ int pageSize = 6; int count = 0; boolean filterByUserProperty = false, filterByUserName = false; Criteria crit = this.createEntityCriteria();//.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); crit.setProjection(Projections.distinct(Projections.property("id"))); String dateFrom = "", dateTo = "", targetDate = ""; if (names != null) { for (String alias : names) { crit.createAlias(alias, alias); if (alias.equals("user")) filterByUserProperty = true; } } if (!filterByUserProperty && !role.equals("")) crit.createAlias("user", "user"); if (values != null) { for (String value : values) { if (!value.equals("") && value != null) { if (targets[count].contains("date")) { if (dateFrom != "") { dateTo = value; } else { dateFrom = value; targetDate = targets[count]; } } else { if (targets[count].contains("userName")) filterByUserName = true; crit.add(Restrictions.like(targets[count], "%" + value + "%")); } } count++; } if (targetDate != "") { if (dateFrom != "" && dateTo == "") { dateTo = dateFrom; } DateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH); try { Date dateF = format.parse(dateFrom); Date dateT = format.parse(dateTo); crit.add(Restrictions.between(targetDate, dateF, dateT)); } catch (ParseException ex) { Logger.getLogger(UserHistoryDaoImpl.class.getName()).log(Level.SEVERE, null, ex); } } } if (!filterByUserName && !role.equals("")) crit.add(Restrictions.like("user.userName", role)); crit.setFirstResult((pageNumber - 1) * pageSize); crit.setMaxResults(pageSize); List<UsersHistory> events = new ArrayList<UsersHistory>(); for (Object idEvent : crit.list()) { events.add(this.findById((Long) idEvent)); } return (List<UsersHistory>) events; }
From source file:com.floreantpos.model.dao.KitchenTicketDAO.java
License:Open Source License
public List<Ticket> findNextKitchenTickets(PaginatedTableModel tableModel) { Session session = null;//from www.j av a 2 s.c o m Criteria criteria = null; try { int nextIndex = tableModel.getNextRowIndex(); session = createNewSession(); criteria = session.createCriteria(getReferenceClass()); criteria.setFirstResult(nextIndex); criteria.setMaxResults(tableModel.getPageSize()); List kitchenTicketList = criteria.list(); criteria.setProjection(Projections.rowCount()); Integer rowCount = (Integer) criteria.uniqueResult(); if (rowCount != null) { tableModel.setNumRows(rowCount); } tableModel.setCurrentRowIndex(nextIndex); return kitchenTicketList; } finally { closeSession(session); } }
From source file:com.floreantpos.model.dao.KitchenTicketDAO.java
License:Open Source License
public List<Ticket> findPreviousKitchenTickets(PaginatedTableModel tableModel) { Session session = null;//ww w. j av a 2s.com Criteria criteria = null; try { int previousIndex = tableModel.getPreviousRowIndex(); session = createNewSession(); criteria = session.createCriteria(getReferenceClass()); criteria.setFirstResult(previousIndex); criteria.setMaxResults(tableModel.getPageSize()); List kitchenTicketList = criteria.list(); criteria.setProjection(Projections.rowCount()); Integer rowCount = (Integer) criteria.uniqueResult(); if (rowCount != null) { tableModel.setNumRows(rowCount); } tableModel.setCurrentRowIndex(previousIndex); return kitchenTicketList; } finally { closeSession(session); } }
From source file:com.floreantpos.model.dao.TicketDAO.java
License:Open Source License
public List<Ticket> findTickets(PaginatedTableModel tableModel) { Session session = null;/*from w ww . j a va 2s . c o m*/ Criteria criteria = null; try { session = createNewSession(); criteria = session.createCriteria(getReferenceClass()); updateCriteriaFilters(criteria); criteria.setFirstResult(0); criteria.setMaxResults(tableModel.getPageSize()); List ticketList = criteria.list(); criteria.setProjection(Projections.rowCount()); Integer rowCount = (Integer) criteria.uniqueResult(); if (rowCount != null) { tableModel.setNumRows(rowCount); } tableModel.setCurrentRowIndex(0); return ticketList; } finally { closeSession(session); } }
From source file:com.floreantpos.model.dao.TicketDAO.java
License:Open Source License
public List<Ticket> findNextTickets(PaginatedTableModel tableModel) { Session session = null;//from w ww .ja v a 2 s . com Criteria criteria = null; try { int nextIndex = tableModel.getNextRowIndex(); session = createNewSession(); criteria = session.createCriteria(getReferenceClass()); updateCriteriaFilters(criteria); criteria.setFirstResult(nextIndex); criteria.setMaxResults(tableModel.getPageSize()); List ticketList = criteria.list(); criteria.setProjection(Projections.rowCount()); Integer rowCount = (Integer) criteria.uniqueResult(); if (rowCount != null) { tableModel.setNumRows(rowCount); } tableModel.setCurrentRowIndex(nextIndex); return ticketList; } finally { closeSession(session); } }
From source file:com.floreantpos.model.dao.TicketDAO.java
License:Open Source License
public List<Ticket> findPreviousTickets(PaginatedTableModel tableModel) { Session session = null;/*from w ww . jav a2 s. co m*/ Criteria criteria = null; try { int previousIndex = tableModel.getPreviousRowIndex(); session = createNewSession(); criteria = session.createCriteria(getReferenceClass()); updateCriteriaFilters(criteria); criteria.setFirstResult(previousIndex); criteria.setMaxResults(tableModel.getPageSize()); List ticketList = criteria.list(); criteria.setProjection(Projections.rowCount()); Integer rowCount = (Integer) criteria.uniqueResult(); if (rowCount != null) { tableModel.setNumRows(rowCount); } tableModel.setCurrentRowIndex(previousIndex); return ticketList; } finally { closeSession(session); } }
From source file:com.floreantpos.model.dao.TicketDAO.java
License:Open Source License
public List<Ticket> findCustomerTickets(Integer customerId, PaginatedTableModel tableModel) { Session session = null;/*from ww w. ja v a2s . c o m*/ Criteria criteria = null; try { session = createNewSession(); criteria = session.createCriteria(getReferenceClass()); criteria.add(Restrictions.eq(Ticket.PROP_CUSTOMER_ID, customerId)); /*if (filter.equals(PaymentStatusFilter.OPEN.toString())) { criteria.add(Restrictions.eq(Ticket.PROP_PAID, Boolean.FALSE)); criteria.add(Restrictions.eq(Ticket.PROP_CLOSED, Boolean.FALSE)); }*/ criteria.setFirstResult(0); criteria.setMaxResults(tableModel.getPageSize()); List ticketList = criteria.list(); criteria.setProjection(Projections.rowCount()); Integer rowCount = (Integer) criteria.uniqueResult(); if (rowCount != null) { tableModel.setNumRows(rowCount); } tableModel.setCurrentRowIndex(0); return ticketList; } finally { closeSession(session); } }