DATAJDBC-378 - Proper handling of null and empty collections in JdbcAggregateTemplate.
Original Pull Request: #155
This commit is contained in:
committed by
Christoph Strobl
parent
b93c4c818c
commit
688eeca6d3
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.jdbc.core;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
@@ -122,6 +123,9 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
|
||||
*/
|
||||
@Override
|
||||
public long count(Class<?> domainType) {
|
||||
|
||||
Assert.notNull(domainType, "Domain type must not be null");
|
||||
|
||||
return accessStrategy.count(domainType);
|
||||
}
|
||||
|
||||
@@ -132,6 +136,9 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
|
||||
@Override
|
||||
public <T> T findById(Object id, Class<T> domainType) {
|
||||
|
||||
Assert.notNull(id, "Id must not be null");
|
||||
Assert.notNull(domainType, "Domain type must not be null");
|
||||
|
||||
T entity = accessStrategy.findById(id, domainType);
|
||||
if (entity != null) {
|
||||
publishAfterLoad(id, entity);
|
||||
@@ -145,6 +152,10 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
|
||||
*/
|
||||
@Override
|
||||
public <T> boolean existsById(Object id, Class<T> domainType) {
|
||||
|
||||
Assert.notNull(id, "Id must not be null");
|
||||
Assert.notNull(domainType, "Domain type must not be null");
|
||||
|
||||
return accessStrategy.existsById(id, domainType);
|
||||
}
|
||||
|
||||
@@ -155,6 +166,8 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
|
||||
@Override
|
||||
public <T> Iterable<T> findAll(Class<T> domainType) {
|
||||
|
||||
Assert.notNull(domainType, "Domain type must not be null");
|
||||
|
||||
Iterable<T> all = accessStrategy.findAll(domainType);
|
||||
publishAfterLoad(all);
|
||||
return all;
|
||||
@@ -167,6 +180,13 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
|
||||
@Override
|
||||
public <T> Iterable<T> findAllById(Iterable<?> ids, Class<T> domainType) {
|
||||
|
||||
Assert.notNull(ids, "Ids must not be null");
|
||||
Assert.notNull(domainType, "Domain type must not be null");
|
||||
|
||||
if (!ids.iterator().hasNext()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
Iterable<T> allById = accessStrategy.findAllById(ids, domainType);
|
||||
publishAfterLoad(allById);
|
||||
return allById;
|
||||
@@ -179,6 +199,9 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
|
||||
@Override
|
||||
public <S> void delete(S aggregateRoot, Class<S> domainType) {
|
||||
|
||||
Assert.notNull(aggregateRoot, "Aggregate root must not be null");
|
||||
Assert.notNull(domainType, "Domain type must not be null");
|
||||
|
||||
IdentifierAccessor identifierAccessor = context.getRequiredPersistentEntity(domainType)
|
||||
.getIdentifierAccessor(aggregateRoot);
|
||||
|
||||
@@ -191,6 +214,10 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
|
||||
*/
|
||||
@Override
|
||||
public <S> void deleteById(Object id, Class<S> domainType) {
|
||||
|
||||
Assert.notNull(id, "Id must not be null");
|
||||
Assert.notNull(domainType, "Domain type must not be null");
|
||||
|
||||
deleteTree(id, null, domainType);
|
||||
}
|
||||
|
||||
@@ -201,6 +228,8 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations {
|
||||
@Override
|
||||
public void deleteAll(Class<?> domainType) {
|
||||
|
||||
Assert.notNull(domainType, "Domain type must not be null");
|
||||
|
||||
AggregateChange<?> change = createDeletingChange(domainType);
|
||||
change.executeWith(interpreter, context, converter);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user