Skip to content

Commit 7320b3b

Browse files
committed
GH-918 - Lazify archiving Cypher statement initialization.
Eagerly initializing the archiving Cypher statements required for the new archiving event completion mode breaks our compatibility with Spring Boot 3.2 as that depends on a Cypher library version not containing the exists(…) operator yet. We now lazily instantiate those statements.
1 parent f64cc8f commit 7320b3b

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

spring-modulith-events/spring-modulith-events-neo4j/src/main/java/org/springframework/modulith/events/neo4j/Neo4jEventPublicationRepository.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.neo4j.driver.Values;
4040
import org.neo4j.driver.types.TypeSystem;
4141
import org.springframework.data.neo4j.core.Neo4jClient;
42+
import org.springframework.data.util.Lazy;
4243
import org.springframework.lang.Nullable;
4344
import org.springframework.modulith.events.core.EventPublicationRepository;
4445
import org.springframework.modulith.events.core.EventSerializer;
@@ -130,22 +131,24 @@ class Neo4jEventPublicationRepository implements EventPublicationRepository {
130131
.set(EVENT_PUBLICATION_NODE.property(COMPLETION_DATE).to(parameter(COMPLETION_DATE)))
131132
.build();
132133

133-
private static final Statement COMPLETE_IN_ARCHIVE_BY_ID_STATEMENT = applyProperties(match(EVENT_PUBLICATION_NODE)
134-
.where(EVENT_PUBLICATION_NODE.property(ID).eq(parameter(ID)))
135-
.and(not(exists(match(EVENT_PUBLICATION_ARCHIVE_NODE)
136-
.where(EVENT_PUBLICATION_ARCHIVE_NODE.property(ID).eq(parameter(ID)))
137-
.returning(literalTrue()).build())))
138-
.with(EVENT_PUBLICATION_NODE));
139-
140-
private static final Statement COMPLETE_IN_ARCHIVE_BY_EVENT_AND_LISTENER_ID_STATEMENT = applyProperties(
141-
match(EVENT_PUBLICATION_NODE)
142-
.where(EVENT_PUBLICATION_NODE.property(EVENT_HASH).eq(parameter(EVENT_HASH)))
143-
.and(EVENT_PUBLICATION_NODE.property(LISTENER_ID).eq(parameter(LISTENER_ID)))
134+
private static final Lazy<Statement> COMPLETE_IN_ARCHIVE_BY_ID_STATEMENT = Lazy
135+
.of(() -> applyProperties(match(EVENT_PUBLICATION_NODE)
136+
.where(EVENT_PUBLICATION_NODE.property(ID).eq(parameter(ID)))
144137
.and(not(exists(match(EVENT_PUBLICATION_ARCHIVE_NODE)
145-
.where(EVENT_PUBLICATION_ARCHIVE_NODE.property(EVENT_HASH).eq(parameter(EVENT_HASH)))
146-
.and(EVENT_PUBLICATION_ARCHIVE_NODE.property(LISTENER_ID).eq(parameter(LISTENER_ID)))
138+
.where(EVENT_PUBLICATION_ARCHIVE_NODE.property(ID).eq(parameter(ID)))
147139
.returning(literalTrue()).build())))
148-
.with(EVENT_PUBLICATION_NODE));
140+
.with(EVENT_PUBLICATION_NODE)));
141+
142+
private static final Lazy<Statement> COMPLETE_IN_ARCHIVE_BY_EVENT_AND_LISTENER_ID_STATEMENT = Lazy
143+
.of(() -> applyProperties(
144+
match(EVENT_PUBLICATION_NODE)
145+
.where(EVENT_PUBLICATION_NODE.property(EVENT_HASH).eq(parameter(EVENT_HASH)))
146+
.and(EVENT_PUBLICATION_NODE.property(LISTENER_ID).eq(parameter(LISTENER_ID)))
147+
.and(not(exists(match(EVENT_PUBLICATION_ARCHIVE_NODE)
148+
.where(EVENT_PUBLICATION_ARCHIVE_NODE.property(EVENT_HASH).eq(parameter(EVENT_HASH)))
149+
.and(EVENT_PUBLICATION_ARCHIVE_NODE.property(LISTENER_ID).eq(parameter(LISTENER_ID)))
150+
.returning(literalTrue()).build())))
151+
.with(EVENT_PUBLICATION_NODE)));
149152

150153
private static Statement applyProperties(OrderableOngoingReadingAndWithWithoutWhere source) {
151154

@@ -260,7 +263,7 @@ public void markCompleted(Object event, PublicationTargetIdentifier identifier,
260263

261264
} else if (completionMode == CompletionMode.ARCHIVE) {
262265

263-
neo4jClient.query(renderer.render(COMPLETE_IN_ARCHIVE_BY_EVENT_AND_LISTENER_ID_STATEMENT))
266+
neo4jClient.query(renderer.render(COMPLETE_IN_ARCHIVE_BY_EVENT_AND_LISTENER_ID_STATEMENT.get()))
264267
.bind(eventHash).to(EVENT_HASH)
265268
.bind(identifier.getValue()).to(LISTENER_ID)
266269
.bind(Values.value(completionDate.atOffset(ZoneOffset.UTC))).to(COMPLETION_DATE)
@@ -295,7 +298,7 @@ public void markCompleted(UUID identifier, Instant completionDate) {
295298

296299
} else if (completionMode == CompletionMode.ARCHIVE) {
297300

298-
neo4jClient.query(renderer.render(COMPLETE_IN_ARCHIVE_BY_ID_STATEMENT))
301+
neo4jClient.query(renderer.render(COMPLETE_IN_ARCHIVE_BY_ID_STATEMENT.get()))
299302
.bind(Values.value(identifier.toString())).to(ID)
300303
.bind(Values.value(completionDate.atOffset(ZoneOffset.UTC))).to(COMPLETION_DATE)
301304
.run();

0 commit comments

Comments
 (0)