Java Code Examples for org.springframework.data.domain.Sort#iterator()
The following examples show how to use
org.springframework.data.domain.Sort#iterator() .
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 File: QueryBuilder.java From spring-data-simpledb with MIT License | 6 votes |
public QueryBuilder with(Sort sort) { if(sort != null) { Iterator<Sort.Order> sortIt = sort.iterator(); if(sortIt.hasNext()) { Sort.Order order = sortIt.next(); appendWhereOrEndClause(query); query.append(order.getProperty()).append(" is not null order by "); query.append(order.getProperty()).append(" ").append(order.getDirection().name().toLowerCase()); } if(sortIt.hasNext()) { throw new IllegalArgumentException("SimpleDb does not support multiple sorting"); } } return this; }
Example 2
Source File: AbstractRdbmsKeyValueRepository.java From spring-cloud-dashboard with Apache License 2.0 | 5 votes |
@Override public Iterable<D> findAll(Sort sort) { Assert.notNull(sort, "sort must not be null"); Iterator<Sort.Order> iter = sort.iterator(); String query = findAllQuery + "ORDER BY "; while (iter.hasNext()) { Sort.Order order = iter.next(); query = query + order.getProperty() + " " + order.getDirection(); if (iter.hasNext()) { query = query + ", "; } } return jdbcTemplate.query(query, rowMapper); }
Example 3
Source File: Converters.java From spring-data-ebean with Apache License 2.0 | 5 votes |
/** * Convert spring data Sort to Ebean OrderBy. * * @param sort * @param <T> * @return */ public static <T> OrderBy<T> convertToEbeanOrderBy(Sort sort) { if (sort == null) { return null; } List<String> list = new ArrayList<>(); Iterator<Sort.Order> orderIterator = sort.iterator(); while (orderIterator.hasNext()) { Sort.Order so = orderIterator.next(); list.add(so.getProperty() + " " + so.getDirection()); } return new OrderBy<T>(StringUtils.collectionToCommaDelimitedString(list)); }
Example 4
Source File: VisitorRepository.java From jump-the-queue with Apache License 2.0 | 4 votes |
/** * Add sorting to the given query on the given alias * * @param query to add sorting to * @param alias to retrieve columns from for sorting * @param sort specification of sorting */ public default void addOrderBy(JPAQuery<VisitorEntity> query, VisitorEntity alias, Sort sort) { if (sort != null && sort.isSorted()) { Iterator<Order> it = sort.iterator(); while (it.hasNext()) { Order next = it.next(); switch (next.getProperty()) { case "username": if (next.isAscending()) { query.orderBy($(alias.getUsername()).asc()); } else { query.orderBy($(alias.getUsername()).desc()); } break; case "name": if (next.isAscending()) { query.orderBy($(alias.getName()).asc()); } else { query.orderBy($(alias.getName()).desc()); } break; case "phoneNumber": if (next.isAscending()) { query.orderBy($(alias.getPhoneNumber()).asc()); } else { query.orderBy($(alias.getPhoneNumber()).desc()); } break; case "password": if (next.isAscending()) { query.orderBy($(alias.getPassword()).asc()); } else { query.orderBy($(alias.getPassword()).desc()); } break; case "acceptedCommercial": if (next.isAscending()) { query.orderBy($(alias.getAcceptedCommercial()).asc()); } else { query.orderBy($(alias.getAcceptedCommercial()).desc()); } break; case "acceptedTerms": if (next.isAscending()) { query.orderBy($(alias.getAcceptedTerms()).asc()); } else { query.orderBy($(alias.getAcceptedTerms()).desc()); } break; case "userType": if (next.isAscending()) { query.orderBy($(alias.getUserType()).asc()); } else { query.orderBy($(alias.getUserType()).desc()); } break; default: throw new IllegalArgumentException("Sorted by the unknown property '" + next.getProperty() + "'"); } } } }
Example 5
Source File: QueueRepository.java From jump-the-queue with Apache License 2.0 | 4 votes |
/** * Add sorting to the given query on the given alias * * @param query to add sorting to * @param alias to retrieve columns from for sorting * @param sort specification of sorting */ public default void addOrderBy(JPAQuery<QueueEntity> query, QueueEntity alias, Sort sort) { if (sort != null && sort.isSorted()) { Iterator<Order> it = sort.iterator(); while (it.hasNext()) { Order next = it.next(); switch (next.getProperty()) { case "name": if (next.isAscending()) { query.orderBy($(alias.getName()).asc()); } else { query.orderBy($(alias.getName()).desc()); } break; case "logo": if (next.isAscending()) { query.orderBy($(alias.getLogo()).asc()); } else { query.orderBy($(alias.getLogo()).desc()); } break; case "currentNumber": if (next.isAscending()) { query.orderBy($(alias.getCurrentNumber()).asc()); } else { query.orderBy($(alias.getCurrentNumber()).desc()); } break; case "attentionTime": if (next.isAscending()) { query.orderBy($(alias.getAttentionTime()).asc()); } else { query.orderBy($(alias.getAttentionTime()).desc()); } break; case "minAttentionTime": if (next.isAscending()) { query.orderBy($(alias.getMinAttentionTime()).asc()); } else { query.orderBy($(alias.getMinAttentionTime()).desc()); } break; case "active": if (next.isAscending()) { query.orderBy($(alias.getActive()).asc()); } else { query.orderBy($(alias.getActive()).desc()); } break; case "customers": if (next.isAscending()) { query.orderBy($(alias.getCustomers()).asc()); } else { query.orderBy($(alias.getCustomers()).desc()); } break; default: throw new IllegalArgumentException("Sorted by the unknown property '" + next.getProperty() + "'"); } } } }
Example 6
Source File: AccessCodeRepository.java From jump-the-queue with Apache License 2.0 | 4 votes |
/** * Add sorting to the given query on the given alias * * @param query to add sorting to * @param alias to retrieve columns from for sorting * @param sort specification of sorting */ public default void addOrderBy(JPAQuery<AccessCodeEntity> query, AccessCodeEntity alias, Sort sort) { if (sort != null && sort.isSorted()) { Iterator<Order> it = sort.iterator(); while (it.hasNext()) { Order next = it.next(); switch (next.getProperty()) { case "ticketNumber": if (next.isAscending()) { query.orderBy($(alias.getTicketNumber()).asc()); } else { query.orderBy($(alias.getTicketNumber()).desc()); } break; case "creationTime": if (next.isAscending()) { query.orderBy($(alias.getCreationTime()).asc()); } else { query.orderBy($(alias.getCreationTime()).desc()); } break; case "startTime": if (next.isAscending()) { query.orderBy($(alias.getStartTime()).asc()); } else { query.orderBy($(alias.getStartTime()).desc()); } break; case "endTime": if (next.isAscending()) { query.orderBy($(alias.getEndTime()).asc()); } else { query.orderBy($(alias.getEndTime()).desc()); } break; case "visitor": if (next.isAscending()) { query.orderBy($(alias.getVisitor().getId()).asc()); } else { query.orderBy($(alias.getVisitor().getId()).desc()); } break; case "queue": if (next.isAscending()) { query.orderBy($(alias.getQueue().getId()).asc()); } else { query.orderBy($(alias.getQueue().getId()).desc()); } break; default: throw new IllegalArgumentException("Sorted by the unknown property '" + next.getProperty() + "'"); } } } }