org.springframework.data.domain.Sort.Order#getProperty ( )源码实例Demo

下面列出了org.springframework.data.domain.Sort.Order#getProperty ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: springlets   文件: OrderAdapter.java
@Override
public OrderDto marshal(Order order) {

  if (order == null) {
    return null;
  }

  OrderDto dto = new OrderDto();
  dto.direction = order.getDirection();
  dto.property = order.getProperty();
  return dto;
}
 
/**
 * <p>
 * Sort on a sequence of fields, possibly none.
 * </P>
 *
 * @param query If not null, will contain one of more {@link Sort.Order} objects.
 * @return A sequence of comparators or {@code null}
 */
public Comparator<Entry<?, ?>> resolve(KeyValueQuery<?> query) {

    if (query == null || query.getSort() == Sort.unsorted()) {
        return null;
    }

    Comparator hazelcastPropertyComparator = null;

    for (Order order : query.getSort()) {

        if (order.getProperty().indexOf('.') > -1) {
            throw new UnsupportedOperationException("Embedded fields not implemented: " + order);
        }

        if (order.isIgnoreCase()) {
            throw new UnsupportedOperationException("Ignore case not implemented: " + order);
        }

        if (NullHandling.NATIVE != order.getNullHandling()) {
            throw new UnsupportedOperationException("Null handling not implemented: " + order);
        }

        if (hazelcastPropertyComparator == null) {
            hazelcastPropertyComparator = new HazelcastPropertyComparator(order.getProperty(),
                    order.isAscending());
        } else {
            hazelcastPropertyComparator = hazelcastPropertyComparator.thenComparing(
                    new HazelcastPropertyComparator(order.getProperty(),
                    order.isAscending()));
        }
    }

    return hazelcastPropertyComparator;
}
 
源代码3 项目: spring-data-keyvalue   文件: SpelSortAccessor.java
@Override
public Comparator<?> resolve(KeyValueQuery<?> query) {

	if (query.getSort().isUnsorted()) {
		return null;
	}

	Optional<Comparator<?>> comparator = Optional.empty();
	for (Order order : query.getSort()) {

		SpelPropertyComparator<Object> spelSort = new SpelPropertyComparator<>(order.getProperty(), parser);

		if (Direction.DESC.equals(order.getDirection())) {

			spelSort.desc();

			if (!NullHandling.NATIVE.equals(order.getNullHandling())) {
				spelSort = NullHandling.NULLS_FIRST.equals(order.getNullHandling()) ? spelSort.nullsFirst()
						: spelSort.nullsLast();
			}
		}

		if (!comparator.isPresent()) {
			comparator = Optional.of(spelSort);
		} else {

			SpelPropertyComparator<Object> spelSortToUse = spelSort;
			comparator = comparator.map(it -> it.thenComparing(spelSortToUse));
		}
	}

	return comparator.orElseThrow(
			() -> new IllegalStateException("No sort definitions have been added to this CompoundComparator to compare"));
}
 
源代码4 项目: jump-the-queue   文件: VisitorRepository.java
/**
 * 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() + "'");
			}
		}
	}
}
 
源代码5 项目: jump-the-queue   文件: QueueRepository.java
/**
 * 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() + "'");
			}
		}
	}
}
 
源代码6 项目: jump-the-queue   文件: AccessCodeRepository.java
/**
 * 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() + "'");
			}
		}
	}
}