Skip to content
Closed

fix #2144

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>4.0.0-2138-query-with-pageable-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Spring Data Relational Parent</name>
Expand Down
2 changes: 1 addition & 1 deletion spring-data-jdbc-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>4.0.0-2138-query-with-pageable-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
4 changes: 2 additions & 2 deletions spring-data-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-data-jdbc</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>4.0.0-2138-query-with-pageable-SNAPSHOT</version>

<name>Spring Data JDBC</name>
<description>Spring Data module for JDBC repositories.</description>
Expand All @@ -15,7 +15,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>4.0.0-2138-query-with-pageable-SNAPSHOT</version>
</parent>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -44,6 +43,7 @@
import org.springframework.data.annotation.ReadOnlyProperty;
import org.springframework.data.annotation.Version;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Persistable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jdbc.testing.EnabledOnFeature;
Expand Down Expand Up @@ -236,10 +236,32 @@ void findAllByQuery() {
Iterable<SimpleListParent> reloadedById = template.findAll(query, SimpleListParent.class);

assertThat(reloadedById) //
.extracting(e -> e.id, e-> e.name, e -> e.content.size()) //
.extracting(e -> e.id, e -> e.name, e -> e.content.size()) //
.containsExactly(tuple(two.id, two.name, 2));
}

@Test // GH-1601
void findAllByQueryWithConflictingSort() {

SimpleListParent one = template.save(SimpleListParent.of("one", "one_1"));
SimpleListParent two = template.save(SimpleListParent.of("two", "two_1", "two_2"));
SimpleListParent three = template.save(SimpleListParent.of("three", "three_1", "three_2", "three_3"));

CriteriaDefinition criteria = CriteriaDefinition.empty();
Query query = Query.query(criteria);
query = query.sort(Sort.by(Sort.Direction.ASC, "id"));
query = query.offset(23);
query = query.limit(11);

Pageable pageable = PageRequest.of(0, 3, Sort.by(Sort.Direction.DESC, "name"));

Iterable<SimpleListParent> reloadedById = template.findAll(query, SimpleListParent.class, pageable);

assertThat(reloadedById) //
.extracting(e -> e.id) //
.containsExactly(two.id, three.id, one.id);
}

@Test // GH-1803
void findAllByQueryWithColumns() {

Expand All @@ -252,7 +274,7 @@ void findAllByQueryWithColumns() {
Iterable<SimpleListParent> reloadedById = template.findAll(query, SimpleListParent.class);

assertThat(reloadedById) //
.extracting(e -> e.id, e-> e.name, e -> e.content.size()) //
.extracting(e -> e.id, e -> e.name, e -> e.content.size()) //
.containsExactly(tuple(two.id, null, 2));
}

Expand Down Expand Up @@ -1382,8 +1404,7 @@ void recordOfSet() {
void mapWithEnumKey() {

EnumMapOwner enumMapOwner = template
.save(
new EnumMapOwner(null, "OwnerName", Map.of(Color.BLUE, new MapElement("Element"))));
.save(new EnumMapOwner(null, "OwnerName", Map.of(Color.BLUE, new MapElement("Element"))));

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

Expand Down Expand Up @@ -2220,8 +2241,7 @@ public Short getVersion() {
@Table("BEFORE_CONVERT_CALLBACK_FOR_SAVE_BATCH")
static class BeforeConvertCallbackForSaveBatch {

@Id
private String id;
@Id private String id;

private String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ void countByQuerySimpleValidTest() {
}

@Test // GH-1192
void selectByQueryPaginationValidTest() {
void selectByQueryPlusPagination() {

SqlGenerator sqlGenerator = createSqlGenerator(DummyEntity.class);

Expand All @@ -965,6 +965,41 @@ void selectByQueryPaginationValidTest() {
.containsOnly(entry("x_name", probe.name));
}

@Test // GH-2138
void selectByQueryWithRedundantPagination() {

SqlGenerator sqlGenerator = createSqlGenerator(DummyEntity.class);

DummyEntity probe = new DummyEntity();
probe.name = "Diego";

Criteria criteria = Criteria.where("name").is(probe.name);
Query query = Query.query(criteria);
query = query.sort(Sort.by(Sort.Order.asc("id")));
query = query.offset(23);
query = query.limit(11);

PageRequest pageRequest = PageRequest.of(2, 1, Sort.by(Sort.Order.asc("name")));

MapSqlParameterSource parameterSource = new MapSqlParameterSource();

String generatedSQL = sqlGenerator.selectByQuery(query, parameterSource, pageRequest);
assertThat(generatedSQL) //
.isNotNull() //
.contains(":x_name") //
.containsIgnoringCase("ORDER BY dummy_entity.x_name ASC") //
.containsIgnoringCase("LIMIT 1") //
.containsIgnoringCase("OFFSET 2 LIMIT 1") //
.doesNotContainIgnoringCase("LIMIT 11") //
.doesNotContainIgnoringCase("OFFSET 23")
.doesNotContainIgnoringCase("dummy_entity.id1 ASC");

assertThat(parameterSource.getValues()) //
.containsOnly(entry("x_name", probe.name));

System.out.println(generatedSQL);
}

@Test // GH-1161
void backReferenceShouldConsiderRenamedParent() {

Expand Down
4 changes: 2 additions & 2 deletions spring-data-r2dbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-data-r2dbc</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>4.0.0-2138-query-with-pageable-SNAPSHOT</version>

<name>Spring Data R2DBC</name>
<description>Spring Data module for R2DBC</description>
Expand All @@ -15,7 +15,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>4.0.0-2138-query-with-pageable-SNAPSHOT</version>
</parent>

<properties>
Expand Down
4 changes: 2 additions & 2 deletions spring-data-relational/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-data-relational</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>4.0.0-2138-query-with-pageable-SNAPSHOT</version>

<name>Spring Data Relational</name>
<description>Spring Data Relational support</description>

<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>4.0.0-2138-query-with-pageable-SNAPSHOT</version>
</parent>

<properties>
Expand Down