List of usage examples for org.hibernate Criteria setMaxResults
public Criteria setMaxResults(int maxResults);
From source file:com.abiquo.server.core.cloud.VirtualApplianceDAO.java
License:Open Source License
/** * @param user, only users with restricted VDCs. If no restricted then use user = null *//*w w w. j a v a 2s . c o m*/ public List<VirtualAppliance> findByEnterprise(final Enterprise enterprise, final FilterOptions filterOptions, final User user) { if (filterOptions == null) { return findByEnterprise(enterprise); } // Check if the orderBy element is actually one of the available ones VirtualAppliance.OrderByEnum orderByEnum = VirtualAppliance.OrderByEnum .valueOf(filterOptions.getOrderBy().toUpperCase()); Integer limit = filterOptions.getLimit(); Integer startwith = filterOptions.getStartwith(); String filter = filterOptions.getFilter(); boolean asc = filterOptions.getAsc(); Criteria criteria = createCriteria(enterprise, filter, orderByEnum, asc); // Check if the page requested is bigger than the last one Long total = count(criteria); criteria = createCriteria(enterprise, filter, orderByEnum, asc); Integer totalResults = total.intValue(); limit = limit != 0 ? limit : totalResults; if (limit != null) { criteria.setMaxResults(limit); } if (startwith >= totalResults) { startwith = totalResults - limit; } criteria.setFirstResult(startwith); criteria.setMaxResults(limit); if (user != null) { criteria.createAlias(VirtualAppliance.VIRTUAL_DATACENTER_PROPERTY, "virtualdatacenter"); criteria.add( Restrictions.in("virtualdatacenter." + PersistentEntity.ID_PROPERTY, availableVdsToUser(user))); } List<VirtualAppliance> result = getResultList(criteria); PagedList<VirtualAppliance> page = new PagedList<VirtualAppliance>(); page.addAll(result); page.setCurrentElement(startwith); page.setPageSize(limit); page.setTotalResults(totalResults); return page; }
From source file:com.abiquo.server.core.cloud.VirtualApplianceDAO.java
License:Open Source License
public List<VirtualAppliance> findByVirtualDatacenter(final VirtualDatacenter virtualDatacenter, final FilterOptions filterOptions) { if (filterOptions == null) { return findByVirtualDatacenter(virtualDatacenter); }//w w w . jav a2 s . c o m // Check if the orderBy element is actually one of the available ones VirtualAppliance.OrderByEnum orderByEnum = VirtualAppliance.OrderByEnum .valueOf(filterOptions.getOrderBy().toUpperCase()); Integer limit = filterOptions.getLimit(); Integer startwith = filterOptions.getStartwith(); String filter = filterOptions.getFilter(); boolean asc = filterOptions.getAsc(); Criteria criteria = createCriteria(virtualDatacenter, filter, orderByEnum, asc); // Check if the page requested is bigger than the last one Long total = count(criteria); criteria = createCriteria(virtualDatacenter, filter, orderByEnum, asc); Integer totalResults = total.intValue(); limit = limit != 0 ? limit : totalResults; if (limit != null) { criteria.setMaxResults(limit); } if (startwith >= totalResults) { startwith = totalResults - limit; } criteria.setFirstResult(startwith); criteria.setMaxResults(limit); List<VirtualAppliance> result = getResultList(criteria); PagedList<VirtualAppliance> page = new PagedList<VirtualAppliance>(); page.addAll(result); page.setCurrentElement(startwith); page.setPageSize(limit); page.setTotalResults(totalResults); return page; }
From source file:com.abiquo.server.core.cloud.VirtualDatacenterDAO.java
License:Open Source License
private Collection<VirtualDatacenter> findVirtualDatacentersByCriterions(final Collection<Criterion> criterions, final FilterOptions filterOptions) { Criteria criteria = getSession().createCriteria(VirtualDatacenter.class); for (Criterion criterion : criterions) { criteria.add(criterion);// ww w . j a v a2s. c om } criteria.addOrder(Order.asc(VirtualDatacenter.NAME_PROPERTY)); if (filterOptions != null) { Integer size = criteria.list().size(); criteria.setFirstResult(filterOptions.getStartwith()); criteria.setMaxResults(filterOptions.getLimit()); PagedList<VirtualDatacenter> vdcList = new PagedList<VirtualDatacenter>(criteria.list()); vdcList.setTotalResults(size); vdcList.setPageSize(filterOptions.getLimit() > size ? size : filterOptions.getLimit()); vdcList.setCurrentElement(filterOptions.getStartwith()); return vdcList; } else { return getResultList(criteria); } }
From source file:com.abiquo.server.core.enterprise.EnterpriseDAO.java
License:Open Source License
public List<Enterprise> findAll(Integer firstElem, final Integer numResults) { // Check if the page requested is bigger than the last one Criteria criteria = createCriteria(); Long total = count();/*from ww w.j av a 2 s.com*/ if (firstElem >= total.intValue()) { firstElem = total.intValue() - numResults; } criteria.setFirstResult(firstElem); criteria.setMaxResults(numResults); List<Enterprise> result = getResultList(criteria); com.abiquo.server.core.util.PagedList<Enterprise> page = new PagedList<Enterprise>(result); page.setCurrentElement(firstElem); page.setPageSize(numResults); page.setTotalResults(total.intValue()); return page; }
From source file:com.abiquo.server.core.enterprise.EnterpriseDAO.java
License:Open Source License
public List<Enterprise> findByPricingTemplate(Integer firstElem, final PricingTemplate pt, final boolean included, final String filterName, final Integer numResults, final Integer idEnterprise) { // Check if the page requested is bigger than the last one Criteria criteria = createCriteria(pt, included, filterName, idEnterprise); Long total = count(criteria); if (firstElem >= total.intValue()) { firstElem = total.intValue() - numResults; }//from w w w. j a v a2 s. c om criteria = createCriteria(pt, included, filterName, idEnterprise); criteria.setFirstResult(firstElem); criteria.setMaxResults(numResults); List<Enterprise> result = getResultList(criteria); PagedList<Enterprise> page = new PagedList<Enterprise>(); page.addAll(result); page.setCurrentElement(firstElem); page.setPageSize(numResults); page.setTotalResults(total.intValue()); return page; }
From source file:com.abiquo.server.core.enterprise.RoleDAO.java
License:Open Source License
public Collection<Role> find(final Enterprise enterprise, final String filter, final String orderBy, final boolean desc, final Integer offset, final Integer numResults, final boolean discardNullEnterprises) { Criteria criteria = createCriteria(enterprise, filter, orderBy, desc, discardNullEnterprises); Long total = count(criteria); criteria = createCriteria(enterprise, filter, orderBy, desc, discardNullEnterprises); criteria.setFirstResult(offset);//w w w .j a v a2s .co m criteria.setMaxResults(numResults); List<Role> result = getResultList(criteria); PagedList<Role> page = new PagedList<Role>(); page.addAll(result); page.setCurrentElement(offset); page.setPageSize(numResults); page.setTotalResults(total.intValue()); return page; }
From source file:com.abiquo.server.core.enterprise.RoleDAO.java
License:Open Source License
public Collection<Role> findExactly(final Enterprise enterprise, final String filter, final String orderBy, final boolean desc, final Integer offset, final Integer numResults, final boolean discardNullEnterprises) { Criteria criteria = createCriteriaExactly(enterprise, filter, orderBy, desc, discardNullEnterprises); Long total = count(criteria); criteria = createCriteriaExactly(enterprise, filter, orderBy, desc, discardNullEnterprises); criteria.setFirstResult(offset * numResults); criteria.setMaxResults(numResults); List<Role> result = getResultList(criteria); PagedList<Role> page = new PagedList<Role>(); page.addAll(result);// ww w .ja va 2 s . c om page.setCurrentElement(offset); page.setPageSize(numResults); page.setTotalResults(total.intValue()); return page; }
From source file:com.abiquo.server.core.enterprise.RoleLdapDAO.java
License:Open Source License
public Collection<RoleLdap> find(final String filter, final String orderBy, final boolean desc, final Integer offset, final Integer numResults) { Criteria criteria = createCriteria(filter, orderBy, desc); Long total = count(criteria); criteria = createCriteria(filter, orderBy, desc); criteria.setFirstResult(offset * numResults); criteria.setMaxResults(numResults); List<RoleLdap> result = getResultList(criteria); PagedList<RoleLdap> page = new PagedList<RoleLdap>(); page.addAll(result);/*from ww w . j a va 2 s .c om*/ page.setCurrentElement(offset); page.setPageSize(numResults); page.setTotalResults(total.intValue()); return page; }
From source file:com.abiquo.server.core.enterprise.UserDAO.java
License:Open Source License
public Collection<User> find(final Enterprise enterprise, final Role role, final String filter, final String orderBy, final boolean desc, final boolean connected, final Integer offset, final Integer numResults) { String[] filters = new String[] {}; if (filter != null) { filters = filter.split("\\s+"); }/*w w w . j a va2s.c om*/ Criteria criteria = createCriteria(enterprise, role, filters, orderBy, desc, connected); Long total = count(criteria); criteria = createCriteria(enterprise, role, filters, orderBy, desc, connected); criteria.setFirstResult(offset * numResults); criteria.setMaxResults(numResults); List<User> result = getResultList(criteria); PagedList<User> page = new PagedList<User>(); page.addAll(result); page.setCurrentElement(offset); page.setPageSize(numResults); page.setTotalResults(total.intValue()); return page; }
From source file:com.abiquo.server.core.pricing.CostCodeDAO.java
License:Open Source License
public Collection<CostCode> find(final String filter, final String orderBy, final boolean desc, final int offset, int numResults) { Criteria criteria = createCriteria(filter, orderBy, desc); Long total = count(criteria); criteria = createCriteria(filter, orderBy, desc); numResults = (int) (numResults != 0 ? numResults : total); if (numResults != 0) { criteria.setFirstResult(offset * numResults); criteria.setMaxResults(numResults); }/*from w w w. j a va2 s .c o m*/ List<CostCode> result = getResultList(criteria); PagedList<CostCode> page = new PagedList<CostCode>(); page.addAll(result); if (numResults != 0) { page.setCurrentElement(offset); page.setPageSize(numResults); } page.setTotalResults(total.intValue()); return page; }