From 0de48790d7e98785d82f7e0668f1a75036f9c152 Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Thu, 10 Aug 2023 00:19:35 +0200 Subject: [PATCH] GH-261 - Avoid materializing JpaEventPublication to mark it completed. We now simply issue an update query. --- .../events/jpa/JpaEventPublicationRepository.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/spring-modulith-events/spring-modulith-events-jpa/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublicationRepository.java b/spring-modulith-events/spring-modulith-events-jpa/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublicationRepository.java index dab67b24..34458d97 100644 --- a/spring-modulith-events/spring-modulith-events-jpa/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublicationRepository.java +++ b/spring-modulith-events/spring-modulith-events-jpa/src/main/java/org/springframework/modulith/events/jpa/JpaEventPublicationRepository.java @@ -57,6 +57,13 @@ class JpaEventPublicationRepository implements EventPublicationRepository { p.publicationDate asc """; + private static final String MARK_COMPLETED_BY_EVENT_AND_LISTENER_ID = """ + update JpaEventPublication p + set p.completionDate = ?3 + where p.serializedEvent = ?1 + and p.listenerId = ?2 + """; + private static final String DELETE_COMPLETED = """ delete from JpaEventPublication p @@ -111,8 +118,11 @@ class JpaEventPublicationRepository implements EventPublicationRepository { @Transactional public void markCompleted(Object event, PublicationTargetIdentifier identifier, Instant completionDate) { - findEntityBySerializedEventAndListenerIdAndCompletionDateNull(event, identifier) - .map(it -> it.completionDate = completionDate); + entityManager.createQuery(MARK_COMPLETED_BY_EVENT_AND_LISTENER_ID) + .setParameter(1, serializeEvent(event)) + .setParameter(2, identifier.getValue()) + .setParameter(3, completionDate) + .executeUpdate(); } /*