Skip to content

Commit eb023fc

Browse files
committed
Polishing.
Adding and correcting `@since` annotations. Cleaning up some JavaDoc. Tweaking some tests to make them more precise. Original pull request #2148
1 parent ed6e8ff commit eb023fc

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

src/main/java/org/springframework/data/jpa/repository/JpaRepository.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,17 @@ public interface JpaRepository<T, ID> extends PagingAndSortingRepository<T, ID>,
7272
/**
7373
* Saves an entity and flushes changes instantly.
7474
*
75-
* @param entity
75+
* @param entity entity to be saved. Must not be {@literal null}.
7676
* @return the saved entity
7777
*/
7878
<S extends T> S saveAndFlush(S entity);
7979

8080
/**
8181
* Saves all entities and flushes changes instantly.
8282
*
83-
* @param entities
83+
* @param entities entities to be deleted. Must not be {@literal null}.
8484
* @return the saved entities
85+
* @since 2.5
8586
*/
8687
<S extends T> List<S> saveAllAndFlush(Iterable<S> entities);
8788

@@ -90,7 +91,7 @@ public interface JpaRepository<T, ID> extends PagingAndSortingRepository<T, ID>,
9091
* first level cache and the database out of sync. Consider flushing the {@link EntityManager} before calling this
9192
* method.
9293
*
93-
* @param entities
94+
* @param entities entities to be deleted. Must not be {@literal null}.
9495
* @deprecated Use {@link #deleteAllInBatch(Iterable)} instead.
9596
*/
9697
@Deprecated
@@ -101,8 +102,8 @@ public interface JpaRepository<T, ID> extends PagingAndSortingRepository<T, ID>,
101102
* first level cache and the database out of sync. Consider flushing the {@link EntityManager} before calling this
102103
* method.
103104
*
104-
* @param entities
105-
* @since 3.0
105+
* @param entities entities to be deleted. Must not be {@literal null}.
106+
* @since 2.5
106107
*/
107108
void deleteAllInBatch(Iterable<T> entities);
108109

@@ -111,8 +112,8 @@ public interface JpaRepository<T, ID> extends PagingAndSortingRepository<T, ID>,
111112
* Deletes the entities identified by the given ids using a single query. This kind of operation leaves JPAs first
112113
* level cache and the database out of sync. Consider flushing the {@link EntityManager} before calling this method.
113114
*
114-
* @param ids
115-
* @since 3.0
115+
* @param ids the ids of the entities to be deleted. Must not be {@literal null}.
116+
* @since 2.5
116117
*/
117118
void deleteAllByIdInBatch(Iterable<ID> ids);
118119

src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java

+11-12
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import org.junit.jupiter.api.Disabled;
4747
import org.junit.jupiter.api.Test;
4848
import org.junit.jupiter.api.extension.ExtendWith;
49-
5049
import org.springframework.beans.factory.annotation.Autowired;
5150
import org.springframework.dao.DataAccessException;
5251
import org.springframework.dao.DataIntegrityViolationException;
@@ -60,16 +59,16 @@
6059
import org.springframework.data.domain.Pageable;
6160
import org.springframework.data.domain.Slice;
6261
import org.springframework.data.domain.Sort;
62+
import org.springframework.data.domain.ExampleMatcher.*;
6363
import org.springframework.data.domain.Sort.Direction;
6464
import org.springframework.data.domain.Sort.Order;
65-
import org.springframework.data.domain.ExampleMatcher.*;
6665
import org.springframework.data.jpa.domain.Specification;
6766
import org.springframework.data.jpa.domain.sample.Address;
6867
import org.springframework.data.jpa.domain.sample.Role;
6968
import org.springframework.data.jpa.domain.sample.SpecialUser;
7069
import org.springframework.data.jpa.domain.sample.User;
71-
import org.springframework.data.jpa.repository.sample.SampleEvaluationContextExtension.SampleSecurityContextHolder;
7270
import org.springframework.data.jpa.repository.sample.UserRepository;
71+
import org.springframework.data.jpa.repository.sample.SampleEvaluationContextExtension.SampleSecurityContextHolder;
7372
import org.springframework.data.jpa.repository.sample.UserRepository.NameOnly;
7473
import org.springframework.test.context.ContextConfiguration;
7574
import org.springframework.test.context.junit.jupiter.SpringExtension;
@@ -152,8 +151,8 @@ void findsAllByGivenIds() {
152151

153152
flushTestUsers();
154153

155-
assertThat(repository.findAllById(asList(firstUser.getId(), secondUser.getId()))).contains(firstUser,
156-
secondUser);
154+
assertThat(repository.findAllById(asList(firstUser.getId(), secondUser.getId()))) //
155+
.containsExactlyInAnyOrder(firstUser, secondUser);
157156
}
158157

159158
@Test
@@ -167,23 +166,23 @@ void testReadByIdReturnsNullForNotFoundEntities() {
167166
@Test
168167
void savesCollectionCorrectly() throws Exception {
169168

170-
assertThat(repository.saveAll(asList(firstUser, secondUser, thirdUser))).hasSize(3).contains(firstUser,
171-
secondUser, thirdUser);
169+
assertThat(repository.saveAll(asList(firstUser, secondUser, thirdUser))) //
170+
.containsExactlyInAnyOrder(firstUser, secondUser, thirdUser);
172171
}
173172

174-
@Test // DATAJPA-1574
173+
@Test // gh-2148
175174
void savesAndFlushesCollectionCorrectly() {
176175

177-
assertThat(repository.saveAllAndFlush(asList(firstUser, secondUser, thirdUser))).hasSize(3).contains(firstUser,
178-
secondUser, thirdUser);
176+
assertThat(repository.saveAllAndFlush(asList(firstUser, secondUser, thirdUser))) //
177+
.containsExactlyInAnyOrder(firstUser, secondUser, thirdUser);
179178
}
180179

181180
@Test
182181
void savingEmptyCollectionIsNoOp() throws Exception {
183182
assertThat(repository.saveAll(new ArrayList<>())).isEmpty();
184183
}
185184

186-
@Test // DATAJPA-1574
185+
@Test // gh-2148
187186
void savingAndFlushingEmptyCollectionIsNoOp() {
188187
assertThat(repository.saveAllAndFlush(new ArrayList<>())).isEmpty();
189188
}
@@ -1114,7 +1113,7 @@ void saveAndFlushShouldSupportReturningSubTypesOfRepositoryEntity() {
11141113
assertThat(user.getEmailAddress()).isEqualTo(savedUser.getEmailAddress());
11151114
}
11161115

1117-
@Test // DATAJPA-1574
1116+
@Test // gh-2148
11181117
void saveAllAndFlushShouldSupportReturningSubTypesOfRepositoryEntity() {
11191118

11201119
repository.deleteAll();

0 commit comments

Comments
 (0)