diff --git a/spring-modulith-events/spring-modulith-events-jdbc/src/main/java/org/springframework/modulith/events/jdbc/JdbcEventPublicationRepository.java b/spring-modulith-events/spring-modulith-events-jdbc/src/main/java/org/springframework/modulith/events/jdbc/JdbcEventPublicationRepository.java index ef9312eb..198b924f 100644 --- a/spring-modulith-events/spring-modulith-events-jdbc/src/main/java/org/springframework/modulith/events/jdbc/JdbcEventPublicationRepository.java +++ b/spring-modulith-events/spring-modulith-events-jdbc/src/main/java/org/springframework/modulith/events/jdbc/JdbcEventPublicationRepository.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.Objects; import java.util.Optional; import java.util.UUID; +import java.util.stream.Collectors; import java.util.stream.IntStream; import org.slf4j.Logger; @@ -99,7 +100,7 @@ class JdbcEventPublicationRepository implements EventPublicationRepository { DELETE FROM EVENT_PUBLICATION WHERE - ID IN (?) + ID IN """; private static final String SQL_STATEMENT_DELETE_UNCOMPLETED = """ @@ -233,9 +234,10 @@ class JdbcEventPublicationRepository implements EventPublicationRepository { @Override public void deletePublications(List identifiers) { - var databaseIds = identifiers.stream().map(this::uuidToDatabase).toList(); + var dbIdentifiers = identifiers.stream().map(databaseType::uuidToDatabase).toList(); - operations.batchUpdate(SQL_STATEMENT_DELETE, batch(databaseIds, DELETE_BATCH_SIZE)); + batch(dbIdentifiers, DELETE_BATCH_SIZE) + .forEach(it -> operations.update(SQL_STATEMENT_DELETE.concat(toParameterPlaceholders(it.length)), it)); } /* @@ -341,6 +343,13 @@ class JdbcEventPublicationRepository implements EventPublicationRepository { .toList(); } + private static String toParameterPlaceholders(int length) { + + return IntStream.range(0, length) + .mapToObj(__ -> "?") + .collect(Collectors.joining(", ", "(", ")")); + } + private static class JdbcEventPublication implements TargetEventPublication { private final UUID id; diff --git a/spring-modulith-events/spring-modulith-events-jdbc/src/test/java/org/springframework/modulith/events/jdbc/JdbcEventPublicationRepositoryIntegrationTests.java b/spring-modulith-events/spring-modulith-events-jdbc/src/test/java/org/springframework/modulith/events/jdbc/JdbcEventPublicationRepositoryIntegrationTests.java index 604a7653..2dead88f 100644 --- a/spring-modulith-events/spring-modulith-events-jdbc/src/test/java/org/springframework/modulith/events/jdbc/JdbcEventPublicationRepositoryIntegrationTests.java +++ b/spring-modulith-events/spring-modulith-events-jdbc/src/test/java/org/springframework/modulith/events/jdbc/JdbcEventPublicationRepositoryIntegrationTests.java @@ -265,14 +265,15 @@ class JdbcEventPublicationRepositoryIntegrationTests { var first = createPublication(new TestEvent("first")); var second = createPublication(new TestEvent("second")); + var third = createPublication(new TestEvent("third")); - repository.deletePublications(List.of(first.getIdentifier())); + repository.deletePublications(List.of(first.getIdentifier(), second.getIdentifier())); assertThat(repository.findIncompletePublications()) .hasSize(1) .element(0) - .matches(it -> it.getIdentifier().equals(second.getIdentifier())) - .matches(it -> it.getEvent().equals(second.getEvent())); + .matches(it -> it.getIdentifier().equals(third.getIdentifier())) + .matches(it -> it.getEvent().equals(third.getEvent())); } @Test // GH-294 diff --git a/spring-modulith-events/spring-modulith-events-jdbc/src/test/resources/application-h2.properties b/spring-modulith-events/spring-modulith-events-jdbc/src/test/resources/application-h2.properties index 19f49d8f..54f38c3d 100644 --- a/spring-modulith-events/spring-modulith-events-jdbc/src/test/resources/application-h2.properties +++ b/spring-modulith-events/spring-modulith-events-jdbc/src/test/resources/application-h2.properties @@ -4,3 +4,6 @@ spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1 spring.test.database.replace=NONE spring.modulith.events.jdbc-schema-initialization.enabled=true + +logging.level.org.springframework.jdbc=trace +spring.main.banner-mode=off