List of usage examples for org.hibernate Criteria setFirstResult
public Criteria setFirstResult(int firstResult);
From source file:com.square.core.dao.implementations.RessourceServiceDaoImplementation.java
License:Open Source License
@SuppressWarnings("unchecked") @Override//ww w.jav a 2 s . c o m public List<RessourceService> rechercherRessourceServiceParCriteres(DimensionCriteresRechercheDto criteres) { final Criteria criteria = createCriteria(RessourceService.class); // Critre sur l'identifiant if (criteres.getId() != null) { criteria.add(Restrictions.eq("id", criteres.getId())); } // Critre sur le libell if (criteres.getLibelle() != null && !criteres.getLibelle().equals("")) { criteria.add(Restrictions.ilike("libelle", criteres.getLibelle().toLowerCase() + "%")); } // Critre sur l'identifiant extrieur if (criteres.getIdentifiantExterieur() != null && !"".equals(criteres.getIdentifiantExterieur())) { criteria.add(Restrictions.eq("identifiantExterieur", criteres.getIdentifiantExterieur())); } // Critre sur une liste d'identifiants extrieurs if (criteres.getEids() != null && criteres.getEids().size() > 0) { criteria.add(Restrictions.in("identifiantExterieur", criteres.getEids())); } // Critre sur la visibilit if (criteres.getVisible() != null) { criteria.add(Restrictions.eq("visible", criteres.getVisible())); } // Maxresults if (criteres.getMaxResults() != null) { criteria.setFirstResult(0); criteria.setMaxResults(criteres.getMaxResults()); } criteria.addOrder(Order.asc("ordre")); criteria.addOrder(Order.asc("libelle")); return criteria.list(); }
From source file:com.square.core.dao.implementations.SegmentDaoImplementation.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/*w w w . ja v a 2s . c o m*/ public List<PersonneSegment> rechercherSegmentsParCriteres(DimensionCriteresRechercheDto criteres) { final Criteria criteria = createCriteria(PersonneSegment.class); // Critre sur l'identifiant if (criteres.getId() != null) { criteria.add(Restrictions.eq("id", criteres.getId())); } // Critre sur le libelle if (criteres.getLibelle() != null && !criteres.getLibelle().equals("")) { criteria.add(Restrictions.ilike("libelle", criteres.getLibelle().toLowerCase() + "%")); } // Critre sur la visibilit if (criteres.getVisible() != null) { criteria.add(Restrictions.eq("visible", criteres.getVisible())); } // Maxresults if (criteres.getMaxResults() != null) { criteria.setFirstResult(0); criteria.setMaxResults(criteres.getMaxResults()); } // Ordonner les lments criteria.addOrder(Order.asc("ordre")); criteria.addOrder(Order.asc("libelle")); return criteria.list(); }
From source file:com.square.core.dao.implementations.SituationFamilialeDaoImplementation.java
License:Open Source License
@SuppressWarnings("unchecked") @Override//from w w w . ja v a2 s. c o m public List<PersonneSituationFamiliale> rechercherSituationFamilialeParCriteres( DimensionCriteresRechercheDto criteres) { final Criteria criteria = createCriteria(PersonneSituationFamiliale.class); // Critre sur l'identifiant if (criteres.getId() != null) { criteria.add(Restrictions.eq("id", criteres.getId())); } // Critre sur le libelle if (criteres.getLibelle() != null && !criteres.getLibelle().equals("")) { criteria.add(Restrictions.ilike("libelle", criteres.getLibelle().toLowerCase() + "%")); } // Critre sur la visibilit if (criteres.getVisible() != null) { criteria.add(Restrictions.eq("visible", criteres.getVisible())); } // Maxresults if (criteres.getMaxResults() != null) { criteria.setFirstResult(0); criteria.setMaxResults(criteres.getMaxResults()); } // Ordonner les lments criteria.addOrder(Order.asc("ordre")); criteria.addOrder(Order.asc("libelle")); return criteria.list(); }
From source file:com.square.core.dao.implementations.TypeVoieDaoImplementation.java
License:Open Source License
@SuppressWarnings("unchecked") @Override//from ww w. jav a 2s. c o m public List<TypeVoie> rechercherTypeVoieParCriteres(DimensionCriteresRechercheDto criteres) { final Criteria criteria = createCriteria(TypeVoie.class); // Critre sur l'identifiant if (criteres.getId() != null) { criteria.add(Restrictions.eq("id", criteres.getId())); } // Critre sur le libelle if (criteres.getLibelle() != null && !criteres.getLibelle().equals("")) { criteria.add(Restrictions.ilike("libelle", criteres.getLibelle().toLowerCase() + "%")); } // Critre sur la visibilit if (criteres.getVisible() != null) { criteria.add(Restrictions.eq("visible", criteres.getVisible())); } // Maxresults if (criteres.getMaxResults() != null) { criteria.setFirstResult(0); criteria.setMaxResults(criteres.getMaxResults()); } // Ordonner les lments criteria.addOrder(Order.asc("ordre")); criteria.addOrder(Order.asc("libelle")); return criteria.list(); }
From source file:com.sunesoft.ancon.core.saleContract.application.SaleContractServiceImpl.java
public PagedResult<SaleContractDto> findPagesBySaleContract_echarts(SaleContractCriteria contractCriteria) { Criteria criteria = dbSupport.getSession().createCriteria(SaleContract.class); criteria.add(Restrictions.eq("isActive", true)); if (contractCriteria.getBeginTime() != null) criteria.add(Restrictions.ge("contractBeginTime", contractCriteria.getBeginTime())); if (contractCriteria.getEndTime() != null) criteria.add(Restrictions.le("contractBeginTime", contractCriteria.getEndTime())); if (!StringUtils.isNullOrWhiteSpace(contractCriteria.getBranchCompany())) criteria.add(Restrictions.eq("branchCompany", contractCriteria.getBranchCompany())); if (!StringUtils.isNullOrWhiteSpace(contractCriteria.getJiaFangName())) criteria.add(Restrictions.eq("jiaFangName", contractCriteria.getJiaFangName())); if (!StringUtils.isNullOrWhiteSpace(contractCriteria.getContractType())) criteria.add(Restrictions.eq("contractType", contractCriteria.getContractType())); if (!StringUtils.isNullOrWhiteSpace(contractCriteria.getProjectMajor())) criteria.add(Restrictions.eq("projectMajor", contractCriteria.getProjectMajor())); if (!StringUtils.isNullOrWhiteSpace(contractCriteria.getContractStatus())) criteria.add(Restrictions.eq("contractStatus", contractCriteria.getContractStatus())); //?//w w w . j a va 2s.c o m int totalCount = ((Long) criteria.setProjection(Projections.rowCount()).uniqueResult()).intValue(); criteria.setProjection(null); criteria.addOrder(Order.asc("contractBeginTime")); criteria.setFirstResult((contractCriteria.getPageNumber() - 1) * contractCriteria.getPageSize()) .setMaxResults(contractCriteria.getPageSize()); List<SaleContract> saleContracts = criteria.list(); List<SaleContractDto> list = new ArrayList<>(); for (SaleContract sale : saleContracts) { SaleContractDto dto = DtoFactory.convert(sale, new SaleContractDto()); list.add(dto); } return new PagedResult<SaleContractDto>(list, contractCriteria.getPageNumber(), contractCriteria.getPageSize(), totalCount); }
From source file:com.telefonica.euro_iaas.commons.dao.AbstractBaseDao.java
License:Apache License
/** * set pagination.// www . ja v a 2 s.c om * * @param searchCriteria * the search criteria (page number, page size, order, etc.) * @param baseCriteria * criteria * @param inverseOrder * defines if the result shall show in inverse order (if default is ASC then will use DESC and * viceversa). * @return the criteria that paginates the result. */ protected Criteria setPagination(AbstractSearchCriteria searchCriteria, Criteria baseCriteria, Boolean inverseOrder) { checkPaginationParameters(searchCriteria.getPage(), searchCriteria.getPageSize()); Order order; if (!inverseOrder) { order = getOrder(searchCriteria.getOrderBy(), searchCriteria.getOrderType()); } else { order = getInverseOrder(searchCriteria.getOrderBy(), searchCriteria.getOrderType()); } baseCriteria.setFirstResult(searchCriteria.getPageSize() * searchCriteria.getPage()); baseCriteria.setMaxResults(searchCriteria.getPageSize()); baseCriteria.addOrder(order); return baseCriteria; }
From source file:com.telefonica.euro_iaas.commons.dao.AbstractBaseDao.java
License:Apache License
/** * set pagination if page number and page size are not null. * //w w w . j a v a 2s . c o m * @param searchCriteria * the search criteria (page number, page size, order, etc.) * @param baseCriteria * criteria * @param inverseOrder * defines if the result shall show in inverse order (if default is ASC then will use DESC and * viceversa). * @return the criteria that optionally paginates the result. */ protected Criteria setOptionalPagination(AbstractSearchCriteria searchCriteria, Criteria baseCriteria, Boolean inverseOrder) { checkNullablePaginationParameters(searchCriteria.getPage(), searchCriteria.getPageSize()); Order order; if (!inverseOrder) { order = getOrder(searchCriteria.getOrderBy(), searchCriteria.getOrderType()); } else { order = getInverseOrder(searchCriteria.getOrderBy(), searchCriteria.getOrderType()); } baseCriteria.addOrder(order); if (searchCriteria.getPage() != null && searchCriteria.getPageSize() != null) { baseCriteria.setFirstResult(searchCriteria.getPageSize() * searchCriteria.getPage()); baseCriteria.setMaxResults(searchCriteria.getPageSize()); } return baseCriteria; }
From source file:com.terp.data.CommonDaoImpl.java
License:Open Source License
/** * find records according to given page num and rows per page count * @param pageNum// w w w .j ava 2 s .c o m * @param rowsPerPage * @return */ @Override public List<T> findPage(int pageNum, int rowsPerPage) { // get current session Session session = HibernateUtil.getSessionFactory().openSession(); // check session if (session == null) { return null; } // begin transaction session.getTransaction().begin(); // find by page num Criteria query = session.createCriteria(this.instance); query.setFirstResult(pageNum - 1); query.setMaxResults(rowsPerPage); List<T> list = query.list(); // commint transaction session.getTransaction().commit(); // return object return list; }
From source file:com.thinkgem.jeesite.common.persistence.BaseDaoImpl.java
License:Open Source License
/** * //from w ww . j a v a 2 s . c om * * @param detachedCriteria * @param page * @return */ @SuppressWarnings("unchecked") public Page<T> find(Page<T> page, DetachedCriteria detachedCriteria) { // get count if (!page.isDisabled() && !page.isNotCount()) { page.setCount(count(detachedCriteria)); if (page.getCount() < 1) { return page; } } Criteria criteria = detachedCriteria.getExecutableCriteria(getSession()); criteria.setResultTransformer(Criteria.ROOT_ENTITY); // set page if (!page.isDisabled()) { criteria.setFirstResult(page.getFirstResult()); criteria.setMaxResults(page.getMaxResults()); } // order by if (StringUtils.isNotBlank(page.getOrderBy())) { for (String order : StringUtils.split(page.getOrderBy(), ",")) { String[] o = StringUtils.split(order, " "); if (o.length >= 1) { criteria.addOrder(Order.asc(o[0])); } else if (o.length >= 2) { if ("DESC".equals(o[1].toUpperCase())) { criteria.addOrder(Order.desc(o[0])); } else { criteria.addOrder(Order.asc(o[0])); } } } } page.setList(criteria.list()); return page; }
From source file:com.thinkmore.framework.orm.hibernate.HibernateDao.java
License:Apache License
/** * ?Criteria,.//from ww w . j a va 2 s. com */ protected Criteria setPageParameter(final Criteria c, final Page<T> page) { // hibernatefirstResult??0 c.setFirstResult(page.getFirst() - 1); c.setMaxResults(page.getPageSize()); if (page.isOrderBySetted()) { String[] orderByArray = StringUtils.split(page.getOrderBy(), ','); String[] orderArray = StringUtils.split(page.getOrder(), ','); Assert.isTrue(orderByArray.length == orderArray.length, "???,????"); for (int i = 0; i < orderByArray.length; i++) { if (Page.ASC.equals(orderArray[i])) { c.addOrder(Order.asc(orderByArray[i])); } else { c.addOrder(Order.desc(orderByArray[i])); } } } return c; }