Skip to content

Commit

Permalink
Merge pull request #566 from jakartaee/remove-in-methods
Browse files Browse the repository at this point in the history
Remove methods at BasicRepository
  • Loading branch information
otaviojava authored Mar 20, 2024
2 parents 23fef77 + d32e3d7 commit 74b0754
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 98 deletions.
33 changes: 0 additions & 33 deletions api/src/main/java/jakarta/data/repository/BasicRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,6 @@ public interface BasicRepository<T, K> extends DataRepository<T, K> {
@Find
Optional<T> findById(@By(ID) K id);

/**
* Returns whether an entity with the given Id exists.
*
* @param id must not be {@code null}.
* @return {@code true} if an entity with the given Id exists, {@code false} otherwise.
* @throws NullPointerException when the Id is {@code null}.
*/
boolean existsById(K id);

/**
* Retrieves all persistent entities of the specified type from the database.
*
Expand All @@ -178,20 +169,6 @@ public interface BasicRepository<T, K> extends DataRepository<T, K> {
@Find
Page<T> findAll(PageRequest<T> pageRequest);

/**
* Returns all instances of the type {@code T} with the given Ids.
* <p>
* If some or all Ids are not found, no entities are returned for these Ids.
* <p>
* Note that the order of elements in the result is not guaranteed.
*
* @param ids must not be {@code null} nor contain any {@code null} values.
* @return guaranteed to be not {@code null}. The size can be equal or less than the number of given
* ids.
* @throws NullPointerException in case the given {@link Iterable ids} or one of its items is {@code null}.
*/
Stream<T> findByIdIn(Iterable<K> ids);

/**
* Deletes the entity with the given Id.
* <p>
Expand All @@ -216,16 +193,6 @@ public interface BasicRepository<T, K> extends DataRepository<T, K> {
@Delete
void delete(T entity);

/**
* Deletes all instances of the type {@code T} with the given Ids.
* <p>
* Entities that are not found in the persistent store are silently ignored.
*
* @param ids must not be {@code null}. Must not contain {@code null} elements.
* @throws NullPointerException when the iterable is {@code null} or contains {@code null} elements.
*/
void deleteByIdIn(Iterable<K> ids);

/**
* Deletes the given entities. Deletion of each entity is performed by matching the unique identifier,
* and if the entity is versioned (for example, with {@code jakarta.persistence.Version}), then also
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,9 @@ public void ensureCharacterPrepopulation() {
strategy = "Use a repository that inherits from BasicRepository and adds some methods of its own. " +
"Use both built-in methods and the additional methods.")
public void testBasicRepository() {
assertEquals(false, numbers.existsById(0L));
assertEquals(true, numbers.existsById(80L));

Stream<NaturalNumber> found;
found = numbers.findByIdIn(List.of(70L, 40L, -20L, 10L));
assertEquals(List.of(10L, 40L, 70L),
found.map(NaturalNumber::getId).sorted().collect(Collectors.toList()));

found = numbers.findByIdBetween(50L, 59L, Sort.asc("numType"));
Stream<NaturalNumber> found = numbers.findByIdBetween(50L, 59L, Sort.asc("numType"));
List<Long> list = found.map(NaturalNumber::getId).collect(Collectors.toList());
assertEquals(Set.of(53L, 59L), // first 2 must be primes
new TreeSet<>(list.subList(0, 2)));
Expand All @@ -146,14 +140,6 @@ public void testBasicRepository() {
strategy = "Use a repository that inherits from BasicRepository and defines no additional methods of its own. " +
"Use all of the built-in methods.")
public void testBasicRepositoryBuiltInMethods() {
boxes.deleteByIdIn(List.of(
"TestBasicRepositoryMethods-01",
"TestBasicRepositoryMethods-02",
"TestBasicRepositoryMethods-03",
"TestBasicRepositoryMethods-04",
"TestBasicRepositoryMethods-05"));

TestPropertyUtility.waitForEventualConsistency();

// BasicRepository.saveAll
Iterable<Box> saved = boxes.saveAll(List.of(Box.of("TestBasicRepositoryMethods-01", 119, 120, 169),
Expand Down Expand Up @@ -189,8 +175,6 @@ public void testBasicRepositoryBuiltInMethods() {

TestPropertyUtility.waitForEventualConsistency();

// BasicRepository.existsById
assertEquals(true, boxes.existsById("TestBasicRepositoryMethods-04"));

// BasicRepository.save
box2.length = 21;
Expand All @@ -214,32 +198,17 @@ public void testBasicRepositoryBuiltInMethods() {

TestPropertyUtility.waitForEventualConsistency();

assertEquals(false, boxes.existsById("TestBasicRepositoryMethods-01"));
assertEquals(3, boxes.findAll().count());

// BasicRepository.findByIdIn
Stream<Box> stream = boxes.findByIdIn(List.of("TestBasicRepositoryMethods-04", "TestBasicRepositoryMethods-05"));
List<Box> list = stream.sorted(Comparator.comparing(b -> b.boxIdentifier)).collect(Collectors.toList());
assertEquals(2, list.size());
box4 = list.get(0);
assertEquals("TestBasicRepositoryMethods-04", box4.boxIdentifier);
assertEquals(45, box4.length);
assertEquals(28, box4.width);
assertEquals(53, box4.height);
box5 = list.get(1);
assertEquals("TestBasicRepositoryMethods-05", box5.boxIdentifier);
assertEquals(153, box5.length);
assertEquals(104, box5.width);
assertEquals(185, box5.height);

// BasicRepository.delete
boxes.delete(box4);

TestPropertyUtility.waitForEventualConsistency();

// BasicRepository.findAll
stream = boxes.findAll();
list = stream.sorted(Comparator.comparing(b -> b.boxIdentifier)).collect(Collectors.toList());
Stream<Box> stream = boxes.findAll();
List<Box> list = stream.sorted(Comparator.comparing(b -> b.boxIdentifier)).collect(Collectors.toList());
assertEquals(2, list.size());
box4 = list.get(0);
assertEquals("TestBasicRepositoryMethods-03", box3.boxIdentifier);
Expand All @@ -265,23 +234,15 @@ public void testBasicRepositoryBuiltInMethods() {
assertEquals(104, box5.width);
assertEquals(185, box5.height);

// BasicRepository.deleteByIdIn
boxes.deleteByIdIn(List.of("TestBasicRepositoryMethods-05"));
// BasicRepository.deleteById
boxes.deleteById("TestBasicRepositoryMethods-05");
TestPropertyUtility.waitForEventualConsistency();

assertEquals(0, boxes.findAll().count());
}

@Assertion(id = "133", strategy = "Use a repository that inherits from BasicRepository and defines no additional methods of its own. Use all of the built-in methods.")
public void testBasicRepositoryMethods() {
boxes.deleteByIdIn(List.of(
"TestBasicRepositoryMethods-01",
"TestBasicRepositoryMethods-02",
"TestBasicRepositoryMethods-03",
"TestBasicRepositoryMethods-04",
"TestBasicRepositoryMethods-05"));

TestPropertyUtility.waitForEventualConsistency();

// BasicRepository.saveAll
Iterable<Box> saved = boxes.saveAll(List.of(Box.of("TestBasicRepositoryMethods-01", 119, 120, 169),
Expand Down Expand Up @@ -317,8 +278,6 @@ public void testBasicRepositoryMethods() {

TestPropertyUtility.waitForEventualConsistency();

// BasicRepository.existsById
assertEquals(true, boxes.existsById("TestBasicRepositoryMethods-04"));

// BasicRepository.save
box2.length = 21;
Expand All @@ -342,32 +301,17 @@ public void testBasicRepositoryMethods() {

TestPropertyUtility.waitForEventualConsistency();

assertEquals(false, boxes.existsById("TestBasicRepositoryMethods-01"));
assertEquals(3, boxes.findAll().count());

// BasicRepository.findByIdIn
Stream<Box> stream = boxes.findByIdIn(List.of("TestBasicRepositoryMethods-04", "TestBasicRepositoryMethods-05"));
List<Box> list = stream.sorted(Comparator.comparing(b -> b.boxIdentifier)).collect(Collectors.toList());
assertEquals(2, list.size());
box4 = list.get(0);
assertEquals("TestBasicRepositoryMethods-04", box4.boxIdentifier);
assertEquals(45, box4.length);
assertEquals(28, box4.width);
assertEquals(53, box4.height);
box5 = list.get(1);
assertEquals("TestBasicRepositoryMethods-05", box5.boxIdentifier);
assertEquals(153, box5.length);
assertEquals(104, box5.width);
assertEquals(185, box5.height);

// BasicRepository.delete
boxes.delete(box4);

TestPropertyUtility.waitForEventualConsistency();

// BasicRepository.findAll
stream = boxes.findAll();
list = stream.sorted(Comparator.comparing(b -> b.boxIdentifier)).collect(Collectors.toList());
Stream<Box> stream = boxes.findAll();
List<Box> list = stream.sorted(Comparator.comparing(b -> b.boxIdentifier)).collect(Collectors.toList());
assertEquals(2, list.size());
box4 = list.get(0);
assertEquals("TestBasicRepositoryMethods-03", box3.boxIdentifier);
Expand All @@ -393,8 +337,8 @@ public void testBasicRepositoryMethods() {
assertEquals(104, box5.width);
assertEquals(185, box5.height);

// BasicRepository.deleteByIdIn
boxes.deleteByIdIn(List.of("TestBasicRepositoryMethods-05"));
// BasicRepository.deleteById
boxes.deleteById("TestBasicRepositoryMethods-05");

TestPropertyUtility.waitForEventualConsistency();

Expand Down

0 comments on commit 74b0754

Please sign in to comment.