|
54 | 54 | import org.springframework.data.jpa.repository.support.QueryHints.NoHints;
|
55 | 55 | import org.springframework.data.repository.support.PageableExecutionUtils;
|
56 | 56 | import org.springframework.data.util.ProxyUtils;
|
| 57 | +import org.springframework.data.util.Streamable; |
57 | 58 | import org.springframework.lang.Nullable;
|
58 | 59 | import org.springframework.stereotype.Repository;
|
59 | 60 | import org.springframework.transaction.annotation.Transactional;
|
@@ -88,19 +89,6 @@ public class SimpleJpaRepository<T, ID> implements JpaRepositoryImplementation<T
|
88 | 89 | private @Nullable CrudMethodMetadata metadata;
|
89 | 90 | private EscapeCharacter escapeCharacter = EscapeCharacter.DEFAULT;
|
90 | 91 |
|
91 |
| - private static <T> Collection<T> toCollection(Iterable<T> ts) { |
92 |
| - |
93 |
| - if (ts instanceof Collection) { |
94 |
| - return (Collection<T>) ts; |
95 |
| - } |
96 |
| - |
97 |
| - List<T> tCollection = new ArrayList<T>(); |
98 |
| - for (T t : ts) { |
99 |
| - tCollection.add(t); |
100 |
| - } |
101 |
| - return tCollection; |
102 |
| - } |
103 |
| - |
104 | 92 | /**
|
105 | 93 | * Creates a new {@link SimpleJpaRepository} to manage objects of the given {@link JpaEntityInformation}.
|
106 | 94 | *
|
@@ -205,63 +193,71 @@ public void delete(T entity) {
|
205 | 193 |
|
206 | 194 | /*
|
207 | 195 | * (non-Javadoc)
|
208 |
| - * @see org.springframework.data.repository.CrudRepository#delete(java.lang.Iterable) |
| 196 | + * @see org.springframework.data.repository.CrudRepository#deleteAllById(java.lang.Iterable) |
209 | 197 | */
|
210 |
| - @Transactional |
211 | 198 | @Override
|
212 |
| - public void deleteAll(Iterable<? extends T> entities) { |
| 199 | + public void deleteAllById(Iterable<? extends ID> ids) { |
213 | 200 |
|
214 |
| - Assert.notNull(entities, "Entities must not be null!"); |
| 201 | + Assert.notNull(ids, "Ids must not be null!"); |
215 | 202 |
|
216 |
| - for (T entity : entities) { |
217 |
| - delete(entity); |
| 203 | + for (ID id : ids) { |
| 204 | + deleteById(id); |
218 | 205 | }
|
219 | 206 | }
|
220 | 207 |
|
| 208 | + /* |
| 209 | + * (non-Javadoc) |
| 210 | + * @see org.springframework.data.repository.CrudRepository#deleteAllByIdInBatch(java.lang.Iterable) |
| 211 | + */ |
221 | 212 | @Override
|
222 |
| - public void deleteAllById(Iterable<? extends ID> ids) { |
| 213 | + public void deleteAllByIdInBatch(Iterable<ID> ids) { |
223 | 214 |
|
224 | 215 | Assert.notNull(ids, "Ids must not be null!");
|
225 | 216 |
|
226 |
| - for (ID id : ids) { |
227 |
| - deleteById(id); |
| 217 | + if (!ids.iterator().hasNext()) { |
| 218 | + return; |
228 | 219 | }
|
| 220 | + |
| 221 | + String queryString = String.format(DELETE_ALL_QUERY_BY_ID_STRING, entityInformation.getEntityName(), |
| 222 | + entityInformation.getIdAttribute().getName()); |
| 223 | + |
| 224 | + Query query = em.createQuery(queryString); |
| 225 | + query.setParameter("ids", ids); |
| 226 | + |
| 227 | + query.executeUpdate(); |
229 | 228 | }
|
230 | 229 |
|
231 | 230 | /*
|
232 | 231 | * (non-Javadoc)
|
233 |
| - * @see org.springframework.data.jpa.repository.JpaRepository#deleteInBatch(java.lang.Iterable) |
| 232 | + * @see org.springframework.data.repository.CrudRepository#delete(java.lang.Iterable) |
234 | 233 | */
|
235 | 234 | @Transactional
|
236 | 235 | @Override
|
237 |
| - public void deleteAllInBatch(Iterable<T> entities) { |
| 236 | + public void deleteAll(Iterable<? extends T> entities) { |
238 | 237 |
|
239 | 238 | Assert.notNull(entities, "Entities must not be null!");
|
240 | 239 |
|
241 |
| - if (!entities.iterator().hasNext()) { |
242 |
| - return; |
| 240 | + for (T entity : entities) { |
| 241 | + delete(entity); |
243 | 242 | }
|
244 |
| - |
245 |
| - applyAndBind(getQueryString(DELETE_ALL_QUERY_STRING, entityInformation.getEntityName()), entities, em) |
246 |
| - .executeUpdate(); |
247 | 243 | }
|
248 | 244 |
|
| 245 | + /* |
| 246 | + * (non-Javadoc) |
| 247 | + * @see org.springframework.data.jpa.repository.JpaRepository#deleteInBatch(java.lang.Iterable) |
| 248 | + */ |
| 249 | + @Transactional |
249 | 250 | @Override
|
250 |
| - public void deleteAllByIdInBatch(Iterable<ID> ids) { |
| 251 | + public void deleteAllInBatch(Iterable<T> entities) { |
251 | 252 |
|
252 |
| - Assert.notNull(ids, "Ids must not be null!"); |
| 253 | + Assert.notNull(entities, "Entities must not be null!"); |
253 | 254 |
|
254 |
| - if (!ids.iterator().hasNext()) { |
| 255 | + if (!entities.iterator().hasNext()) { |
255 | 256 | return;
|
256 | 257 | }
|
257 | 258 |
|
258 |
| - String queryTemplate = DELETE_ALL_QUERY_BY_ID_STRING; |
259 |
| - String queryString = String.format(queryTemplate, entityInformation.getEntityName(), entityInformation.getIdAttribute().getName()); |
260 |
| - |
261 |
| - Query query = em.createQuery(queryString); |
262 |
| - query.setParameter("ids", ids); |
263 |
| - |
264 |
| - query.executeUpdate(); |
| 259 | + applyAndBind(getQueryString(DELETE_ALL_QUERY_STRING, entityInformation.getEntityName()), entities, em) |
| 260 | + .executeUpdate(); |
265 | 261 | }
|
266 | 262 |
|
267 | 263 | /*
|
@@ -408,7 +404,7 @@ public List<T> findAllById(Iterable<ID> ids) {
|
408 | 404 | return results;
|
409 | 405 | }
|
410 | 406 |
|
411 |
| - Collection<ID> idCollection = toCollection(ids); |
| 407 | + Collection<ID> idCollection = Streamable.of(ids).toList(); |
412 | 408 |
|
413 | 409 | ByIdsSpecification<T> specification = new ByIdsSpecification<T>(entityInformation);
|
414 | 410 | TypedQuery<T> query = getQuery(specification, Sort.unsorted());
|
|
0 commit comments