List of usage examples for org.hibernate Criteria setFirstResult
public Criteria setFirstResult(int firstResult);
From source file:com.myapp.core.base.dao.impl.AbstractBaseDao.java
/** * ? ?? ?// w w w . j a v a 2 s . c om * ? ??? */ @Deprecated public PageModel toPageDetachedCriteria(Class claz, DetachedCriteria dca, ProjectionList pList, Integer curPage, Integer pageSize) throws QueryException { Criteria query = dca.getExecutableCriteria(getCurrentSession()); long rowCount = ((Long) query.setProjection(Projections.rowCount()).uniqueResult()).longValue(); PageModel pm = new PageModel(curPage, pageSize, rowCount); if (pList != null) { query.setProjection(pList); } else { query.setProjection(null); } query.setResultTransformer(Transformers.aliasToBean(claz)); query.setFirstResult(pm.getStartNum()); query.setMaxResults(pageSize); pm.setDatas(query.list()); return pm; }
From source file:com.mycompany.restful.dao.FeatureDao.java
public JSONObject getFeatures(RequestParams param) { Object recordsFiltered = 0, recordsTotal = 0; Criteria Features; List<Feature> features; Session session = null;//from www. j a v a 2s .c o m JSONObject obj = new JSONObject(); try { session = sessionFactory.openSession(); session.beginTransaction(); Features = session.createCriteria(Feature.class); if (!"".equals(param.getValue()) && param.getValue() != null) { Criterion rest1 = Restrictions.like("renderingEngine", "%" + param.getValue() + "%"); Criterion rest2 = Restrictions.like("browser", "%" + param.getValue() + "%"); Criterion rest3 = Restrictions.like("platform", "%" + param.getValue() + "%"); Criterion rest4 = Restrictions.like("engineVersion", "%" + param.getValue() + "%"); Criterion rest5 = Restrictions.like("cssGrade", "%" + param.getValue() + "%"); Features.add(Restrictions.or(rest1, rest2, rest3, rest4, rest5)); } if (!"".equals(param.getColumn()) && param.getColumn() != null) { if ("asc".equals(param.getDir())) { Features.addOrder(Order.asc(param.getColumn())); } else { Features.addOrder(Order.desc(param.getColumn())); } } recordsTotal = session.createCriteria(Feature.class).setProjection(Projections.rowCount()).list() .get(0); recordsFiltered = Features.list().size(); Features.setFirstResult(param.getStart()).setMaxResults(param.getLength()); features = Features.list(); obj.put("total", recordsTotal); obj.put("filtered", recordsFiltered); obj.put("data", features); session.getTransaction().commit(); } catch (Exception ex) { if (session != null) { session.getTransaction().rollback(); } } finally { if (session != null) { session.close(); } } return obj; }
From source file:com.painiu.core.dao.hibernate.PhotoDAOHibernate.java
License:Open Source License
public Result getPhotos(final User user, final String[] tags, final boolean taggedAll, final String text, final int start, final int limit, final Relation relation) { return (Result) getReadOnlyHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { //Criteria criteria = buildCountPhotoCriteria(session, user, group, tags, taggedAll, text, relation); Criteria criteria = buildCountPhotoCriteria(session, user, tags, taggedAll, text, relation); int count = ((Integer) criteria.list().iterator().next()).intValue(); //criteria = buildPhotoCriteria(session, user, group, tags, taggedAll, text, relation, false); criteria = buildPhotoCriteria(session, user, tags, taggedAll, text, relation, false); List data = criteria.setFirstResult(start).setMaxResults(limit).list(); Result result = new Result(start, limit); result.setTotal(count);/* w ww. j a va 2 s . c o m*/ result.setData(data); if (user != null) { for (Iterator i = data.iterator(); i.hasNext();) { Photo photo = (Photo) i.next(); photo.setUser(user); } } return result; } }); }
From source file:com.project.framework.dao.BaseDao.java
License:Apache License
/** * ?Criteria,.//from w ww . j av a 2 s . c om */ protected Criteria setPageParameter(final Criteria c, final Page<T> page) { if (page.getStartIndex() > Integer.MAX_VALUE) throw new ClassCastException("Hibernate can not support startIndex Greater than Integer.Max"); //hibernatefirstResult??0 c.setFirstResult((int) page.getStartIndex()); c.setMaxResults(page.getPageSize()); //order by ? if (page.isOrder()) { Map<String, String> orderMap = page.getOrderMap(); Iterator<String> iterator = orderMap.keySet().iterator(); while (iterator.hasNext()) { String propertyName = iterator.next(); if (orderMap.get(propertyName).equals(Page.ORDER_ASC)) { c.addOrder(Order.asc(propertyName)); } else { c.addOrder(Order.desc(propertyName)); } } } return c; }
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 . j a v a 2 s . co m 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 {//from ww w. j a v a 2 s. c o 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 {/*ww w.j a v a 2s . co 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.quix.aia.cn.imo.mapper.AddressBookMaintenance.java
License:Open Source License
/** * <p>/*from w w w . ja v a 2 s.c om*/ * 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;// www . 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;//from ww w . j ava 2s .c om } 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; }