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

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

Introduction

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

Prototype

private Sort(Direction direction, List<String> properties) 

Source Link

Document

Creates a new Sort instance.

Usage

From source file:com.luna.common.plugin.serivce.BaseMovableService.java

public void reweight() {
    int batchSize = 100;
    Sort sort = new Sort(Sort.Direction.DESC, "weight");
    Pageable pageable = new PageRequest(0, batchSize, sort);
    Page<M> page = findAll(pageable);
    do {//from  www  .  j a v  a2  s . co m
        //doReweight?requiresNew
        ((BaseMovableService) AopContext.currentProxy()).doReweight(page);

        RepositoryHelper.clear();

        if (page.isLastPage()) {
            break;
        }

        pageable = new PageRequest((pageable.getPageNumber() + 1) * batchSize, batchSize, sort);

        page = findAll(pageable);

    } while (true);
}

From source file:cn.guoyukun.spring.jpa.plugin.serivce.BaseMovableService.java

public void reweight() {
    int batchSize = 100;
    Sort sort = new Sort(Sort.Direction.DESC, "weight");
    Pageable pageable = new PageRequest(0, batchSize, sort);
    Page<M> page = findAll(pageable);
    do {/*from   w w w .  j  a v a2  s. c  o m*/
        //doReweight?requiresNew
        ((BaseMovableService) AopContext.currentProxy()).doReweight(page);

        RepositoryHelper.clear();

        if (page.isLast()) {
            break;
        }

        pageable = new PageRequest((pageable.getPageNumber() + 1) * batchSize, batchSize, sort);

        page = findAll(pageable);

    } while (true);
}

From source file:org.centralperf.controller.RunController.java

/**
 * Display all runs//from w  w w . j a  va  2  s .co  m
 * @param model   Model prepared for "all runs" view
 * @return The "all runs" view name
 */
@RequestMapping("/run")
public String showRuns(Model model) {
    log.debug("Displaying runs");
    Sort runSort = new Sort(Sort.Direction.DESC, "startDate");
    model.addAttribute("runs", runRepository.findAll(runSort));
    Sort scriptSort = new Sort(Sort.DEFAULT_DIRECTION, "label");
    model.addAttribute("scripts", scriptRepository.findAll(scriptSort));
    model.addAttribute("newRun", new Run());
    return "runs";
}

From source file:com.luna.common.service.UserServiceTest.java

@Test
public void testFindAllBySearchAndPageableAndSortAsc() {
    int count = 15;
    User lastUser = null;//from w  ww  .j a  va 2  s  . c o  m
    for (int i = 0; i < count; i++) {
        lastUser = userService.save(createUser());
    }

    Sort sortAsc = new Sort(Sort.Direction.ASC, "id");
    Pageable pageable = new PageRequest(0, 5, sortAsc);
    Map<String, Object> searchParams = new HashMap<String, Object>();
    searchParams.put("username_like", "zhang");
    Searchable search = Searchable.newSearchable(searchParams).setPage(pageable);

    Page<User> userPage = userService.findAll(search);
    assertEquals(5, userPage.getNumberOfElements());
    assertFalse(userPage.getContent().contains(lastUser));
    assertTrue(userPage.getContent().get(0).getId() < userPage.getContent().get(1).getId());
}

From source file:edu.zipcloud.cloudstreetmarket.core.services.StockProductServiceImpl.java

@Override
public ChartStock getChartStock(StockProduct index, ChartType type, ChartHistoSize histoSize,
        ChartHistoMovingAverage histoAverage, ChartHistoTimeSpan histoPeriod, Integer intradayWidth,
        Integer intradayHeight) {

    Specification<ChartStock> spec = new ChartSpecifications<ChartStock>().typeEquals(type);

    if (type.equals(ChartType.HISTO)) {
        if (histoSize != null) {
            spec = Specifications.where(spec).and(new ChartSpecifications<ChartStock>().sizeEquals(histoSize));
        }/* ww  w.  ja v  a  2  s .c  o m*/
        if (histoAverage != null) {
            spec = Specifications.where(spec)
                    .and(new ChartSpecifications<ChartStock>().histoMovingAverageEquals(histoAverage));
        }
        if (histoPeriod != null) {
            spec = Specifications.where(spec)
                    .and(new ChartSpecifications<ChartStock>().histoTimeSpanEquals(histoPeriod));
        }
    } else {
        if (intradayWidth != null) {
            spec = Specifications.where(spec)
                    .and(new ChartSpecifications<ChartStock>().intradayWidthEquals(intradayWidth));
        }
        if (intradayHeight != null) {
            spec = Specifications.where(spec)
                    .and(new ChartSpecifications<ChartStock>().intradayHeightEquals(intradayHeight));
        }
    }

    spec = Specifications.where(spec).and(new ChartSpecifications<ChartStock>().indexEquals(index));
    return chartStockRepository.findAll(spec, new Sort(Direction.DESC, "id")).stream().findFirst().orElse(null);
}

From source file:com.luna.common.web.bind.method.annotation.PageableMethodArgumentResolverTest.java

@Test
public void testParameterDefaultPageableAndOverrideSort() throws Exception {

    request.setParameter("sort2.id", "desc");
    request.setParameter("sort1.baseInfo.realname", "asc");

    MethodParameter parameter = new MethodParameter(parameterDefaultPageable, 0);
    NativeWebRequest webRequest = new ServletWebRequest(request);
    Pageable pageable = (Pageable) new PageableMethodArgumentResolver().resolveArgument(parameter, null,
            webRequest, null);//from   w ww  .j a v  a2  s  .com

    assertEquals(Controller.DEFAULT_PAGENUMBER, pageable.getPageNumber());
    assertEquals(Controller.DEFAULT_PAGESIZE, pageable.getPageSize());
    Sort expectedSort = new Sort(Sort.Direction.ASC, "baseInfo.realname")
            .and(new Sort(Sort.Direction.DESC, "id"));
    assertEquals(expectedSort, pageable.getSort());
}

From source file:com.simphony.managedbeans.CostBean.java

private Sort sortByOrigin() {
    return new Sort(Sort.Direction.ASC, "origin.description");
}

From source file:com.simphony.managedbeans.SalePointBean.java

private Sort sortByDescription() {
    return new Sort(Sort.Direction.ASC, "description");
}

From source file:com.simphony.managedbeans.AssociateBean.java

private Sort sortByKeyId() {
    return new Sort(Sort.Direction.ASC, "keyId");
}

From source file:cn.guoyukun.spring.jpa.entity.search.SearchRequest.java

@Override
public Searchable addSort(final Sort.Direction direction, final String property) {
    merge(new Sort(direction, property), page);
    return this;
}