Skip to content
This repository has been archived by the owner on Sep 1, 2023. It is now read-only.

saveAll batch size dynamic configuration #43

Open
benlahav opened this issue Apr 12, 2023 · 0 comments
Open

saveAll batch size dynamic configuration #43

benlahav opened this issue Apr 12, 2023 · 0 comments

Comments

@benlahav
Copy link

Like in Hibernate, to have the ability to enforce batch sizes limitations from the application.yml file.

Something like this:

neo4j:
  uri: bolt://localhost:7687
  authentication:
    username: neo4j
    password: password
  minTransactionSize: 5
  maxTransactionSize: 50

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();
                }
	}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant