Like in Hibernate, to have the ability to enforce batch sizes limitations from the application.yml
file.
When a batch that is less than or greater than these are trying to operate then raise an exception:
@Repository
@Transactional(readOnly = true)
@API(status = API.Status.STABLE, since = "6.0")
public class SimpleNeo4jRepository<T, ID> implements PagingAndSortingRepository<T, ID>, CrudRepository<T, ID> {
...
@Override
@Transactional
public <S extends T> List<S> saveAll(Iterable<S> entities) {
validateBatchOperationSizeLimitations(entities); // <- Add this
return this.neo4jOperations.saveAll(entities);
}
// Validation method
private void validateBatchOperationSizeLimitations(Iterable<S> entities) {
boolean isMinViolation = this.configuration.minTransactionSize() > entities.size();
boolean isMaxViolation = this.configuration.maxTransactionSize() < entities.size();
if (isMinViolation || isMaxViolation) {
throw new BatchSizeLimitationException();
}
}