List of usage examples for org.hibernate Criteria setMaxResults
public Criteria setMaxResults(int maxResults);
From source file:com.prueba.spring.dao.impl.ColaboradorDAO.java
@Transactional(readOnly = true) public RespuestaGenerica<jqGridModel> obtenerTodosGrid(String indice, String orden, int paginaActual, int cantidadRegistros) { RespuestaGenerica<jqGridModel> respuesta; try {/*from w ww. ja v a 2 s. c om*/ this.iniciaOperacion(); jqGridModel<Colaborador> model = new jqGridModel<Colaborador>(); model.setPage(paginaActual); model.setRecords(this.cantidadRegistros().getRespuesta()); model.setTotal((int) Math.ceil((double) model.getRecords() / (double) cantidadRegistros)); Criteria criteria = session.createCriteria(Colaborador.class); criteria.setFirstResult((paginaActual - 1) * cantidadRegistros); criteria.setMaxResults(cantidadRegistros); if (orden.equalsIgnoreCase("asc")) { criteria.addOrder(Order.asc(indice)); } else if (orden.equalsIgnoreCase("desc")) { criteria.addOrder(Order.desc(indice)); } model.setRows(criteria.list()); respuesta = new RespuestaGenerica<jqGridModel>(model); } catch (Exception ex) { Logger.getLogger(ColaboradorDAO.class.getName()).log(Level.SEVERE, null, ex); respuesta = new RespuestaGenerica<jqGridModel>(ex); } finally { try { session.close(); } catch (Exception ex) { Logger.getLogger(ColaboradorDAO.class.getName()).log(Level.SEVERE, null, ex); } } return respuesta; }
From source file:com.prueba.spring.dao.impl.EventoDAO.java
@Transactional(readOnly = true) public RespuestaGenerica<jqGridModel> obtenerTodosGrid(String indice, String orden, int paginaActual, int cantidadRegistros) { RespuestaGenerica<jqGridModel> respuesta; try {/* www. j a va2 s . co m*/ jqGridModel<Evento> model = new jqGridModel<Evento>(); model.setPage(paginaActual); model.setRecords(this.cantidadRegistros().getRespuesta()); model.setTotal((int) Math.ceil((double) model.getRecords() / (double) cantidadRegistros)); Criteria criteria = session.createCriteria(Evento.class); criteria.setFirstResult((paginaActual - 1) * cantidadRegistros); criteria.setMaxResults(cantidadRegistros); if (orden.equalsIgnoreCase("asc")) { criteria.addOrder(Order.asc(indice)); } else if (orden.equalsIgnoreCase("desc")) { criteria.addOrder(Order.desc(indice)); } model.setRows(criteria.list()); respuesta = new RespuestaGenerica<jqGridModel>(model); } catch (Exception ex) { Logger.getLogger(EventoDAO.class.getName()).log(Level.SEVERE, null, ex); respuesta = new RespuestaGenerica<jqGridModel>(ex); } finally { try { session.close(); } catch (Exception ex) { Logger.getLogger(EventoDAO.class.getName()).log(Level.SEVERE, null, ex); } } return respuesta; }
From source file:com.prueba.spring.dao.impl.UsuarioDAO.java
@Transactional(readOnly = true) public RespuestaGenerica<jqGridModel<Usuario>> obtenerTodosGrid(String indice, String orden, int paginaActual, int cantidadRegistros) { RespuestaGenerica<jqGridModel<Usuario>> respuesta; try {//from w ww. java 2 s.c o m this.iniciaOperacion(); jqGridModel<Usuario> model = new jqGridModel(); model.setPage(paginaActual); model.setRecords(this.cantidadRegistros().getRespuesta()); model.setTotal((int) Math.ceil((double) model.getRecords() / (double) cantidadRegistros)); Criteria criteria = session.createCriteria(Usuario.class); criteria.setFirstResult((paginaActual - 1) * cantidadRegistros); criteria.setMaxResults(cantidadRegistros); if (orden.equalsIgnoreCase("asc")) { criteria.addOrder(Order.asc(indice)); } else if (orden.equalsIgnoreCase("desc")) { criteria.addOrder(Order.desc(indice)); } model.setRows(criteria.list()); respuesta = new RespuestaGenerica(model); } catch (Exception ex) { Logger.getLogger(UsuarioDAO.class.getName()).log(Level.SEVERE, null, ex); respuesta = new RespuestaGenerica(ex); } finally { try { session.close(); } catch (Exception ex) { Logger.getLogger(UsuarioDAO.class.getName()).log(Level.SEVERE, null, ex); } } return respuesta; }
From source file:com.qcadoo.model.internal.search.SearchCriteriaImpl.java
License:Open Source License
@Override public void addFirstAndMaxResults(final Criteria criteria) { criteria.setMaxResults(maxResults).setFirstResult(firstResult); }
From source file:com.quix.aia.cn.imo.mapper.AddressBookMaintenance.java
License:Open Source License
/** * <p>//from w w w .ja v a 2 s . c o m * This method retrieves all AddressBooks of Particular Agent * <p> * * @param agentID * @return List<AddressBook> List of Class Object * */ public List<AddressBook> getAgentAddressBook(HttpServletRequest request, ServletContext context) { Session session = null; ArrayList<AddressBook> list = null; Criteria criteria = null; CandidateEducationMaintenance candidateEducationMaintenance = new CandidateEducationMaintenance(); CandidateESignatureMaintenance candidateESignatureMaintenance = new CandidateESignatureMaintenance(); CandidateFamilyInfoMaintenance candidateFamilyInfoMaintenance = new CandidateFamilyInfoMaintenance(); CandidateGroupMaintenance candidateGroupMaintenance = new CandidateGroupMaintenance(); CandidateProfessionalCertificationMaintenance candidateProfessionalCertificationMaintenance = new CandidateProfessionalCertificationMaintenance(); CandidateWorkExperienceMaintenance candidateWorkExperienceMaintenance = new CandidateWorkExperienceMaintenance(); CandidateNoteMaintenance candidateNoteMaintenance = new CandidateNoteMaintenance(); Map<String, String> configurationMap = (Map<String, String>) context .getAttribute(ApplicationAttribute.CONFIGURATION_PROPERTIES_MAP); int addressBookListingOffset = 0; addressBookListingOffset = Integer.parseInt(configurationMap.get("addressBookListingOffset")); String agentId = request.getParameter("agentId"); String pageNo = request.getParameter("pageNo"); String dateTime = request.getParameter("dateTime"); String coBranch = request.getParameter("co"); int firstRecordNo = 0; agentId = agentId == null ? "" : agentId; pageNo = pageNo == null ? "0" : pageNo; Date date = null; if (null != dateTime && !"".equals(dateTime)) { date = LMSUtil.convertDateToyyyymmddhhmmssDashed(dateTime); } if (Long.parseLong(pageNo) > 0) { firstRecordNo = ((addressBookListingOffset * Integer.parseInt(pageNo)) - addressBookListingOffset); } try { session = HibernateFactory.openSession(); criteria = session.createCriteria(AddressBook.class); criteria.setFirstResult(firstRecordNo); criteria.setMaxResults(addressBookListingOffset); criteria.add(Restrictions.eq("agentId", agentId)); if (null != date) { criteria.add(Expression.ge("modificationDate", date)); } if (null != coBranch && !"".equals(coBranch)) { criteria.add(Restrictions.eq("co", coBranch)); } list = (ArrayList) criteria.list(); for (AddressBook addressBook : list) { addressBook.setCandidateEducations(candidateEducationMaintenance .readCandidateEducations(addressBook.getCandidateEducations())); addressBook.setCandidateESignatures(candidateESignatureMaintenance .readCandidateESignatures(addressBook.getCandidateESignatures())); addressBook.setCandidateFamilyInfos(candidateFamilyInfoMaintenance .readCandidateFamilyInfos(addressBook.getCandidateFamilyInfos())); addressBook.setCandidateGroups( candidateGroupMaintenance.readCandidateGroups(addressBook.getCandidateGroups())); addressBook.setCandidateProfessionalCertifications( candidateProfessionalCertificationMaintenance.readCandidateProfessionalCertifications( addressBook.getCandidateProfessionalCertifications())); addressBook.setCandidateWorkExperiences(candidateWorkExperienceMaintenance .readCandidateWorkExperiences(addressBook.getCandidateWorkExperiences())); addressBook.setCandidateNotes( candidateNoteMaintenance.readCandidateNotes(addressBook.getCandidateNotes())); } } catch (Exception ex) { log.log(Level.SEVERE, ex.getMessage()); ex.printStackTrace(); LogsMaintenance logsMain = new LogsMaintenance(); StringWriter errors = new StringWriter(); ex.printStackTrace(new PrintWriter(errors)); logsMain.insertLogs("AddressBookMaintenance", Level.SEVERE + "", errors.toString()); list = new ArrayList<AddressBook>(); } finally { try { HibernateFactory.close(session); } catch (Exception e) { log.log(Level.SEVERE, e.getMessage()); e.printStackTrace(); } session = null; criteria = null; candidateEducationMaintenance = null; candidateESignatureMaintenance = null; candidateFamilyInfoMaintenance = null; candidateGroupMaintenance = null; candidateProfessionalCertificationMaintenance = null; candidateWorkExperienceMaintenance = null; candidateNoteMaintenance = null; } return list; }
From source file:com.rajtech.stockwebservice.dao.Impl.CustomerDaoImpl.java
@Override public List<Customer> findByPage(int page, int no_of_record) { List<Customer> customers = null; if (page == 0) { page = 1;/*from w w w.j a va 2 s. c o m*/ } int indexPage = (page * no_of_record) - no_of_record; Criteria criteria = createEntityCriteria(); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); criteria.setFirstResult(indexPage); criteria.setMaxResults(no_of_record); customers = criteria.list(); return customers; }
From source file:com.rajtech.stockwebservice.dao.Impl.PackageSizrDaoImpl.java
@Override public List<PackagesSize> findByPage(int page, int no_of_record) { List<PackagesSize> packagesSizes = null; if (page == 0) { page = 1;/* w w w . jav a2s.c o m*/ } int indexPage = (page * no_of_record) - no_of_record; Criteria criteria = createEntityCriteria(); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); criteria.setFirstResult(indexPage); criteria.setMaxResults(no_of_record); packagesSizes = criteria.list(); return packagesSizes; }
From source file:com.rajtech.stockwebservice.dao.Impl.PackDaoImpl.java
@Override public List<PackMaster> findByPage(int page, int no_of_record) { List<PackMaster> packMasters = null; if (page == 0) { page = 1;//from w w w . j a va 2s .c o m } int indexPage = (page * no_of_record) - no_of_record; Criteria criteria = createEntityCriteria(); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); criteria.setFirstResult(indexPage); criteria.setMaxResults(no_of_record); packMasters = criteria.list(); return packMasters; }
From source file:com.rajtech.stockwebservice.dao.Impl.PurchaseDaoImpl.java
@Override public List<PurchaseMaster> findByPage(int page, int no_of_record) { List<PurchaseMaster> purchaseMasters = null; if (page == 0) { page = 1;//w w w. ja v a 2s. c o m } int indexPage = (page * no_of_record) - no_of_record; Criteria criteria = createEntityCriteria(); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); criteria.setFirstResult(indexPage); criteria.setMaxResults(no_of_record); purchaseMasters = criteria.list(); return purchaseMasters; }