Drop superfluous class argument from delete methods in JdbcAggregateTemplate.
Closes: #1315 Original pull request: #1324.
This commit is contained in:
committed by
Jens Schauder
parent
01e98dc171
commit
aef1e34f5e
@@ -102,13 +102,21 @@ public interface JdbcAggregateOperations {
|
||||
* {@link org.springframework.dao.OptimisticLockingFailureException}. If no rows match the generated delete operation
|
||||
* this fact will be silently ignored.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @param ids the ids of the aggregate roots of the aggregates to be deleted. Must not be {@code null}.
|
||||
* @param domainType the type of the aggregate root.
|
||||
* @param <T> the type of the aggregate root.
|
||||
*/
|
||||
<T> void deleteAllById(Iterable<?> ids, Class<T> domainType);
|
||||
|
||||
/**
|
||||
* Delete an aggregate identified by its aggregate root.
|
||||
*
|
||||
* @param aggregateRoot to delete. Must not be {@code null}.
|
||||
* @param <T> the type of the aggregate root.
|
||||
*/
|
||||
<T> void delete(T aggregateRoot);
|
||||
|
||||
/**
|
||||
* Delete an aggregate identified by its aggregate root.
|
||||
*
|
||||
@@ -118,8 +126,12 @@ public interface JdbcAggregateOperations {
|
||||
* @throws org.springframework.dao.OptimisticLockingFailureException when {@literal T} has a version attribute and the
|
||||
* version attribute of the provided entity does not match the version attribute in the database, or when
|
||||
* there is no aggregate root with matching id. In other cases a NOOP delete is silently ignored.
|
||||
* @deprecated since 3.0 use {@link #delete(Object)} instead
|
||||
*/
|
||||
<T> void delete(T aggregateRoot, Class<T> domainType);
|
||||
@Deprecated
|
||||
default <T> void delete(T aggregateRoot, Class<T> domainType) {
|
||||
delete(aggregateRoot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all aggregates of a given type.
|
||||
@@ -128,6 +140,14 @@ public interface JdbcAggregateOperations {
|
||||
*/
|
||||
void deleteAll(Class<?> domainType);
|
||||
|
||||
/**
|
||||
* Delete all aggregates identified by their aggregate roots.
|
||||
*
|
||||
* @param aggregateRoots to delete. Must not be {@code null}.
|
||||
* @param <T> the type of the aggregate roots.
|
||||
*/
|
||||
<T> void deleteAll(Iterable<? extends T> aggregateRoots);
|
||||
|
||||
/**
|
||||
* Delete all aggregates identified by their aggregate roots.
|
||||
*
|
||||
@@ -137,8 +157,12 @@ public interface JdbcAggregateOperations {
|
||||
* @throws org.springframework.dao.OptimisticLockingFailureException when {@literal T} has a version attribute and for at least on entity the
|
||||
* version attribute of the entity does not match the version attribute in the database, or when
|
||||
* there is no aggregate root with matching id. In other cases a NOOP delete is silently ignored.
|
||||
* @deprecated since 3.0 use {@link #deleteAll(Iterable)} instead.
|
||||
*/
|
||||
<T> void deleteAll(Iterable<? extends T> aggregateRoots, Class<T> domainType);
|
||||
@Deprecated
|
||||
default <T> void deleteAll(Iterable<? extends T> aggregateRoots, Class<T> domainType) {
|
||||
deleteAll(aggregateRoots);
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts the number of aggregates of a given type.
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.data.jdbc.core;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
@@ -303,11 +304,11 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S> void delete(S aggregateRoot, Class<S> domainType) {
|
||||
public <S> void delete(S aggregateRoot) {
|
||||
|
||||
Assert.notNull(aggregateRoot, "Aggregate root must not be null");
|
||||
Assert.notNull(domainType, "Domain type must not be null");
|
||||
|
||||
Class<S> domainType = (Class<S>) aggregateRoot.getClass();
|
||||
IdentifierAccessor identifierAccessor = context.getRequiredPersistentEntity(domainType)
|
||||
.getIdentifierAccessor(aggregateRoot);
|
||||
|
||||
@@ -353,10 +354,26 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void deleteAll(Iterable<? extends T> instances, Class<T> domainType) {
|
||||
public <T> void deleteAll(Iterable<? extends T> instances) {
|
||||
|
||||
Assert.isTrue(instances.iterator().hasNext(), "Aggregate instances must not be empty");
|
||||
|
||||
Map<Class, List<Object>> groupedByType = new HashMap<>();
|
||||
|
||||
for (T instance : instances) {
|
||||
Class<?> type = instance.getClass();
|
||||
final List<Object> list = groupedByType.computeIfAbsent(type, __ -> new ArrayList<>());
|
||||
list.add(instance);
|
||||
}
|
||||
|
||||
for (Class type : groupedByType.keySet()) {
|
||||
doDeleteAll(groupedByType.get(type), type);
|
||||
}
|
||||
}
|
||||
|
||||
private <T> void doDeleteAll(Iterable<? extends T> instances, Class<T> domainType) {
|
||||
|
||||
|
||||
BatchingAggregateChange<T, DeleteAggregateChange<T>> batchingAggregateChange = BatchingAggregateChange
|
||||
.forDelete(domainType);
|
||||
Map<Object, T> instancesBeforeExecute = new LinkedHashMap<>();
|
||||
|
||||
@@ -25,14 +25,11 @@ import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jdbc.core.JdbcAggregateOperations;
|
||||
import org.springframework.data.jdbc.core.convert.JdbcConverter;
|
||||
import org.springframework.data.mapping.PersistentEntity;
|
||||
import org.springframework.data.relational.core.query.Query;
|
||||
import org.springframework.data.relational.repository.query.RelationalExampleMapper;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.repository.PagingAndSortingRepository;
|
||||
import org.springframework.data.repository.query.FluentQuery;
|
||||
import org.springframework.data.repository.query.QueryByExampleExecutor;
|
||||
import org.springframework.data.support.PageableExecutionUtils;
|
||||
import org.springframework.data.util.Streamable;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -110,7 +107,7 @@ public class SimpleJdbcRepository<T, ID>
|
||||
@Transactional
|
||||
@Override
|
||||
public void delete(T instance) {
|
||||
entityOperations.delete(instance, entity.getType());
|
||||
entityOperations.delete(instance);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -121,7 +118,7 @@ public class SimpleJdbcRepository<T, ID>
|
||||
@Transactional
|
||||
@Override
|
||||
public void deleteAll(Iterable<? extends T> entities) {
|
||||
entityOperations.deleteAll(entities, entity.getType());
|
||||
entityOperations.deleteAll(entities);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
|
||||
Reference in New Issue
Block a user