|
39 | 39 | import org.neo4j.driver.Values;
|
40 | 40 | import org.neo4j.driver.types.TypeSystem;
|
41 | 41 | import org.springframework.data.neo4j.core.Neo4jClient;
|
| 42 | +import org.springframework.data.util.Lazy; |
42 | 43 | import org.springframework.lang.Nullable;
|
43 | 44 | import org.springframework.modulith.events.core.EventPublicationRepository;
|
44 | 45 | import org.springframework.modulith.events.core.EventSerializer;
|
@@ -130,22 +131,24 @@ class Neo4jEventPublicationRepository implements EventPublicationRepository {
|
130 | 131 | .set(EVENT_PUBLICATION_NODE.property(COMPLETION_DATE).to(parameter(COMPLETION_DATE)))
|
131 | 132 | .build();
|
132 | 133 |
|
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))) |
144 | 137 | .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))) |
147 | 139 | .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))); |
149 | 152 |
|
150 | 153 | private static Statement applyProperties(OrderableOngoingReadingAndWithWithoutWhere source) {
|
151 | 154 |
|
@@ -260,7 +263,7 @@ public void markCompleted(Object event, PublicationTargetIdentifier identifier,
|
260 | 263 |
|
261 | 264 | } else if (completionMode == CompletionMode.ARCHIVE) {
|
262 | 265 |
|
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())) |
264 | 267 | .bind(eventHash).to(EVENT_HASH)
|
265 | 268 | .bind(identifier.getValue()).to(LISTENER_ID)
|
266 | 269 | .bind(Values.value(completionDate.atOffset(ZoneOffset.UTC))).to(COMPLETION_DATE)
|
@@ -295,7 +298,7 @@ public void markCompleted(UUID identifier, Instant completionDate) {
|
295 | 298 |
|
296 | 299 | } else if (completionMode == CompletionMode.ARCHIVE) {
|
297 | 300 |
|
298 |
| - neo4jClient.query(renderer.render(COMPLETE_IN_ARCHIVE_BY_ID_STATEMENT)) |
| 301 | + neo4jClient.query(renderer.render(COMPLETE_IN_ARCHIVE_BY_ID_STATEMENT.get())) |
299 | 302 | .bind(Values.value(identifier.toString())).to(ID)
|
300 | 303 | .bind(Values.value(completionDate.atOffset(ZoneOffset.UTC))).to(COMPLETION_DATE)
|
301 | 304 | .run();
|
|
0 commit comments