1 /**
2 * Copyright © 2018 spring-data-dynamodb (https://github.com/derjust/spring-data-dynamodb)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.socialsignin.spring.data.dynamodb.utils;
17
18 import org.springframework.data.domain.Pageable;
19 import org.springframework.data.domain.Sort;
20
21 /**
22 * Some helper methods to deal with {@link Sort}.
23 *
24 * @author derjust
25 */
26 public interface SortHandler {
27
28 /**
29 * @param pageable
30 * The {@link Pageable} to check that no sort is specified
31 */
32 default void ensureNoSort(Pageable pageable) {
33 Sort sort = pageable.getSort();
34 ensureNoSort(sort);
35 }
36
37 /**
38 * @param sort
39 * The {@link Sort} to check that no sort is specified
40 * @throws UnsupportedOperationException
41 * if a {@code sort} is initialized (non-null && not
42 * {@link Sort#unsorted()}
43 */
44 default void ensureNoSort(Sort sort) throws UnsupportedOperationException {
45 if (!Sort.unsorted().equals(sort)) {
46 throwUnsupportedSortOperationException();
47 }
48 }
49
50 default <T> T throwUnsupportedSortOperationException() {
51 throw new UnsupportedOperationException("Sorting not supported for scan expressions");
52 }
53 }