Add paginated active lamp retrieval to repository#417
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request adds paginated active lamp retrieval capabilities to the repository layer and updates the service to use an efficient pageSize+1 pagination pattern for determining hasMore without requiring separate count queries.
Changes:
- Added paginated
findAllActive(Pageable)methods to repository interfaces and all implementations (JPA, in-memory, adapter) - Updated
LampService.findAllActivePage()to use the new paginated query method with pageSize+1 pattern for efficient hasMore detection - Added comprehensive unit and integration tests covering pagination behavior, ordering, soft-delete filtering, and edge cases
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/java/src/main/java/org/openapitools/repository/LampRepository.java | Added paginated findAllActive(Pageable) method signature with documentation |
| src/java/src/main/java/org/openapitools/repository/JpaLampRepository.java | Implemented paginated findAllActive with JPQL query ordering by createdAt and id |
| src/java/src/main/java/org/openapitools/repository/impl/InMemoryLampRepository.java | Implemented paginated findAllActive with in-memory sorting and windowing |
| src/java/src/main/java/org/openapitools/config/RepositoryConfig.java | Added adapter method to forward paginated findAllActive calls to JPA repository |
| src/java/src/main/java/org/openapitools/service/LampService.java | Refactored pagination to use pageSize+1 pattern with new repository method |
| src/java/src/test/java/org/openapitools/service/LampServiceTest.java | Updated unit tests to verify pageSize+1 behavior and hasMore calculation |
| src/java/src/test/java/org/openapitools/repository/LampRepositoryTest.java | Added tests for paginated active lamp retrieval with ordering verification |
| src/java/src/test/java/org/openapitools/integration/JpaLampRepositoryIntegrationTest.java | Added integration test for paginated active lamp window with soft-delete filtering |
| @@ -48,6 +49,18 @@ public interface JpaLampRepository extends JpaRepository<LampEntity, UUID> { | |||
| @Query("SELECT l FROM LampEntity l WHERE l.deletedAt IS NULL ORDER BY l.createdAt ASC") | |||
There was a problem hiding this comment.
The non-paginated findAllActive() method only orders by createdAt, while the paginated version (line 61) orders by createdAt and id. This inconsistency could cause different ordering when lamps have the same createdAt timestamp. For deterministic and consistent results, consider updating this query to also include id as a secondary sort: ORDER BY l.createdAt ASC, l.id ASC
| @Query("SELECT l FROM LampEntity l WHERE l.deletedAt IS NULL ORDER BY l.createdAt ASC") | |
| @Query( | |
| "SELECT l FROM LampEntity l WHERE l.deletedAt IS NULL ORDER BY l.createdAt ASC, l.id ASC") |
| .sorted(Comparator.comparing(LampEntity::getCreatedAt)) | ||
| .toList(); |
There was a problem hiding this comment.
The non-paginated findAllActive() method only orders by createdAt, while the paginated version orders by createdAt and id. This inconsistency could cause different ordering when lamps have the same createdAt timestamp. For deterministic and consistent results, consider updating this sort to also include id as a secondary comparator: .sorted(Comparator.comparing(LampEntity::getCreatedAt).thenComparing(LampEntity::getId))
Summary
Testing