Skip to content

Commit c9801dc

Browse files
Added support for negative length
1 parent 88446cd commit c9801dc

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

src/main/java/org/springframework/data/jpa/datatables/mapping/DataTablesInput.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class DataTablesInput {
3939
* negates any benefits of server-side processing!)
4040
*/
4141
@NotNull
42-
@Min(0)
42+
@Min(-1)
4343
private Integer length;
4444

4545
/**

src/main/java/org/springframework/data/jpa/datatables/repository/DataTablesRepositoryImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ private Pageable getPageable(DataTablesInput input) {
8585
}
8686
Sort sort = orders.isEmpty() ? null : new Sort(orders);
8787

88+
if (input.getLength() == -1) {
89+
input.setStart(0);
90+
input.setLength(Integer.MAX_VALUE);
91+
}
8892
return new PageRequest(input.getStart() / input.getLength(),
8993
input.getLength(), sort);
9094
}

src/test/java/org/springframework/data/jpa/datatables/repository/UserRepositoryTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,30 @@ public void testWithAdditionalSpecification() {
266266

267267
}
268268

269+
@Test
270+
public void testWithZeroLength() {
271+
DataTablesInput input = getBasicInput();
272+
273+
input.setLength(0);
274+
DataTablesOutput<User> output = userRepository.findAll(input);
275+
assertNotNull(output);
276+
assertNotNull(output.getError());
277+
assertEquals(output.getError(),
278+
"java.lang.ArithmeticException: / by zero");
279+
}
280+
281+
@Test
282+
public void testWithNegativeLength() {
283+
DataTablesInput input = getBasicInput();
284+
285+
input.setLength(-1);
286+
DataTablesOutput<User> output = userRepository.findAll(input);
287+
assertNotNull(output);
288+
assertNull(output.getError());
289+
assertEquals(24, (long) output.getRecordsFiltered());
290+
assertEquals(24, (long) output.getRecordsTotal());
291+
}
292+
269293
/**
270294
*
271295
* @return basic input parameters

0 commit comments

Comments
 (0)