Skip to content

Commit

Permalink
Merge pull request #2993 from pjeanjean/XWIKI-21922-fix-2
Browse files Browse the repository at this point in the history
XWIKI-21922: Introduce methods to fetch a subset of revisions in XWikiVersioningStoreInterface
  • Loading branch information
tmortagne authored Mar 15, 2024
2 parents a49fd13 + 02818d6 commit 965166b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,17 @@ private void applyCriteria(final long id, RevisionCriteria criteria)
}

Date minDate = criteria.getMinDate();
Date maxDate = criteria.getMaxDate();
// Hibernate requires positive timestamps.
if (minDate.getTime() < 0) {
minDate = new Date(0);
}
predicates.add(this.builder.between(this.root.get(FIELD_DATE), minDate, criteria.getMaxDate()));
// Most databases (e.g., MariaDB) store timestamps as seconds, using integers. As such we cannot go
// higher than Integer.MAX_VALUE seconds.
if (maxDate.getTime() > Integer.MAX_VALUE * 1000L) {
maxDate = new Date(Integer.MAX_VALUE * 1000L);
}
predicates.add(this.builder.between(this.root.get(FIELD_DATE), minDate, maxDate));

if (!criteria.getIncludeMinorVersions()) {
// In this case, we keep only the highest minor version for each major version.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ void testRCSNodeInfoCountQueryWithAuthorCriteria()
LiteralExpression<Date> dateUpperExpression = (LiteralExpression<Date>) datePredicate.getUpperBound();
assertEquals("mocked date", datePredicate.getExpression().toString());
assertEquals(new Date(0L), dateLowerExpression.getLiteral());
assertEquals(new Date(Long.MAX_VALUE), dateUpperExpression.getLiteral());
assertEquals(new Date(Integer.MAX_VALUE * 1000L), dateUpperExpression.getLiteral());
}

@Test
Expand Down Expand Up @@ -270,7 +270,7 @@ void testRCSNodeInfoQueryWithAuthorCriteria()
LiteralExpression<Date> dateUpperExpression = (LiteralExpression<Date>) datePredicate.getUpperBound();
assertEquals("mocked date", datePredicate.getExpression().toString());
assertEquals(new Date(0L), dateLowerExpression.getLiteral());
assertEquals(new Date(Long.MAX_VALUE), dateUpperExpression.getLiteral());
assertEquals(new Date(Integer.MAX_VALUE * 1000L), dateUpperExpression.getLiteral());
}

@Test
Expand Down

0 comments on commit 965166b

Please sign in to comment.