Java Code Examples for org.springframework.data.domain.Sort#isUnsorted()
The following examples show how to use
org.springframework.data.domain.Sort#isUnsorted() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: spring-cloud-gcp File: SpannerStatementQueryExecutor.java License: Apache License 2.0 | 6 votes |
public static StringBuilder applySort(Sort sort, StringBuilder sql, SpannerPersistentEntity<?> persistentEntity) { if (sort == null || sort.isUnsorted()) { return sql; } sql.append(" ORDER BY "); StringJoiner sj = new StringJoiner(" , "); sort.iterator().forEachRemaining((o) -> { SpannerPersistentProperty property = persistentEntity.getPersistentProperty(o.getProperty()); String sortedPropertyName = (property != null) ? property.getColumnName() : o.getProperty(); String sortedProperty = o.isIgnoreCase() ? "LOWER(" + sortedPropertyName + ")" : sortedPropertyName; sj.add(sortedProperty + (o.isAscending() ? " ASC" : " DESC")); }); return sql.append(sj); }
Example 2
Source Project: micronaut-data File: SpringPageableRequestArgumentBinder.java License: Apache License 2.0 | 5 votes |
@Override public BindingResult<Pageable> bind(ArgumentConversionContext<Pageable> context, HttpRequest<?> source) { HttpParameters parameters = source.getParameters(); int page = Math.max(parameters.getFirst(configuration.getPageParameterName(), Integer.class) .orElse(0), 0); final int configuredMaxSize = configuration.getMaxPageSize(); final int defaultSize = configuration.getDefaultPageSize(); int size = Math.min(parameters.getFirst(configuration.getSizeParameterName(), Integer.class) .orElse(defaultSize), configuredMaxSize); String sortParameterName = configuration.getSortParameterName(); boolean hasSort = parameters.contains(sortParameterName); Pageable pageable; Sort sort; if (hasSort) { List<String> sortParams = parameters.getAll(sortParameterName); List<Sort.Order> orders = sortParams.stream() .map(sortMapper) .collect(Collectors.toList()); sort = Sort.by(orders); } else { sort = Sort.unsorted(); } if (size < 1) { if (page == 0 && configuredMaxSize < 1 && sort.isUnsorted()) { pageable = Pageable.unpaged(); } else { pageable = PageRequest.of(page, defaultSize, sort); } } else { pageable = PageRequest.of(page, size, sort); } return () -> Optional.of(pageable); }
Example 3
Source Project: spring-data File: AqlUtils.java License: Apache License 2.0 | 5 votes |
private static StringBuilder buildSortClause( final Sort sort, @Nullable final String varName, final StringBuilder clause) { if (sort.isUnsorted()) { return clause; } final String prefix = StringUtils.hasText(varName) ? escapeSortProperty(varName) : null; clause.append("SORT "); boolean first = true; for (final Sort.Order order : sort) { if (!first) { clause.append(", "); } else { first = false; } if (prefix != null) { clause.append(prefix).append('.'); } final String escapedProperty = escapeSortProperty(order.getProperty()); clause.append(escapedProperty).append(' ').append(order.getDirection()); } return clause; }
Example 4
Source Project: spring-data-cosmosdb File: AbstractQueryGenerator.java License: MIT License | 5 votes |
private String generateQuerySort(@NonNull Sort sort) { if (sort.isUnsorted()) { return ""; } final String queryTail = "ORDER BY"; final List<String> subjects = sort.stream().map(this::getParameter).collect(Collectors.toList()); return queryTail + " " + String.join(",", subjects); }
Example 5
Source Project: spring-data-mybatis File: SimpleMybatisRepository.java License: Apache License 2.0 | 5 votes |
@Override public List<T> findAll(Sort sort) { if (null == sort || sort.isUnsorted()) { return findAll(); } return selectList("__find", Collections.singletonMap("__sort", sort)); }
Example 6
Source Project: spring-data-mybatis File: SimpleMybatisRepository.java License: Apache License 2.0 | 5 votes |
@Override public <X extends T> List<T> findAll(Sort sort, X condition) { if (null == sort || sort.isUnsorted()) { return findAll(condition); } return selectList("__find", new HashMap<String, Object>() { { put("__sort", sort); put("__condition", condition); } }); }
Example 7
Source Project: spring-data-mybatis File: MybatisMapperBuildAssistant.java License: Apache License 2.0 | 5 votes |
protected String buildStandardOrderBy(Sort sort) { if (null == sort || sort.isUnsorted()) { return ""; } final Map<String, String> map = findNormalColumns().stream() .collect(Collectors.toMap(p -> p.getName(), p -> p.getColumnName())); return " order by " + sort.stream() .map(order -> map.getOrDefault(order.getProperty(), order.getProperty()) + ' ' + order.getDirection().name().toLowerCase()) .collect(Collectors.joining(",")); }
Example 8
Source Project: spring-data File: DerivedQueryCreator.java License: Apache License 2.0 | 4 votes |
/** * Builds a full AQL query from a built Disjunction, additional information from PartTree and special parameters * caught by ArangoParameterAccessor * * @param criteria * @param sort * @return */ @Override protected String complete(final Criteria criteria, final Sort sort) { if (tree.isDistinct() && !tree.isCountProjection()) { LOGGER.debug("Use of 'Distinct' is meaningful only in count queries"); } final StringBuilder query = new StringBuilder(); final String with = withCollections.stream().collect(Collectors.joining(", ")); if (!with.isEmpty()) { query.append("WITH ").append(with).append(" "); } query.append("FOR ").append("e").append(" IN ").append(collectionName); if (!criteria.getPredicate().isEmpty()) { query.append(" FILTER ").append(criteria.getPredicate()); } if (tree.isCountProjection() || tree.isExistsProjection()) { if (tree.isDistinct()) { query.append(" COLLECT entity = ").append("e"); } query.append(" COLLECT WITH COUNT INTO length"); } String sortString = " " + AqlUtils.buildSortClause(sort, "e"); if ((!this.geoFields.isEmpty() || isUnique != null && isUnique) && !tree.isDelete() && !tree.isCountProjection() && !tree.isExistsProjection()) { final String distanceSortKey = " SORT " + Criteria .distance(uniqueLocation, bind(getUniquePoint()[0]), bind(getUniquePoint()[1])).getPredicate(); if (sort.isUnsorted()) { sortString = distanceSortKey; } else { sortString = distanceSortKey + ", " + sortString.substring(5, sortString.length()); } } query.append(sortString); if (tree.isLimiting()) { query.append(" LIMIT ").append(tree.getMaxResults()); } final Pageable pageable = accessor.getPageable(); if (pageable != null && pageable.isPaged()) { query.append(" ").append(AqlUtils.buildLimitClause(pageable)); } if (tree.isDelete()) { query.append(" REMOVE e IN ").append(collectionName); } else if (tree.isCountProjection() || tree.isExistsProjection()) { query.append(" RETURN length"); } else { query.append(" RETURN "); if (this.geoFields.isEmpty()) { query.append("e"); } else { query.append(format("MERGE(e, { '_distance': %s })", Criteria.distance(uniqueLocation, bind(getUniquePoint()[0]), bind(getUniquePoint()[1])) .getPredicate())); } } return query.toString(); }