Example usage for org.springframework.data.domain PageImpl PageImpl

List of usage examples for org.springframework.data.domain PageImpl PageImpl

Introduction

In this page you can find the example usage for org.springframework.data.domain PageImpl PageImpl.

Prototype

public PageImpl(List<T> content, Pageable pageable, long total) 

Source Link

Document

Constructor of PageImpl .

Usage

From source file:siddur.solidtrust.autoscoutde.AutoscoutDeService.java

public Page<ScoutCar> top100Detail(Pageable pageable, Fast100 f, String type, int index, String name) {
    String baseJpql = "from AutoscoutDe m where m.dateRemoved != '0000-00-00'" + " and m.brand = '"
            + f.getBrand() + "' and m.model = '" + f.getModel() + "' and m.build = '" + f.getBuild()
            + "' and m.enginesize = " + f.getEngineSize() + " and m.fuel = '" + f.getFuelType()
            + "' and m.arrangement = '" + f.getArrangement() + "'";

    if (type.equals("color")) {
        baseJpql += " and m.color='" + name + "'";
    } else {/*  w  ww. j a  v a2  s  . c o m*/
        Integer[] range = type.equals("price") ? Sorter.PRICE_RANGE : Sorter.MILEAGE_RANGE;
        if (index == 0) {
            baseJpql += " and m." + type + " < " + range[index];
        } else if (index == range.length) {
            baseJpql += " and m." + type + " >= " + range[index - 1];
        } else {
            baseJpql += " and m." + type + " < " + range[index];
            baseJpql += " and m." + type + " >= " + range[index - 1];
        }
    }

    String jpql = selectSQL + baseJpql;
    log4j.info(jpql);

    List<Object[]> list = em.createQuery(jpql, Object[].class)
            .setFirstResult(pageable.getPageSize() * pageable.getPageNumber())
            .setMaxResults(pageable.getPageSize()).getResultList();
    List<ScoutCar> results = ScoutCar.toScoutCarList(list, true);

    long count = em.createQuery("select count(m) " + baseJpql, Long.class).getSingleResult();
    Page<ScoutCar> page = new PageImpl<ScoutCar>(results, pageable, (int) count);
    return page;
}

From source file:siddur.solidtrust.insurancehelper.InsuranceService.java

/**
 * demo in admin page/*from w  ww  .  ja  v  a 2s.c o m*/
 * @param daysToAlert days from today
 * @param aheadDays default: 4 * 7days
 * @return
 */
public Page<InsuranceCar> alertDemo(Pageable pageable, int daysToAlert, int aheadDays) {
    Date start = new Date();
    Date end = DateUtils.addDays(start, aheadDays);
    end = DateUtils.addDays(end, daysToAlert);
    String date = DateUtil.date2String(end);
    String baseJpql = "from InsuranceCar i" + " where i.status > 0" //include status = 1 or 2. It is different from alert() function.
            + " and i.expectedSoldDate <= '" + date + "'";

    log4j.info(baseJpql);
    String ql = baseJpql + " order by i.licensePlate";
    long count = em.createQuery("select count(i) " + baseJpql, Long.class).getSingleResult();

    List<InsuranceCar> list = em.createQuery(ql, InsuranceCar.class)
            .setFirstResult(pageable.getPageSize() * pageable.getPageNumber())
            .setMaxResults(pageable.getPageSize()).getResultList();
    Page<InsuranceCar> page = new PageImpl<InsuranceCar>(list, pageable, (int) count);
    return page;
}

From source file:siddur.solidtrust.marktplaats.MarktplaatsService.java

public Page<MarktplaatsCar> timeOnSale(Pageable pageable, String brand, String model, String build,
        String fuelType) {/*from   w  w w  .java 2  s .c o m*/
    String baseJpql = "from SortedMarktplaats s, NewMarktplaats m where s.id = m.id and m.dateRegisted is not null and m.repetition is null";
    if (!StringUtils.isEmpty(brand)) {
        baseJpql += " and s.brand = '" + brand + "'";
    }
    if (!StringUtils.isEmpty(model)) {
        baseJpql += " and s.model = '" + model + "'";
    }
    if (!StringUtils.isEmpty(build)) {
        baseJpql += " and s.build = '" + build + "'";
    }
    if (!StringUtils.isEmpty(fuelType)) {
        baseJpql += " and s.fuelType = '" + fuelType + "'";
    }

    String countSql = "select count(m) " + baseJpql;
    int count = em.createQuery(countSql, Long.class).getSingleResult().intValue();

    String jpql = marktplaatsCarSelectSQL + baseJpql;
    log4j.info(jpql);

    List<Object[]> list = em.createQuery(jpql, Object[].class)
            .setFirstResult(pageable.getPageSize() * pageable.getPageNumber())
            .setMaxResults(pageable.getPageSize()).getResultList();
    List<MarktplaatsCar> results = toMarktplaatsList(list);
    Page<MarktplaatsCar> page = new PageImpl<MarktplaatsCar>(results, pageable, count);
    return page;
}

From source file:siddur.solidtrust.marktplaats.MarktplaatsService.java

@Transactional(readOnly = true)
public Page<MarktplaatsCar> timeOnSaleByLucene(Pageable pageable, String brand, String model, String build)
        throws Exception {
    List<Integer> items = searchIds(brand, model, build, null);

    String jpql = marktplaatsCarSelectSQL
            + " from NewMarktplaats m where m.id in :ids and m.dateRegisted is not null";
    String totalJpql = "select count(m) from NewMarktplaats m where m.id in :ids and m.dateRegisted is not null";
    log4j.info(jpql);/*  w  ww.j av  a  2s. c  o m*/

    List<Object[]> list = em.createQuery(jpql, Object[].class).setParameter("ids", items)
            .setFirstResult(pageable.getPageSize() * pageable.getPageNumber())
            .setMaxResults(pageable.getPageSize()).getResultList();

    long total = em.createQuery(totalJpql, Long.class).setParameter("ids", items).getSingleResult();
    List<MarktplaatsCar> results = toMarktplaatsList(list);
    Page<MarktplaatsCar> page = new PageImpl<MarktplaatsCar>(results, pageable, total);
    return page;
}

From source file:siddur.solidtrust.marktplaats.MarktplaatsService.java

@Transactional(readOnly = true)
public void mileageByLucene(Model _model, Pageable pageable, String brand, String model, String build,
        String fuelType) throws Exception {
    List<Integer> items = searchIds(brand, model, build, fuelType);
    if (items.isEmpty()) {
        return;/*from   ww w .j  ava 2s.  c o  m*/
    }
    String suffix = " from NewMarktplaats m where m.id in :ids and m.mileage > 10";
    String jpql = marktplaatsCarMileageSelectSQL + suffix;
    String totalJpql = "select count(m), avg(m.mileage)" + suffix;

    List<Object[]> list = em.createQuery(jpql, Object[].class).setParameter("ids", items)
            .setFirstResult(pageable.getOffset()).setMaxResults(pageable.getPageSize()).getResultList();

    Object[] count = em.createQuery(totalJpql, Object[].class).setParameter("ids", items).getSingleResult();
    List<MarktplaatsCar> results = toMarktplaatsListForMileage(list);
    Page<MarktplaatsCar> page = new PageImpl<MarktplaatsCar>(results, pageable, (long) count[0]);
    _model.addAttribute("page", page);
    _model.addAttribute("mileage", ((Double) count[1]).intValue());

}

From source file:siddur.solidtrust.marktplaats.MarktplaatsService.java

public Page<MarktplaatsCar> top100Detail(Pageable pageable, Fast100 f, String type, int index, String name) {
    String baseJpql = "from SortedMarktplaats s, NewMarktplaats m where s.id = m.id"
            + " and m.repetition is null" + " and m.dateRegisted is not null"
            + " and m.price != 99999 and m.price != 999999 and m.price != 9999999" + " and s.brand = '"
            + f.getBrand() + "' and s.model = '" + f.getModel() + "' and s.build = '" + f.getBuild()
            + "' and s.engineSize = " + f.getEngineSize() + " and s.fuelType = '" + f.getFuelType()
            + "' and m.arrangement = '" + f.getArrangement() + "'";

    if (type.equals("color")) {
        baseJpql += " and s.color='" + name + "'";
    } else {/*from w ww.j a  v  a  2s  .com*/
        Integer[] range = type.equals("price") ? Sorter.PRICE_RANGE : Sorter.MILEAGE_RANGE;
        if (index == 0) {
            baseJpql += " and s." + type + " < " + range[index];
        } else if (index == range.length) {
            baseJpql += " and s." + type + " >= " + range[index - 1];
        } else {
            baseJpql += " and s." + type + " < " + range[index];
            baseJpql += " and s." + type + " >= " + range[index - 1];
        }
    }

    String jpql = marktplaatsCarSelectSQL + baseJpql;
    log4j.info(jpql);

    List<Object[]> list = em.createQuery(jpql, Object[].class)
            .setFirstResult(pageable.getPageSize() * pageable.getPageNumber())
            .setMaxResults(pageable.getPageSize()).getResultList();
    List<MarktplaatsCar> results = toMarktplaatsList(list);

    long count = em.createQuery("select count(m) " + baseJpql, Long.class).getSingleResult();
    Page<MarktplaatsCar> page = new PageImpl<MarktplaatsCar>(results, pageable, (int) count);
    return page;
}

From source file:siddur.solidtrust.wok.WokController.java

@RequestMapping("list")
@Transactional(readOnly = true)/*w w  w.j  a  v  a 2 s.c  o m*/
public String list(@RequestParam(value = "id", required = false) String id,
        @RequestParam(value = "onlyRemoved", required = false, defaultValue = "false") boolean onlyRemoved,
        @RequestParam(value = "page", required = false, defaultValue = "1") Integer pageIndex,
        @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize,
        Model model) {
    String jpql = "select a.licensePlate, a.brand, a.type, w.addedAt, w.removedAt from Wachtopkeuren w, AzureCar a where w.licensePlate = a.licensePlate";
    if (onlyRemoved) {
        jpql += " and w.removedAt > w.addedAt";
        model.addAttribute("onlyRemoved", onlyRemoved);
    }

    if (!StringUtils.isEmpty(id)) {
        jpql += " and w.licensePlate = '" + id + "'";
        List<Object[]> results = em.createQuery(jpql, Object[].class).getResultList();
        if (!results.isEmpty()) {
            model.addAttribute("car", results.get(0));
        }
        model.addAttribute("key", id);
    } else {
        Pageable pageable = new PageRequest(pageIndex - 1, pageSize);
        List<Object[]> results = em.createQuery(jpql, Object[].class).setFirstResult(pageable.getOffset())
                .setMaxResults(pageable.getPageSize()).getResultList();

        String countQL = "select count(w) from Wachtopkeuren w";
        if (onlyRemoved) {
            countQL += " where w.removedAt > w.addedAt";
        }
        long count = em.createQuery(countQL, Long.class).getSingleResult();
        Page<Object[]> page = new PageImpl<Object[]>(results, pageable, (int) count);
        model.addAttribute("page", page);
    }
    return "wok/list";
}