Skip to content

Commit 7475fd4

Browse files
committed
Polishing.
Use consistent method and argument names for newly introduced methods. Reorder and group template API methods to keep related methods together. See: #1315 Original pull request: #1324.
1 parent a3d334d commit 7475fd4

File tree

8 files changed

+210
-208
lines changed

8 files changed

+210
-208
lines changed

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateOperations.java

Lines changed: 107 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -82,95 +82,42 @@ public interface JdbcAggregateOperations {
8282
<T> T update(T instance);
8383

8484
/**
85-
* Deletes a single Aggregate including all entities contained in that aggregate.
86-
* <p>
87-
* Since no version attribute is provided this method will never throw a
88-
* {@link org.springframework.dao.OptimisticLockingFailureException}. If no rows match the generated delete operation
89-
* this fact will be silently ignored.
90-
* </p>
85+
* Counts the number of aggregates of a given type.
9186
*
92-
* @param id the id of the aggregate root of the aggregate to be deleted. Must not be {@code null}.
93-
* @param domainType the type of the aggregate root.
94-
* @param <T> the type of the aggregate root.
87+
* @param domainType the type of the aggregates to be counted.
88+
* @return the number of instances stored in the database. Guaranteed to be not {@code null}.
9589
*/
96-
<T> void deleteById(Object id, Class<T> domainType);
90+
long count(Class<?> domainType);
9791

9892
/**
99-
* Deletes all aggregates identified by their aggregate root ids.
100-
* <p>
101-
* Since no version attribute is provided this method will never throw a
102-
* {@link org.springframework.dao.OptimisticLockingFailureException}. If no rows match the generated delete operation
103-
* this fact will be silently ignored.
104-
* </p>
93+
* Counts the number of aggregates of a given type that match the given <code>query</code>.
10594
*
106-
* @param ids the ids of the aggregate roots of the aggregates to be deleted. Must not be {@code null}.
107-
* @param domainType the type of the aggregate root.
108-
* @param <T> the type of the aggregate root.
95+
* @param query must not be {@literal null}.
96+
* @param domainType the entity type must not be {@literal null}.
97+
* @return the number of instances stored in the database. Guaranteed to be not {@code null}.
98+
* @since 3.0
10999
*/
110-
<T> void deleteAllById(Iterable<?> ids, Class<T> domainType);
100+
<T> long count(Query query, Class<T> domainType);
111101

112102
/**
113-
* Delete an aggregate identified by its aggregate root.
103+
* Determine whether there are aggregates that match the {@link Query}
114104
*
115-
* @param aggregateRoot to delete. Must not be {@code null}.
116-
* @param <T> the type of the aggregate root.
105+
* @param query must not be {@literal null}.
106+
* @param domainType the entity type must not be {@literal null}.
107+
* @return {@literal true} if the object exists.
108+
* @since 3.0
117109
*/
118-
<T> void delete(T aggregateRoot);
110+
<T> boolean exists(Query query, Class<T> domainType);
119111

120112
/**
121-
* Delete an aggregate identified by its aggregate root.
113+
* Checks if an aggregate identified by type and id exists in the database.
122114
*
123-
* @param aggregateRoot to delete. Must not be {@code null}.
124-
* @param domainType the type of the aggregate root. Must not be {@code null}.
115+
* @param id the id of the aggregate root.
116+
* @param domainType the type of the aggregate root.
125117
* @param <T> the type of the aggregate root.
126-
* @throws org.springframework.dao.OptimisticLockingFailureException when {@literal T} has a version attribute and the
127-
* version attribute of the provided entity does not match the version attribute in the database, or when
128-
* there is no aggregate root with matching id. In other cases a NOOP delete is silently ignored.
129-
* @deprecated since 3.0 use {@link #delete(Object)} instead
130-
*/
131-
@Deprecated
132-
default <T> void delete(T aggregateRoot, Class<T> domainType) {
133-
delete(aggregateRoot);
134-
}
135-
136-
/**
137-
* Delete all aggregates of a given type.
138-
*
139-
* @param domainType type of the aggregate roots to be deleted. Must not be {@code null}.
140-
*/
141-
void deleteAll(Class<?> domainType);
142-
143-
/**
144-
* Delete all aggregates identified by their aggregate roots.
145-
*
146-
* @param aggregateRoots to delete. Must not be {@code null}.
147-
* @param <T> the type of the aggregate roots.
148-
*/
149-
<T> void deleteAll(Iterable<? extends T> aggregateRoots);
150-
151-
/**
152-
* Delete all aggregates identified by their aggregate roots.
153-
*
154-
* @param aggregateRoots to delete. Must not be {@code null}.
155-
* @param domainType type of the aggregate roots to be deleted. Must not be {@code null}.
156-
* @param <T> the type of the aggregate roots.
157-
* @throws org.springframework.dao.OptimisticLockingFailureException when {@literal T} has a version attribute and for at least on entity the
158-
* version attribute of the entity does not match the version attribute in the database, or when
159-
* there is no aggregate root with matching id. In other cases a NOOP delete is silently ignored.
160-
* @deprecated since 3.0 use {@link #deleteAll(Iterable)} instead.
161-
*/
162-
@Deprecated
163-
default <T> void deleteAll(Iterable<? extends T> aggregateRoots, Class<T> domainType) {
164-
deleteAll(aggregateRoots);
165-
}
166-
167-
/**
168-
* Counts the number of aggregates of a given type.
169-
*
170-
* @param domainType the type of the aggregates to be counted.
171-
* @return the number of instances stored in the database. Guaranteed to be not {@code null}.
118+
* @return whether the aggregate exists.
172119
*/
173-
long count(Class<?> domainType);
120+
<T> boolean existsById(Object id, Class<T> domainType);
174121

175122
/**
176123
* Load an aggregate from the database.
@@ -202,16 +149,6 @@ default <T> void deleteAll(Iterable<? extends T> aggregateRoots, Class<T> domain
202149
*/
203150
<T> Iterable<T> findAll(Class<T> domainType);
204151

205-
/**
206-
* Checks if an aggregate identified by type and id exists in the database.
207-
*
208-
* @param id the id of the aggregate root.
209-
* @param domainType the type of the aggregate root.
210-
* @param <T> the type of the aggregate root.
211-
* @return whether the aggregate exists.
212-
*/
213-
<T> boolean existsById(Object id, Class<T> domainType);
214-
215152
/**
216153
* Load all aggregates of a given type, sorted.
217154
*
@@ -238,53 +175,117 @@ default <T> void deleteAll(Iterable<? extends T> aggregateRoots, Class<T> domain
238175
* Execute a {@code SELECT} query and convert the resulting item to an entity ensuring exactly one result.
239176
*
240177
* @param query must not be {@literal null}.
241-
* @param entityClass the entity type must not be {@literal null}.
178+
* @param domainType the entity type must not be {@literal null}.
242179
* @return exactly one result or {@link Optional#empty()} if no match found.
243180
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException if more than one match found.
244181
* @since 3.0
245182
*/
246-
<T> Optional<T> selectOne(Query query, Class<T> entityClass);
183+
<T> Optional<T> findOne(Query query, Class<T> domainType);
247184

248185
/**
249186
* Execute a {@code SELECT} query and convert the resulting items to a {@link Iterable} that is sorted.
250187
*
251188
* @param query must not be {@literal null}.
252-
* @param entityClass the entity type must not be {@literal null}.
189+
* @param domainType the entity type must not be {@literal null}.
253190
* @return a non-null sorted list with all the matching results.
254191
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException if more than one match found.
255192
* @since 3.0
256193
*/
257-
<T> Iterable<T> select(Query query, Class<T> entityClass);
194+
<T> Iterable<T> findAll(Query query, Class<T> domainType);
258195

259196
/**
260-
* Determine whether there are aggregates that match the {@link Query}
197+
* Returns a {@link Page} of entities matching the given {@link Query}. In case no match could be found, an empty
198+
* {@link Page} is returned.
261199
*
262200
* @param query must not be {@literal null}.
263-
* @param entityClass the entity type must not be {@literal null}.
264-
* @return {@literal true} if the object exists.
201+
* @param domainType the entity type must not be {@literal null}.
202+
* @param pageable can be null.
203+
* @return a {@link Page} of entities matching the given {@link Example}.
265204
* @since 3.0
266205
*/
267-
<T> boolean exists(Query query, Class<T> entityClass);
206+
<T> Page<T> findAll(Query query, Class<T> domainType, Pageable pageable);
268207

269208
/**
270-
* Counts the number of aggregates of a given type that match the given <code>query</code>.
209+
* Deletes a single Aggregate including all entities contained in that aggregate.
210+
* <p>
211+
* Since no version attribute is provided this method will never throw a
212+
* {@link org.springframework.dao.OptimisticLockingFailureException}. If no rows match the generated delete operation
213+
* this fact will be silently ignored.
214+
* </p>
271215
*
272-
* @param query must not be {@literal null}.
273-
* @param entityClass the entity type must not be {@literal null}.
274-
* @return the number of instances stored in the database. Guaranteed to be not {@code null}.
275-
* @since 3.0
216+
* @param id the id of the aggregate root of the aggregate to be deleted. Must not be {@code null}.
217+
* @param domainType the type of the aggregate root.
218+
* @param <T> the type of the aggregate root.
276219
*/
277-
<T> long count(Query query, Class<T> entityClass);
220+
<T> void deleteById(Object id, Class<T> domainType);
278221

279222
/**
280-
* Returns a {@link Page} of entities matching the given {@link Query}. In case no match could be found, an empty
281-
* {@link Page} is returned.
223+
* Deletes all aggregates identified by their aggregate root ids.
224+
* <p>
225+
* Since no version attribute is provided this method will never throw a
226+
* {@link org.springframework.dao.OptimisticLockingFailureException}. If no rows match the generated delete operation
227+
* this fact will be silently ignored.
228+
* </p>
282229
*
283-
* @param query must not be {@literal null}.
284-
* @param entityClass the entity type must not be {@literal null}.
285-
* @param pageable can be null.
286-
* @return a {@link Page} of entities matching the given {@link Example}.
287-
* @since 3.0
230+
* @param ids the ids of the aggregate roots of the aggregates to be deleted. Must not be {@code null}.
231+
* @param domainType the type of the aggregate root.
232+
* @param <T> the type of the aggregate root.
288233
*/
289-
<T> Page<T> select(Query query, Class<T> entityClass, Pageable pageable);
234+
<T> void deleteAllById(Iterable<?> ids, Class<T> domainType);
235+
236+
/**
237+
* Delete an aggregate identified by its aggregate root.
238+
*
239+
* @param aggregateRoot to delete. Must not be {@code null}.
240+
* @param <T> the type of the aggregate root.
241+
*/
242+
<T> void delete(T aggregateRoot);
243+
244+
/**
245+
* Delete an aggregate identified by its aggregate root.
246+
*
247+
* @param aggregateRoot to delete. Must not be {@code null}.
248+
* @param domainType the type of the aggregate root. Must not be {@code null}.
249+
* @param <T> the type of the aggregate root.
250+
* @throws org.springframework.dao.OptimisticLockingFailureException when {@literal T} has a version attribute and the
251+
* version attribute of the provided entity does not match the version attribute in the database, or when
252+
* there is no aggregate root with matching id. In other cases a NOOP delete is silently ignored.
253+
* @deprecated since 3.0 use {@link #delete(Object)} instead
254+
*/
255+
@Deprecated(since = "3.0")
256+
default <T> void delete(T aggregateRoot, Class<T> domainType) {
257+
delete(aggregateRoot);
258+
}
259+
260+
/**
261+
* Delete all aggregates of a given type.
262+
*
263+
* @param domainType type of the aggregate roots to be deleted. Must not be {@code null}.
264+
*/
265+
void deleteAll(Class<?> domainType);
266+
267+
/**
268+
* Delete all aggregates identified by their aggregate roots.
269+
*
270+
* @param aggregateRoots to delete. Must not be {@code null}.
271+
* @param <T> the type of the aggregate roots.
272+
*/
273+
<T> void deleteAll(Iterable<? extends T> aggregateRoots);
274+
275+
/**
276+
* Delete all aggregates identified by their aggregate roots.
277+
*
278+
* @param aggregateRoots to delete. Must not be {@code null}.
279+
* @param domainType type of the aggregate roots to be deleted. Must not be {@code null}.
280+
* @param <T> the type of the aggregate roots.
281+
* @throws org.springframework.dao.OptimisticLockingFailureException when {@literal T} has a version attribute and for
282+
* at least on entity the version attribute of the entity does not match the version attribute in the
283+
* database, or when there is no aggregate root with matching id. In other cases a NOOP delete is silently
284+
* ignored.
285+
* @deprecated since 3.0 use {@link #deleteAll(Iterable)} instead.
286+
*/
287+
@Deprecated(since = "3.0")
288+
default <T> void deleteAll(Iterable<? extends T> aggregateRoots, Class<T> domainType) {
289+
deleteAll(aggregateRoots);
290+
}
290291
}

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateTemplate.java

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -214,25 +214,35 @@ public long count(Class<?> domainType) {
214214
}
215215

216216
@Override
217-
public <T> T findById(Object id, Class<T> domainType) {
217+
public <T> long count(Query query, Class<T> domainType) {
218+
return accessStrategy.count(query, domainType);
219+
}
220+
221+
@Override
222+
public <T> boolean exists(Query query, Class<T> domainType) {
223+
return accessStrategy.exists(query, domainType);
224+
}
225+
226+
@Override
227+
public <T> boolean existsById(Object id, Class<T> domainType) {
218228

219229
Assert.notNull(id, "Id must not be null");
220230
Assert.notNull(domainType, "Domain type must not be null");
221231

222-
T entity = accessStrategy.findById(id, domainType);
223-
if (entity == null) {
224-
return null;
225-
}
226-
return triggerAfterConvert(entity);
232+
return accessStrategy.existsById(id, domainType);
227233
}
228234

229235
@Override
230-
public <T> boolean existsById(Object id, Class<T> domainType) {
236+
public <T> T findById(Object id, Class<T> domainType) {
231237

232238
Assert.notNull(id, "Id must not be null");
233239
Assert.notNull(domainType, "Domain type must not be null");
234240

235-
return accessStrategy.existsById(id, domainType);
241+
T entity = accessStrategy.findById(id, domainType);
242+
if (entity == null) {
243+
return null;
244+
}
245+
return triggerAfterConvert(entity);
236246
}
237247

238248
@Override
@@ -256,32 +266,22 @@ public <T> Page<T> findAll(Class<T> domainType, Pageable pageable) {
256266
}
257267

258268
@Override
259-
public <T> Optional<T> selectOne(Query query, Class<T> entityClass) {
260-
return accessStrategy.selectOne(query, entityClass);
269+
public <T> Optional<T> findOne(Query query, Class<T> domainType) {
270+
return accessStrategy.findOne(query, domainType);
261271
}
262272

263273
@Override
264-
public <T> Iterable<T> select(Query query, Class<T> entityClass) {
265-
return accessStrategy.select(query, entityClass);
274+
public <T> Iterable<T> findAll(Query query, Class<T> domainType) {
275+
return accessStrategy.findAll(query, domainType);
266276
}
267277

268278
@Override
269-
public <T> boolean exists(Query query, Class<T> entityClass) {
270-
return accessStrategy.exists(query, entityClass);
271-
}
272-
273-
@Override
274-
public <T> long count(Query query, Class<T> entityClass) {
275-
return accessStrategy.count(query, entityClass);
276-
}
279+
public <T> Page<T> findAll(Query query, Class<T> domainType, Pageable pageable) {
277280

278-
@Override
279-
public <T> Page<T> select(Query query, Class<T> entityClass, Pageable pageable) {
280-
281-
Iterable<T> items = triggerAfterConvert(accessStrategy.select(query, entityClass, pageable));
281+
Iterable<T> items = triggerAfterConvert(accessStrategy.findAll(query, domainType, pageable));
282282
List<T> content = StreamSupport.stream(items.spliterator(), false).collect(Collectors.toList());
283283

284-
return PageableExecutionUtils.getPage(content, pageable, () -> accessStrategy.count(query, entityClass));
284+
return PageableExecutionUtils.getPage(content, pageable, () -> accessStrategy.count(query, domainType));
285285
}
286286

287287
@Override
@@ -373,7 +373,6 @@ public <T> void deleteAll(Iterable<? extends T> instances) {
373373

374374
private <T> void doDeleteAll(Iterable<? extends T> instances, Class<T> domainType) {
375375

376-
377376
BatchingAggregateChange<T, DeleteAggregateChange<T>> batchingAggregateChange = BatchingAggregateChange
378377
.forDelete(domainType);
379378
Map<Object, T> instancesBeforeExecute = new LinkedHashMap<>();

0 commit comments

Comments
 (0)