Skip to content

Commit 9aa9a4b

Browse files
mp911deschauder
authored andcommitted
Fix unpaged revision query.
We now return all results for an unpaged query. Closes #3999 Original pull request #4000
1 parent 2a0bddb commit 9aa9a4b

File tree

2 files changed

+51
-11
lines changed

2 files changed

+51
-11
lines changed

spring-data-envers/src/main/java/org/springframework/data/envers/repository/support/EnversRevisionRepositoryImpl.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,12 @@ public Page<Revision<N, T>> findRevisions(ID id, Pageable pageable) {
182182

183183
orderMapped.forEach(baseQuery::addOrder);
184184

185+
if (pageable.isPaged()) {
186+
baseQuery.setFirstResult((int) pageable.getOffset()) //
187+
.setMaxResults(pageable.getPageSize());
188+
}
189+
185190
List<Object[]> resultList = baseQuery //
186-
.setFirstResult((int) pageable.getOffset()) //
187-
.setMaxResults(pageable.getPageSize()) //
188191
.getResultList();
189192

190193
Long count = (Long) createBaseQuery(id) //

spring-data-envers/src/test/java/org/springframework/data/envers/repository/support/RepositoryIntegrationTests.java

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,23 @@
1515
*/
1616
package org.springframework.data.envers.repository.support;
1717

18+
import static org.assertj.core.api.Assertions.*;
19+
import static org.springframework.data.history.RevisionMetadata.RevisionType.*;
20+
21+
import java.time.Instant;
22+
import java.util.Arrays;
23+
import java.util.HashSet;
24+
import java.util.Iterator;
25+
import java.util.Optional;
26+
1827
import org.junit.jupiter.api.BeforeEach;
1928
import org.junit.jupiter.api.Test;
2029
import org.junit.jupiter.api.extension.ExtendWith;
30+
2131
import org.springframework.beans.factory.annotation.Autowired;
2232
import org.springframework.data.domain.Page;
2333
import org.springframework.data.domain.PageRequest;
34+
import org.springframework.data.domain.Pageable;
2435
import org.springframework.data.domain.Sort;
2536
import org.springframework.data.envers.Config;
2637
import org.springframework.data.envers.sample.Country;
@@ -33,21 +44,13 @@
3344
import org.springframework.test.context.ContextConfiguration;
3445
import org.springframework.test.context.junit.jupiter.SpringExtension;
3546

36-
import java.time.Instant;
37-
import java.util.Arrays;
38-
import java.util.HashSet;
39-
import java.util.Iterator;
40-
import java.util.Optional;
41-
42-
import static org.assertj.core.api.Assertions.*;
43-
import static org.springframework.data.history.RevisionMetadata.RevisionType.*;
44-
4547
/**
4648
* Integration tests for repositories.
4749
*
4850
* @author Oliver Gierke
4951
* @author Jens Schauder
5052
* @author Niklas Loechte
53+
* @author Mark Paluch
5154
*/
5255
@ExtendWith(SpringExtension.class)
5356
@ContextConfiguration(classes = Config.class)
@@ -107,6 +110,40 @@ void testLifeCycle() {
107110
});
108111
}
109112

113+
@Test // GH-3999
114+
void shouldReturnUnpagedResults() {
115+
116+
License license = new License();
117+
license.name = "Schnitzel";
118+
119+
licenseRepository.save(license);
120+
121+
Country de = new Country();
122+
de.code = "de";
123+
de.name = "Deutschland";
124+
125+
countryRepository.save(de);
126+
127+
Country se = new Country();
128+
se.code = "se";
129+
se.name = "Schweden";
130+
131+
countryRepository.save(se);
132+
133+
license.laender = new HashSet<>();
134+
license.laender.addAll(Arrays.asList(de, se));
135+
136+
licenseRepository.save(license);
137+
138+
de.name = "Daenemark";
139+
140+
countryRepository.save(de);
141+
142+
Page<Revision<Integer, License>> revisions = licenseRepository.findRevisions(license.id, Pageable.unpaged());
143+
144+
assertThat(revisions).hasSize(2);
145+
}
146+
110147
@Test // #1
111148
void returnsEmptyLastRevisionForUnrevisionedEntity() {
112149
assertThat(countryRepository.findLastChangeRevision(100L)).isEmpty();

0 commit comments

Comments
 (0)