Skip to content

Commit 7b80548

Browse files
committed
Polishing.
Reformat 'applyScrollOrderBy'. See #2149 Signed-off-by: Artemiy Chereshnevvv <[email protected]>
1 parent c90d2b4 commit 7b80548

File tree

2 files changed

+5
-20
lines changed

2 files changed

+5
-20
lines changed

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/PartTreeJdbcQuery.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717

1818
import static org.springframework.data.jdbc.repository.query.JdbcQueryExecution.*;
1919

20-
import java.lang.reflect.Field;
2120
import java.sql.ResultSet;
2221
import java.util.ArrayList;
23-
import java.util.Arrays;
2422
import java.util.Collection;
2523
import java.util.LinkedHashMap;
2624
import java.util.List;
@@ -29,7 +27,6 @@
2927
import java.util.function.IntFunction;
3028
import java.util.function.LongSupplier;
3129
import java.util.function.Supplier;
32-
import java.util.stream.Collectors;
3330

3431
import org.jspecify.annotations.Nullable;
3532
import org.springframework.core.convert.converter.Converter;
@@ -65,7 +62,6 @@
6562
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
6663
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
6764
import org.springframework.util.Assert;
68-
import org.springframework.util.ReflectionUtils;
6965

7066
/**
7167
* An {@link AbstractJdbcQuery} implementation based on a {@link PartTree}.

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/StatementFactory.java

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -237,30 +237,19 @@ Sort applyScrollOrderBy(Sort sort, @Nullable ScrollPosition scrollPosition) {
237237
if (!(scrollPosition instanceof KeysetScrollPosition) || scrollPosition.isInitial())
238238
return sort;
239239

240-
Set<String> orders = sort.get().map(Sort.Order::getProperty).map(it -> {
241-
RelationalPersistentProperty prop = entity.getPersistentProperty(it);
242-
if (prop == null)
243-
return it;
244-
245-
return prop.getName();
246-
}).collect(Collectors.toSet());
240+
Set<String> sortedProperties = sort.get().map(Sort.Order::getProperty).collect(Collectors.toSet());
247241

248242
Set<String> keys = ((KeysetScrollPosition) scrollPosition).getKeys().keySet();
249243

250-
Set<String> notSorted = keys.stream().map(it -> {
251-
RelationalPersistentProperty prop = entity.getPersistentProperty(it);
252-
if (prop == null)
253-
return it;
254-
255-
return prop.getName();
256-
}).filter(it -> orders.stream().noneMatch(order -> order.equalsIgnoreCase(it))).collect(Collectors.toSet());
244+
Set<String> notSortedProperties
245+
= keys.stream().filter(it -> !sortedProperties.contains(it)).collect(Collectors.toSet());
257246

258-
if (notSorted.isEmpty())
247+
if (notSortedProperties.isEmpty())
259248
return sort;
260249

261250
Sort.Direction defaultSort = sort.get().map(Sort.Order::getDirection).findAny().orElse(Sort.DEFAULT_DIRECTION);
262251

263-
return sort.and(Sort.by(defaultSort, notSorted.toArray(new String[0])));
252+
return sort.and(Sort.by(defaultSort, notSortedProperties.toArray(new String[0])));
264253
}
265254

266255
Criteria applyScrollCriteria(@Nullable ScrollPosition position, Sort sort) {

0 commit comments

Comments
 (0)