本文整理了Java中org.springframework.data.domain.Pageable.getSort()
方法的一些代码示例,展示了Pageable.getSort()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Pageable.getSort()
方法的具体详情如下:
包路径:org.springframework.data.domain.Pageable
类名称:Pageable
方法名:getSort
[英]Returns the sorting parameters.
[中]返回排序参数。
代码示例来源:origin: apache/ignite
/**
* Add a dynamic part of a query for the pagination support.
*
* @param sql Builder instance.
* @param pageable Pageable instance.
* @return Builder instance.
*/
public static StringBuilder addPaging(StringBuilder sql, Pageable pageable) {
if (pageable.getSort() != null)
addSorting(sql, pageable.getSort());
sql.append(" LIMIT ").append(pageable.getPageSize()).append(" OFFSET ").append(pageable.getOffset());
return sql;
}
代码示例来源:origin: apache/ignite
/**
* Add a dynamic part of a query for the pagination support.
*
* @param sql Builder instance.
* @param pageable Pageable instance.
* @return Builder instance.
*/
public static StringBuilder addPaging(StringBuilder sql, Pageable pageable) {
if (pageable.getSort() != null)
addSorting(sql, pageable.getSort());
sql.append(" LIMIT ").append(pageable.getPageSize()).append(" OFFSET ").append(pageable.getOffset());
return sql;
}
代码示例来源:origin: spring-projects/spring-data-jpa
/**
* Creates a new {@link TypedQuery} from the given {@link Specification}.
*
* @param spec can be {@literal null}.
* @param domainClass must not be {@literal null}.
* @param pageable must not be {@literal null}.
* @return
*/
protected <S extends T> TypedQuery<S> getQuery(@Nullable Specification<S> spec, Class<S> domainClass,
Pageable pageable) {
Sort sort = pageable.isPaged() ? pageable.getSort() : Sort.unsorted();
return getQuery(spec, domainClass, sort);
}
代码示例来源:origin: spring-projects/spring-data-jpa
/**
* Creates a new {@link TypedQuery} from the given {@link Specification}.
*
* @param spec can be {@literal null}.
* @param pageable must not be {@literal null}.
* @return
*/
protected TypedQuery<T> getQuery(@Nullable Specification<T> spec, Pageable pageable) {
Sort sort = pageable.isPaged() ? pageable.getSort() : Sort.unsorted();
return getQuery(spec, getDomainClass(), sort);
}
代码示例来源:origin: spring-projects/spring-data-mongodb
/**
* Sets the given pagination information on the {@link Query} instance. Will transparently set {@code skip} and
* {@code limit} as well as applying the {@link Sort} instance defined with the {@link Pageable}.
*
* @param pageable
* @return
*/
public Query with(Pageable pageable) {
if (pageable.isUnpaged()) {
return this;
}
this.limit = pageable.getPageSize();
this.skip = pageable.getOffset();
return with(pageable.getSort());
}
代码示例来源:origin: spring-projects/spring-data-mongodb
/**
* Applies the given {@link Pageable} to the given {@link SpringDataMongodbQuery}.
*
* @param query
* @param pageable
* @return
*/
private SpringDataMongodbQuery<T> applyPagination(SpringDataMongodbQuery<T> query, Pageable pageable) {
query = query.offset(pageable.getOffset()).limit(pageable.getPageSize());
return applySorting(query, pageable.getSort());
}
代码示例来源:origin: spring-projects/spring-data-jpa
/**
* Applies the given {@link Pageable} to the given {@link JPQLQuery}.
*
* @param pageable
* @param query must not be {@literal null}.
* @return the Querydsl {@link JPQLQuery}.
*/
public <T> JPQLQuery<T> applyPagination(Pageable pageable, JPQLQuery<T> query) {
if (pageable.isUnpaged()) {
return query;
}
query.offset(pageable.getOffset());
query.limit(pageable.getPageSize());
return applySorting(pageable.getSort(), query);
}
代码示例来源:origin: spring-projects/spring-data-redis
@Override
public <S extends T> Page<S> findAll(Example<S> example, Pageable pageable) {
Assert.notNull(pageable, "Pageable must not be null!");
RedisOperationChain operationChain = createQuery(example);
KeyValueQuery<RedisOperationChain> query = new KeyValueQuery<>(operationChain);
Iterable<T> result = keyValueTemplate.find(
query.orderBy(pageable.getSort()).skip(pageable.getOffset()).limit(pageable.getPageSize()),
entityInformation.getJavaType());
long count = operationChain.isEmpty() ? keyValueTemplate.count(entityInformation.getJavaType())
: keyValueTemplate.count(query, entityInformation.getJavaType());
List<S> list = new ArrayList<>();
for (T t : result) {
list.add((S) t);
}
return new PageImpl<>(list, pageable, count);
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testDoReadFirstReadNoResults() throws Exception {
ArgumentCaptor<PageRequest> pageRequestContainer = ArgumentCaptor.forClass(PageRequest.class);
when(repository.findAll(pageRequestContainer.capture())).thenReturn(new PageImpl<>(new ArrayList<>()));
assertNull(reader.doRead());
Pageable pageRequest = pageRequestContainer.getValue();
assertEquals(0, pageRequest.getOffset());
assertEquals(0, pageRequest.getPageNumber());
assertEquals(1, pageRequest.getPageSize());
assertEquals("id: ASC", pageRequest.getSort().toString());
}
代码示例来源:origin: spring-projects/spring-batch
@Test
@SuppressWarnings("serial")
public void testDoReadFirstReadExhausted() throws Exception {
ArgumentCaptor<PageRequest> pageRequestContainer = ArgumentCaptor.forClass(PageRequest.class);
final Object result = new Object();
when(repository.findAll(pageRequestContainer.capture())).thenReturn(new PageImpl<>(new ArrayList<Object>() {{
add(new Object());
}})).thenReturn(new PageImpl<>(new ArrayList<Object>(){{
add(result);
}})).thenReturn(new PageImpl<>(new ArrayList<>()));
assertFalse(reader.doRead() == result);
assertEquals(result, reader.doRead());
assertNull(reader.doRead());
Pageable pageRequest = pageRequestContainer.getValue();
assertEquals(2, pageRequest.getOffset());
assertEquals(2, pageRequest.getPageNumber());
assertEquals(1, pageRequest.getPageSize());
assertEquals("id: ASC", pageRequest.getSort().toString());
}
代码示例来源:origin: spring-projects/spring-batch
@Test
@SuppressWarnings("serial")
public void testDoReadFirstReadSecondPage() throws Exception {
ArgumentCaptor<PageRequest> pageRequestContainer = ArgumentCaptor.forClass(PageRequest.class);
final Object result = new Object();
when(repository.findAll(pageRequestContainer.capture())).thenReturn(new PageImpl<>(new ArrayList<Object>() {{
add(new Object());
}})).thenReturn(new PageImpl<>(new ArrayList<Object>(){{
add(result);
}}));
assertFalse(reader.doRead() == result);
assertEquals(result, reader.doRead());
Pageable pageRequest = pageRequestContainer.getValue();
assertEquals(1, pageRequest.getOffset());
assertEquals(1, pageRequest.getPageNumber());
assertEquals(1, pageRequest.getPageSize());
assertEquals("id: ASC", pageRequest.getSort().toString());
}
代码示例来源:origin: spring-projects/spring-batch
@Test
@SuppressWarnings("serial")
public void testDoReadFirstReadResults() throws Exception {
ArgumentCaptor<PageRequest> pageRequestContainer = ArgumentCaptor.forClass(PageRequest.class);
final Object result = new Object();
when(repository.findAll(pageRequestContainer.capture())).thenReturn(new PageImpl<>(new ArrayList<Object>(){{
add(result);
}}));
assertEquals(result, reader.doRead());
Pageable pageRequest = pageRequestContainer.getValue();
assertEquals(0, pageRequest.getOffset());
assertEquals(0, pageRequest.getPageNumber());
assertEquals(1, pageRequest.getPageSize());
assertEquals("id: ASC", pageRequest.getSort().toString());
}
代码示例来源:origin: spring-projects/spring-batch
@Test
@SuppressWarnings("serial")
public void testJumpToItem() throws Exception {
reader.setPageSize(100);
ArgumentCaptor<PageRequest> pageRequestContainer = ArgumentCaptor.forClass(PageRequest.class);
when(repository.findAll(pageRequestContainer.capture())).thenReturn(new PageImpl<>(new ArrayList<Object>() {{
add(new Object());
}}));
reader.jumpToItem(485);
Pageable pageRequest = pageRequestContainer.getValue();
assertEquals(400, pageRequest.getOffset());
assertEquals(4, pageRequest.getPageNumber());
assertEquals(100, pageRequest.getPageSize());
assertEquals("id: ASC", pageRequest.getSort().toString());
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testDifferentTypes() throws Exception {
TestRepository differentRepository = mock(TestRepository.class);
RepositoryItemReader<String> reader = new RepositoryItemReader<>();
sorts = new HashMap<>();
sorts.put("id", Direction.ASC);
reader.setRepository(differentRepository);
reader.setPageSize(1);
reader.setSort(sorts);
reader.setMethodName("findFirstNames");
ArgumentCaptor<PageRequest> pageRequestContainer = ArgumentCaptor.forClass(PageRequest.class);
when(differentRepository.findFirstNames(pageRequestContainer.capture())).thenReturn(new PageImpl<>(new ArrayList<String>(){{
add("result");
}}));
assertEquals("result", reader.doRead());
Pageable pageRequest = pageRequestContainer.getValue();
assertEquals(0, pageRequest.getOffset());
assertEquals(0, pageRequest.getPageNumber());
assertEquals(1, pageRequest.getPageSize());
assertEquals("id: ASC", pageRequest.getSort().toString());
}
代码示例来源:origin: spring-projects/spring-data-neo4j
public SortOrder getSort(Pageable pageable) {
return PagingAndSortingUtils.convert(pageable.getSort());
}
代码示例来源:origin: spring-projects/spring-data-rest
@Override
public Pageable resolveArgument(MethodParameter methodParameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) {
Pageable pageable = delegate.resolveArgument(methodParameter, mavContainer, webRequest, binderFactory);
if (pageable == null || pageable.getSort() == null) {
return pageable;
}
Sort translated = translator.translateSort(pageable.getSort(), methodParameter, webRequest);
return PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), translated);
}
}
代码示例来源:origin: spring-projects/spring-data-neo4j
public String getCypherQuery(Pageable pageable, boolean forSlicing) {
String result = cypherQuery;
Sort sort = null;
if (pageable.isPaged() && pageable.getSort() != Sort.unsorted()) {
sort = pageable.getSort();
}
if (sort != Sort.unsorted()) {
// Custom queries in the OGM do not support pageable
result = addSorting(result, sort);
}
result = addPaging(result, pageable, forSlicing);
return result;
}
代码示例来源:origin: spring-projects/spring-data-rest
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
Pageable pageable = delegate.resolveArgument(parameter, mavContainer, webRequest, binderFactory);
if (pageable == null || pageable.getSort() == null) {
return new DefaultedPageable(pageable, delegate.isFallbackPageable(pageable));
}
Sort translated = translator.translateSort(pageable.getSort(), parameter, webRequest);
pageable = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), translated);
return new DefaultedPageable(pageable, delegate.isFallbackPageable(pageable));
}
}
代码示例来源:origin: spring-projects/spring-data-neo4j
@Override
public Page<T> findAll(Pageable pageable, int depth) {
Pagination pagination = new Pagination(pageable.getPageNumber(), pageable.getPageSize());
Collection<T> data = session.loadAll(clazz, PagingAndSortingUtils.convert(pageable.getSort()), pagination, depth);
return PageableExecutionUtils.getPage(new ArrayList<>(data), pageable, () -> session.countEntitiesOfType(clazz));
}
}
代码示例来源:origin: org.springframework.data/spring-data-mongodb
/**
* Applies the given {@link Pageable} to the given {@link SpringDataMongodbQuery}.
*
* @param query
* @param pageable
* @return
*/
private SpringDataMongodbQuery<T> applyPagination(SpringDataMongodbQuery<T> query, Pageable pageable) {
query = query.offset(pageable.getOffset()).limit(pageable.getPageSize());
return applySorting(query, pageable.getSort());
}
内容来源于网络,如有侵权,请联系作者删除!