List of usage examples for org.springframework.data.domain Sort and
public Sort and(Sort sort)
From source file:cn.guoyukun.spring.jpa.entity.search.SearchRequest.java
private void merge(Sort sort, Pageable page) { if (sort == null) { sort = this.sort; }//www. j ava 2 s . c o m if (page == null) { page = this.page; } //?? if (sort == null) { this.sort = page != null ? page.getSort() : null; } else { this.sort = (page != null ? sort.and(page.getSort()) : sort); } //??page if (page != null) { this.page = new PageRequest(page.getPageNumber(), page.getPageSize(), this.sort); } else { this.page = null; } }
From source file:cn.guoyukun.spring.jpa.web.bind.method.annotation.PageableMethodArgumentResolver.java
private Pageable defaultPageable(PageableDefaults pageableDefaults) { if (pageableDefaults == null) { return null; }/*ww w .j av a 2 s . c om*/ int pageNumber = pageableDefaults.pageNumber(); int pageSize = pageableDefaults.value(); String[] sortStrArray = pageableDefaults.sort(); Sort sort = null; for (String sortStr : sortStrArray) { String[] sortStrPair = sortStr.split("="); Sort newSort = new Sort(Sort.Direction.fromString(sortStrPair[1]), sortStrPair[0]); if (sort == null) { sort = newSort; } else { sort = sort.and(newSort); } } return new PageRequest(pageNumber, pageSize, sort); }
From source file:se.inera.axel.shs.broker.messagestore.internal.MongoMessageLogService.java
@Override public Iterable<ShsMessageEntry> listMessages(String shsTo, Filter filter) { Criteria criteria = Criteria.where("label.to.value").is(shsTo).and("label.transferType") .is(TransferType.ASYNCH).and("state").is(MessageState.RECEIVED).and("archived").in(null, false); if (filter.getProductIds() != null && !filter.getProductIds().isEmpty()) { criteria = criteria.and("label.product.value").in(filter.getProductIds()); }/*w w w . j av a 2s. c o m*/ if (filter.getNoAck() == true) { criteria = criteria.and("acknowledged").in(false, null); } if (filter.getStatus() != null) { criteria = criteria.and("label.status").is(filter.getStatus()); } if (filter.getEndRecipient() != null) { criteria = criteria.and("label.endRecipient.value").is(filter.getEndRecipient()); } if (filter.getOriginator() != null) { criteria = criteria.and("label.originatorOrFrom.value").is(filter.getOriginator()); } if (filter.getCorrId() != null) { criteria = criteria.and("label.corrId").is(filter.getCorrId()); } if (filter.getContentId() != null) { criteria = criteria.and("label.content.contentId").is(filter.getContentId()); } if (filter.getMetaName() != null) { criteria = criteria.and("label.meta.name").is(filter.getMetaName()); } if (filter.getMetaValue() != null) { criteria = criteria.and("label.meta.value").is(filter.getMetaValue()); } if (filter.getSince() != null) { criteria = criteria.and("stateTimeStamp").gte(filter.getSince()); } Query query = Query.query(criteria); Sort sort = createAttributeSort(filter); Sort arrivalOrderSort = createArrivalOrderSort(filter); if (sort != null) sort.and(arrivalOrderSort); else sort = arrivalOrderSort; query.with(sort); if (filter.getMaxHits() != null && filter.getMaxHits() > 0) query = query.limit(filter.getMaxHits()); else query = query.limit(200); return mongoTemplate.find(query, ShsMessageEntry.class); }
From source file:org.tylproject.vaadin.addon.MongoContainer.java
@Override public void sort(Object[] propertyId, boolean[] ascending) { if (propertyId.length != ascending.length) throw new IllegalArgumentException( String.format("propertyId array length does not match" + "ascending array length (%d!=%d)", propertyId.length, ascending.length)); Sort result = null; // if the arrays are empty, will just the conditions if (propertyId.length != 0) { result = new Sort(ascending[0] ? Sort.Direction.ASC : Sort.Direction.DESC, propertyId[0].toString()); for (int i = 1; i < propertyId.length; i++) { result = result.and(new Sort(ascending[i] ? Sort.Direction.ASC : Sort.Direction.DESC, propertyId[i].toString())); }/* w ww. j a v a 2s. c om*/ } resetQuery(); applySort(this.query, result); applyCriteriaList(this.query, appliedCriteria); this.sort = result; refresh(); fireItemSetChange(); }
From source file:cn.guoyukun.spring.jpa.web.bind.method.annotation.PageableMethodArgumentResolver.java
private Sort getSort(String sortNamePrefix, Map<String, String[]> sortMap, Pageable defaultPageRequest, NativeWebRequest webRequest) {/*from ww w . j a va2s. co m*/ Sort sort = null; List<OrderedSort> orderedSortList = Lists.newArrayList(); for (String name : sortMap.keySet()) { //sort1.abc int propertyIndex = name.indexOf(".") + 1; int order = 0; String orderStr = name.substring(sortNamePrefix.length(), propertyIndex - 1); try { if (!StringUtils.isEmpty(orderStr)) { order = Integer.valueOf(orderStr); } } catch (Exception e) { } String property = name.substring(propertyIndex); assertSortProperty(property); Sort.Direction direction = Sort.Direction.fromString(sortMap.get(name)[0]); orderedSortList.add(new OrderedSort(property, direction, order)); } Collections.sort(orderedSortList); for (OrderedSort orderedSort : orderedSortList) { Sort newSort = new Sort(orderedSort.direction, orderedSort.property); if (sort == null) { sort = newSort; } else { sort = sort.and(newSort); } } if (sort == null) { return defaultPageRequest.getSort(); } return sort; }