diff --git a/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateTemplate.java b/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateTemplate.java index 979f8296..6409a3c4 100644 --- a/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateTemplate.java +++ b/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateTemplate.java @@ -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 findById(Object id, Class 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 boolean existsById(Object id, Class 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 Iterable findAll(Class domainType) { + Assert.notNull(domainType, "Domain type must not be null"); + Iterable all = accessStrategy.findAll(domainType); publishAfterLoad(all); return all; @@ -167,6 +180,13 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations { @Override public Iterable findAllById(Iterable ids, Class 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 allById = accessStrategy.findAllById(ids, domainType); publishAfterLoad(allById); return allById; @@ -179,6 +199,9 @@ public class JdbcAggregateTemplate implements JdbcAggregateOperations { @Override public void delete(S aggregateRoot, Class 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 void deleteById(Object id, Class 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); }