Java 类org.springframework.data.domain.Sort.NullHandling 实例源码

项目:commons-jkit    文件:OrderDeserializer.java   
private Object create(String direction, String property, boolean isIgnoreCase, String nullHandling)
        throws IOException {
    if (property == null) {
        throw new IOException(getType().getName() + " expects name.");
    }

    try {
        return _constructor.newInstance(//
                isNullValue(direction) ? null : Direction.fromStringOrNull(direction), //
                property, //
                isIgnoreCase, //
                isNullValue(nullHandling) ? null : NullHandling.valueOf(nullHandling));
    }
    catch (Exception e) {
        throw new IOExceptionWrapper(e);
    }
}
项目:commons-jkit    文件:Hessian2SerializationTest.java   
@Test
public void testSort_Order() throws Exception {
    Hessian2Serialization.addSerializer(Sort.Order.class, new OrderSerializer());
    Hessian2Serialization.addDeserializer(Sort.Order.class, new OrderDeserializer());

    final Sort.Order[] orders = new Sort.Order[3];
    orders[0] = new Sort.Order(Sort.Direction.ASC, "order_num", null);
    orders[1] = new Sort.Order(null, "order_num", null);
    orders[2] = new Sort.Order(Sort.Direction.DESC, "create_time", NullHandling.NULLS_LAST);

    final byte[] buf = Hessian2Serialization.serialize(orders);

    //      System.out.println(new String(buf));

    final Sort.Order[] expectOrders = Hessian2Serialization.deserialize(buf);

    for (int i = 0; i < orders.length; i++) {
        Assert.assertTrue(orders[i].equals(expectOrders[i]));
    }
}
项目:spring-data-mapdb    文件:MapDbSortAccessor.java   
/**
 * Sort on a sequence of fields, possibly none.
 *
 * @param query
 *            If not null, will contain one of more {@link Sort.Order}
 *            objects.
 * @return A sequence of comparators or {@code null}
 */
public Comparator<?> resolve(KeyValueQuery<?> query) {

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

    CompoundComparator<Object> compoundComparator = new CompoundComparator<>();

    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);
        }

        PropertyComparator propertyComparator = new PropertyComparator(order.getProperty(),
                order.isAscending());

        compoundComparator.addComparator(propertyComparator);
    }

    return compoundComparator;
}
项目:commons-jkit    文件:OrderDeserializer.java   
public OrderDeserializer() {
    try {
        _constructor = getType().getDeclaredConstructor(Direction.class, String.class, boolean.class,
                NullHandling.class);
        _constructor.setAccessible(true);
    }
    catch (Exception e) {
        throw new RuntimeException(e);
    }
}
项目:commons-jkit    文件:Hessian2SerializationTest.java   
@Test
public void testSort() throws Exception {
    Hessian2Serialization.addSerializer(Sort.Order.class, new OrderSerializer());
    Hessian2Serialization.addDeserializer(Sort.Order.class, new OrderDeserializer());
    Hessian2Serialization.addSerializer(Sort.class, new SortSerializer());
    Hessian2Serialization.addDeserializer(Sort.class, new SortDeserializer());

    final Sort.Order[] orders = new Sort.Order[3];
    orders[0] = new Sort.Order(Sort.Direction.ASC, "order_num", null);
    orders[0] = null;
    orders[2] = new Sort.Order(Sort.Direction.DESC, "create_time", NullHandling.NULLS_LAST);

    final Sort sort = new Sort(orders);

    final byte[] buf = Hessian2Serialization.serialize(sort);

    final Sort expectSort = Hessian2Serialization.deserialize(buf);

    final Iterator<Order> iterator = expectSort.iterator();
    int i = 0;
    while (iterator.hasNext()) {
        Order expect = iterator.next();

        Assert.assertTrue(orders[i] == expect || orders[i].equals(expect));
        ++i;
    }
}
项目:spring-data-hazelcast    文件:HazelcastSortAccessor.java   
/**
 * <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() == null) {
        return null;
    }

    CompoundComparator<Entry<?, ?>> compoundComparator = new CompoundComparator<>();

    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);
        }

        HazelcastPropertyComparator hazelcastPropertyComparator = new HazelcastPropertyComparator(order.getProperty(),
                order.isAscending());

        compoundComparator.addComparator(hazelcastPropertyComparator);
    }

    return compoundComparator;
}
项目:spring-data-keyvalue    文件:SpelSortAccessor.java   
@SuppressWarnings({ "rawtypes", "unchecked" })
@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"));
}
项目:spring-data-keyvalue    文件:KeyValueQuerydslUtilsUnitTests.java   
@Test // DATACMNS-525
public void toOrderSpecifierConvertsSortWithNullHandlingCorrectly() {

    Sort sort = Sort.by(new Sort.Order(Direction.DESC, "firstname", NullHandling.NULLS_LAST));

    OrderSpecifier<?>[] specifiers = toOrderSpecifier(sort, builder);

    assertThat(specifiers,
            IsArrayContainingInOrder.arrayContaining(QPerson.person.firstname.desc().nullsLast()));
}