Search in sources :

Example 6 with GenericEntityList

use of com.salesmanager.core.model.common.GenericEntityList in project shopizer by shopizer-ecommerce.

the class RepositoryHelper method paginateQuery.

@SuppressWarnings("rawtypes")
public static Query paginateQuery(Query q, Number count, GenericEntityList entityList, Criteria criteria) {
    if (entityList == null) {
        entityList = new GenericEntityList();
    }
    if (criteria.isLegacyPagination()) {
        if (criteria.getMaxCount() > 0) {
            q.setFirstResult(criteria.getStartIndex());
            q.setMaxResults(Math.min(criteria.getMaxCount(), count.intValue()));
        }
    } else {
        // int firstResult = ((criteria.getStartPage()==0?criteria.getStartPage()+1:criteria.getStartPage()) - 1) * criteria.getPageSize();
        int firstResult = ((criteria.getStartPage() == 0 ? 0 : criteria.getStartPage())) * criteria.getPageSize();
        q.setFirstResult(firstResult);
        q.setMaxResults(criteria.getPageSize());
        int lastPageNumber = (count.intValue() / criteria.getPageSize()) + 1;
        entityList.setTotalPages(lastPageNumber);
        entityList.setTotalCount(count.intValue());
    }
    return q;
}
Also used : GenericEntityList(com.salesmanager.core.model.common.GenericEntityList)

Aggregations

GenericEntityList (com.salesmanager.core.model.common.GenericEntityList)6 Query (javax.persistence.Query)4 ServiceException (com.salesmanager.core.business.exception.ServiceException)3 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)2 ConversionException (com.salesmanager.core.business.exception.ConversionException)1 ContentService (com.salesmanager.core.business.services.content.ContentService)1 MerchantStoreService (com.salesmanager.core.business.services.merchant.MerchantStoreService)1 CountryService (com.salesmanager.core.business.services.reference.country.CountryService)1 LanguageService (com.salesmanager.core.business.services.reference.language.LanguageService)1 ZoneService (com.salesmanager.core.business.services.reference.zone.ZoneService)1 MerchantConfigurationService (com.salesmanager.core.business.services.system.MerchantConfigurationService)1 MeasureUnit (com.salesmanager.core.constants.MeasureUnit)1 Product (com.salesmanager.core.model.catalog.product.Product)1 ProductList (com.salesmanager.core.model.catalog.product.ProductList)1 AttributeCriteria (com.salesmanager.core.model.catalog.product.attribute.AttributeCriteria)1 InputContentFile (com.salesmanager.core.model.content.InputContentFile)1 MerchantStoreCriteria (com.salesmanager.core.model.merchant.MerchantStoreCriteria)1 OrderList (com.salesmanager.core.model.order.OrderList)1 Language (com.salesmanager.core.model.reference.language.Language)1 MerchantConfiguration (com.salesmanager.core.model.system.MerchantConfiguration)1