本文整理汇总了Java中org.springframework.data.domain.Sort.Order类的典型用法代码示例。如果您正苦于以下问题:Java Order类的具体用法?Java Order怎么用?Java Order使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Order类属于org.springframework.data.domain.Sort包,在下文中一共展示了Order类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPageable
import org.springframework.data.domain.Sort.Order; //导入依赖的package包/类
/**
* Creates a 'LIMIT .. OFFSET .. ORDER BY ..' clause for the given
* {@link DataTablesInput}.
*
* @param input
* the {@link DataTablesInput} mapped from the Ajax request
* @return a {@link Pageable}, must not be {@literal null}.
*/
@Transactional
private Pageable getPageable(DataTablesInput input) {
List<Order> orders = new ArrayList<Order>();
for (OrderParameter order : input.getOrder()) {
log.debug("order column: " + order.getColumn() + "");
ColumnParameter column = input.getColumns().get(order.getColumn());
if (column.getOrderable()) {
String sortColumn = column.getData();
Direction sortDirection = Direction.fromString(order.getDir());
orders.add(new Order(sortDirection, sortColumn));
}
}
Sort sort = orders.isEmpty() ? null : new Sort(orders);
if (input.getLength() == -1) {
input.setStart(0);
input.setLength(Integer.MAX_VALUE);
}
return new PageRequest(input.getStart() / input.getLength(), input.getLength(), sort);
}
示例2: orderByExpression
import org.springframework.data.domain.Sort.Order; //导入依赖的package包/类
protected String orderByExpression(Sort sort) {
final String noSort = "";
if (sort == null || !sort.iterator().hasNext()) {
return noSort;
}
StringBuilder sb = new StringBuilder(" ORDER BY ");
for (Iterator<Order> it = sort.iterator(); it.hasNext(); ) {
Order order = it.next();
sb.append(order.getProperty()).append(' ').append(order.getDirection());
if (it.hasNext()) {
sb.append(COMMA);
}
}
return sb.toString();
}
示例3: findAll
import org.springframework.data.domain.Sort.Order; //导入依赖的package包/类
/**
* 方法名 : findAll
* 功 能 : TODO(这里用一句话描述这个方法的作用)
* 参 数 : @return
* 参 考 : @see tk.ainiyue.admin.roles.service.SysRolesService#findAll()
* 作 者 : Tenghui.Wang
*/
@Override
public Page<SysSeedInfo> findAll(int pageNumber, int pageSize, String searchText) {
Sort sort = new Sort(new Order(Direction.DESC, "seedName"));
PageRequest request = this.buildPageRequest(pageNumber, pageSize, sort);
Page<SysSeedInfo> sourceCodes = null;
if (searchText == null || "".equals(searchText)) {
sourceCodes = sysSeedDao.findAll(request);
} else {
SysSeedInfo info = new SysSeedInfo();
info.setSeedName(searchText);
Example<SysSeedInfo> example = Example.of(info);
sourceCodes = sysSeedDao.findAll(example, request);
}
return sourceCodes;
}
示例4: getActiveUserStoriesByProjectNameTest
import org.springframework.data.domain.Sort.Order; //导入依赖的package包/类
@Test
public void getActiveUserStoriesByProjectNameTest() {
DashboardDTO dashboard = TestObjectFactory.createDashboard();
Feature story1 = TestObjectFactory.createActiveStory();
Feature story2 = TestObjectFactory.createActiveStory();
List<Feature> stories = new ArrayList<>();
stories.add(story1);
stories.add(story2);
when(featureRepository.findActiveUserStoriesByBoards(Arrays.asList(dashboard.getName()),
new Sort(new Order("sStatus")))).thenReturn(stories);
List<Feature> activeStoriesByDashboardName
= featureService.getActiveUserStoriesByBoards(Arrays.asList(dashboard.getName()));
verify(featureRepository, times(1))
.findActiveUserStoriesByBoards(Arrays.asList(dashboard.getName()), new Sort(new Order("sStatus")));
assertThat(activeStoriesByDashboardName.get(0)).isEqualTo(story1);
assertThat(activeStoriesByDashboardName.get(1)).isEqualTo(story2);
}
示例5: getOrdes
import org.springframework.data.domain.Sort.Order; //导入依赖的package包/类
public static <T> List<Order> getOrdes(String orderBy) {
if (StringUtils.isEmpty(orderBy)) {
return Collections.emptyList();
}
String[] groups = orderBy.trim().split(",");
List<Order> orders = new ArrayList<Order>(groups.length);
for (String group : groups) {
boolean ascending = true;
String[] array = group.split("\\s", 2);
String property = array[0];
if (array.length > 1) {
ascending ="asc".equalsIgnoreCase(array[0]);;
}
Order order = new Order(ascending ? Direction.ASC : Direction.DESC, property);
orders.add(order);
}
return orders;
}
示例6: createSpringSort
import org.springframework.data.domain.Sort.Order; //导入依赖的package包/类
private <T, F> Sort createSpringSort(Query<T, F> q) {
List<QuerySortOrder> sortOrders;
if (q.getSortOrders().isEmpty()) {
sortOrders = getDefaultSortOrders();
} else {
sortOrders = q.getSortOrders();
}
List<Order> orders = sortOrders.stream()
.map(PageableDataProvider::queryOrderToSpringOrder)
.collect(Collectors.toList());
if (orders.isEmpty()) {
return null;
} else {
return new Sort(orders);
}
}
示例7: apply
import org.springframework.data.domain.Sort.Order; //导入依赖的package包/类
@Override
public SortOptions apply(Query<?> query) {
SortOptions.Builder sortOptions = SortOptions.newBuilder();
query.getSort().ifPresent(sort -> {
for (Order order : sort) {
SearchFieldMetadata searchFieldMetadata = searchMetadata.getField(query.getResultType(), order.getProperty());
SortExpression.Builder expression = SortExpression.newBuilder()
.setExpression(searchFieldMetadata.getEncodedName())
.setDirection(order.getDirection().isAscending() ? ASCENDING : DESCENDING);
applyDefaultValue(order, searchFieldMetadata.getIndexType(), expression);
sortOptions.addSortExpression(expression.build());
}
});
return sortOptions.build();
}
示例8: should_sort_health_responses
import org.springframework.data.domain.Sort.Order; //导入依赖的package包/类
@Test
public void should_sort_health_responses() {
// GIVEN
Sort sort = new Sort(
new Order(ASC, "status"),
new Order(DESC, "totalTimeMillis"),
new Order(ASC, "service")
);
// WHEN
Comparator<HealthResponse> comparator = sortCompare.getComparator(sort);
List<HealthResponse> sorted = ImmutableList.sortedCopyOf(comparator, givenHealthResponses());
// THEN
then(sorted).extracting(HealthResponse::getService).containsExactly("E", "D", "C", "B", "A");
}
示例9: getPageable
import org.springframework.data.domain.Sort.Order; //导入依赖的package包/类
public Pageable getPageable(Map<String, String> requestParams) {
int page = RequestUtil.getInteger(requestParams, "pageNum", 1) - 1;
int size = RequestUtil.getInteger(requestParams, "pageSize", 10);
String[] orders = RequestUtil.getArray(requestParams, "sortOrder");
String[] sorts = RequestUtil.getArray(requestParams, "sortName");
List<Order> sortOrders = new ArrayList<Order>();
for (int i = 0; i < sorts.length; i++) {
String sort = sorts[i];
String order = orders[i];
if (order.equals("asc")) {
sortOrders.add(new Order(Direction.ASC, sort));
} else if (order.equals("desc")) {
sortOrders.add(new Order(Direction.DESC, sort));
} else {
throw new IllegalArgumentException("Value for param 'order' is not valid : '" + order + "', must be 'asc' or 'desc'");
}
}
if (sortOrders.isEmpty()) {
return new PageRequest(page, size);
} else {
return new PageRequest(page, size, new Sort(sortOrders));
}
}
示例10: sortQuery
import org.springframework.data.domain.Sort.Order; //导入依赖的package包/类
private Query<T> sortQuery(Query<T> query, Sort sort){
if (sort == null){
return query;
}
Order order;
for (Iterator<Order> iter=sort.iterator(); iter.hasNext(); ){
order=iter.next();
String condition = order.getProperty();
if (order.getDirection().isDescending()){
condition = "-" + condition;
}
query = query.order(condition);
}
return query;
}
示例11: toSpringDataPageable
import org.springframework.data.domain.Sort.Order; //导入依赖的package包/类
public <T> Pageable toSpringDataPageable(
PaginacioParamsDto dto,
Map<String, String> mapeigPropietatsOrdenacio) {
List<Order> orders = new ArrayList<Order>();
if (dto.getOrdres() != null) {
for (OrdreDto ordre: dto.getOrdres()) {
Direction direccio = OrdreDireccioDto.DESCENDENT.equals(ordre.getDireccio()) ? Sort.Direction.DESC : Sort.Direction.ASC;
String propietat = ordre.getCamp();
if (mapeigPropietatsOrdenacio != null) {
String mapeig = mapeigPropietatsOrdenacio.get(ordre.getCamp());
if (mapeig != null)
propietat = mapeig;
} else {
propietat = ordre.getCamp();
}
orders.add(new Order(
direccio,
propietat));
}
}
return new PageRequest(
dto.getPaginaNum(),
dto.getPaginaTamany(),
new Sort(orders));
}
示例12: findAll
import org.springframework.data.domain.Sort.Order; //导入依赖的package包/类
@Override
public Map<String, Object> findAll(int pageNumber) {
logger.debug("Finding all valueSets with paging");
Sort sort = new Sort(new Order(Direction.ASC, "code"));
PageRequest pageRequest = new PageRequest(pageNumber,
VALUE_SET_PAGE_SIZE, sort);
Page<ValueSet> valueSets = valueSetRepository.findAll(pageRequest);
Map<String, Object> pageResultsMap = new HashMap<String, Object>();
pageResultsMap.put("valueSets",
setDeletableToValueSetDto((valueSets.getContent())));
pageResultsMap.put("totalNumberOfValueSets",
valueSets.getTotalElements());
pageResultsMap.put("totalPages", valueSets.getTotalPages());
pageResultsMap.put("itemsPerPage", valueSets.getSize());
pageResultsMap.put("currentPage", valueSets.getNumber());
pageResultsMap.put("numberOfElements", valueSets.getNumberOfElements());
return pageResultsMap;
}
示例13: findAllByName
import org.springframework.data.domain.Sort.Order; //导入依赖的package包/类
@Override
public Map<String, Object> findAllByName(String searchTerm,
String valueSetCategory, int pageNumber) {
Sort sort = new Sort(new Order(Direction.ASC, "code"));
PageRequest pageRequest = new PageRequest(pageNumber,
VALUE_SET_PAGE_SIZE, sort);
Page<ValueSet> pagedValueSets = valueSetRepository.findAllByNameLike(
"%" + searchTerm + "%", "%" + valueSetCategory + "%",
pageRequest);
Map<String, Object> pageResultsMap = new HashMap<String, Object>();
pageResultsMap.put("valueSets",
setDeletableToValueSetDto(pagedValueSets.getContent()));
pageResultsMap.put("totalNumberOfValueSets",
pagedValueSets.getTotalElements());
pageResultsMap.put("totalPages", pagedValueSets.getTotalPages());
pageResultsMap.put("itemsPerPage", pagedValueSets.getSize());
pageResultsMap.put("currentPage", pagedValueSets.getNumber());
pageResultsMap.put("numberOfElements",
pagedValueSets.getNumberOfElements());
return pageResultsMap;
}
示例14: findAllByCode
import org.springframework.data.domain.Sort.Order; //导入依赖的package包/类
@Override
public Map<String, Object> findAllByCode(String searchTerm,
String valueSetCategory, int pageNumber) {
Sort sort = new Sort(new Order(Direction.ASC, "code"));
PageRequest pageRequest = new PageRequest(pageNumber,
VALUE_SET_PAGE_SIZE, sort);
Page<ValueSet> pagedValueSets = valueSetRepository.findAllByCodeLike(
"%" + searchTerm + "%", "%" + valueSetCategory + "%",
pageRequest);
Map<String, Object> pageResultsMap = new HashMap<String, Object>();
pageResultsMap.put("valueSets",
setDeletableToValueSetDto(pagedValueSets.getContent()));
pageResultsMap.put("totalNumberOfValueSets",
pagedValueSets.getTotalElements());
pageResultsMap.put("totalPages", pagedValueSets.getTotalPages());
pageResultsMap.put("itemsPerPage", pagedValueSets.getSize());
pageResultsMap.put("currentPage", pagedValueSets.getNumber());
pageResultsMap.put("numberOfElements",
pagedValueSets.getNumberOfElements());
return pageResultsMap;
}
示例15: findAllByAscendingSort
import org.springframework.data.domain.Sort.Order; //导入依赖的package包/类
@Test
public void findAllByAscendingSort() throws Exception {
// given
dbSetupTracker.skipNextLaunch();
// when
List<BookApi> bookApis = repository.findAll(new Sort(new Order(Sort.Direction.ASC, "id")));
// then
assertThat(bookApis)
.isNotNull()
.isNotEmpty()
.hasSize(3)
.extracting("id", "name", "url")
.containsExactly(
tuple(1, "Amazon Product Advertising API", "https://ecs.amazonaws.jp/onca/xml"),
tuple(2, "Google Books API", "https://www.googleapis.com/books/v1/volumes"),
tuple(3, "楽天ブックス書籍検索API", "https://app.rakuten.co.jp/services/api/BooksBook/Search/20130522")
);
}