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

saveAll batch size dynamic configuration #43

@benlahav

Description

@benlahav

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();
                }
	}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions