Skip to content

Commit dc353bd

Browse files
committed
tried to reproduce the issue
1 parent 09d5a53 commit dc353bd

File tree

2 files changed

+60
-8
lines changed

2 files changed

+60
-8
lines changed

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/AbstractJdbcAggregateTemplateIntegrationTests.java

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131

3232
import org.junit.jupiter.api.Disabled;
3333
import org.junit.jupiter.api.Test;
34-
3534
import org.springframework.beans.factory.annotation.Autowired;
3635
import org.springframework.context.annotation.Bean;
3736
import org.springframework.context.annotation.Configuration;
@@ -44,6 +43,7 @@
4443
import org.springframework.data.annotation.ReadOnlyProperty;
4544
import org.springframework.data.annotation.Version;
4645
import org.springframework.data.domain.PageRequest;
46+
import org.springframework.data.domain.Pageable;
4747
import org.springframework.data.domain.Persistable;
4848
import org.springframework.data.domain.Sort;
4949
import org.springframework.data.jdbc.testing.EnabledOnFeature;
@@ -236,10 +236,30 @@ void findAllByQuery() {
236236
Iterable<SimpleListParent> reloadedById = template.findAll(query, SimpleListParent.class);
237237

238238
assertThat(reloadedById) //
239-
.extracting(e -> e.id, e-> e.name, e -> e.content.size()) //
239+
.extracting(e -> e.id, e -> e.name, e -> e.content.size()) //
240240
.containsExactly(tuple(two.id, two.name, 2));
241241
}
242242

243+
@Test // GH-1601
244+
void findAllByQueryWithConflictingSort() {
245+
246+
SimpleListParent one = template.save(SimpleListParent.of("one", "one_1"));
247+
SimpleListParent two = template.save(SimpleListParent.of("two", "two_1", "two_2"));
248+
SimpleListParent three = template.save(SimpleListParent.of("three", "three_1", "three_2", "three_3"));
249+
250+
CriteriaDefinition criteria = CriteriaDefinition.empty();
251+
Query query = Query.query(criteria);
252+
query.sort(Sort.by(Sort.Direction.ASC, "id"));
253+
254+
Pageable pageable = PageRequest.of(0, 3, Sort.by(Sort.Direction.DESC, "name"));
255+
256+
Iterable<SimpleListParent> reloadedById = template.findAll(query, SimpleListParent.class, pageable);
257+
258+
assertThat(reloadedById) //
259+
.extracting(e -> e.id) //
260+
.containsExactly(two.id, three.id, one.id);
261+
}
262+
243263
@Test // GH-1803
244264
void findAllByQueryWithColumns() {
245265

@@ -252,7 +272,7 @@ void findAllByQueryWithColumns() {
252272
Iterable<SimpleListParent> reloadedById = template.findAll(query, SimpleListParent.class);
253273

254274
assertThat(reloadedById) //
255-
.extracting(e -> e.id, e-> e.name, e -> e.content.size()) //
275+
.extracting(e -> e.id, e -> e.name, e -> e.content.size()) //
256276
.containsExactly(tuple(two.id, null, 2));
257277
}
258278

@@ -1382,8 +1402,7 @@ void recordOfSet() {
13821402
void mapWithEnumKey() {
13831403

13841404
EnumMapOwner enumMapOwner = template
1385-
.save(
1386-
new EnumMapOwner(null, "OwnerName", Map.of(Color.BLUE, new MapElement("Element"))));
1405+
.save(new EnumMapOwner(null, "OwnerName", Map.of(Color.BLUE, new MapElement("Element"))));
13871406

13881407
Iterable<EnumMapOwner> enumMapOwners = template.findAll(EnumMapOwner.class);
13891408

@@ -2220,8 +2239,7 @@ public Short getVersion() {
22202239
@Table("BEFORE_CONVERT_CALLBACK_FOR_SAVE_BATCH")
22212240
static class BeforeConvertCallbackForSaveBatch {
22222241

2223-
@Id
2224-
private String id;
2242+
@Id private String id;
22252243

22262244
private String name;
22272245

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/SqlGeneratorUnitTests.java

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ void countByQuerySimpleValidTest() {
939939
}
940940

941941
@Test // GH-1192
942-
void selectByQueryPaginationValidTest() {
942+
void selectByQueryPlusPagination() {
943943

944944
SqlGenerator sqlGenerator = createSqlGenerator(DummyEntity.class);
945945

@@ -965,6 +965,40 @@ void selectByQueryPaginationValidTest() {
965965
.containsOnly(entry("x_name", probe.name));
966966
}
967967

968+
@Test // GH-2138
969+
void selectByQueryWithRedundantPagination() {
970+
971+
SqlGenerator sqlGenerator = createSqlGenerator(DummyEntity.class);
972+
973+
DummyEntity probe = new DummyEntity();
974+
probe.name = "Diego";
975+
976+
Criteria criteria = Criteria.where("name").is(probe.name);
977+
Query query = Query.query(criteria);
978+
query.sort(Sort.by(Sort.Order.asc("id")));
979+
query.offset(23);
980+
query.limit(11);
981+
982+
PageRequest pageRequest = PageRequest.of(2, 1, Sort.by(Sort.Order.asc("name")));
983+
984+
MapSqlParameterSource parameterSource = new MapSqlParameterSource();
985+
986+
String generatedSQL = sqlGenerator.selectByQuery(query, parameterSource, pageRequest);
987+
assertThat(generatedSQL) //
988+
.isNotNull() //
989+
.contains(":x_name") //
990+
.containsIgnoringCase("ORDER BY dummy_entity.x_name ASC") //
991+
.containsIgnoringCase("LIMIT 1") //
992+
.containsIgnoringCase("OFFSET 2 LIMIT 1") //
993+
.doesNotContainIgnoringCase("LIMIT 11") //
994+
.doesNotContainIgnoringCase("OFFSET 23");
995+
996+
assertThat(parameterSource.getValues()) //
997+
.containsOnly(entry("x_name", probe.name));
998+
999+
System.out.println(generatedSQL);
1000+
}
1001+
9681002
@Test // GH-1161
9691003
void backReferenceShouldConsiderRenamedParent() {
9701004

0 commit comments

Comments
 (0)