Skip to content

Commit

Permalink
Only create the event in the table if the database supports events
Browse files Browse the repository at this point in the history
  • Loading branch information
carlesarnal committed Oct 3, 2024
1 parent af1f36d commit dc83838
Showing 1 changed file with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -536,9 +536,7 @@ public Pair<ArtifactMetaDataDto, ArtifactVersionMetaDataDto> createArtifact(Stri
pair = ImmutablePair.of(amdDto, null);
}

if (supportsDatabaseEvents()) {
outboxEvent.fire(ArtifactCreated.of(amdDto));
}
outboxEvent.fire(ArtifactCreated.of(amdDto));

return pair;
});
Expand Down Expand Up @@ -779,9 +777,7 @@ public List<String> deleteArtifact(String groupId, String artifactId)

deleteAllOrphanedContentRaw(handle);

if (supportsDatabaseEvents()) {
outboxEvent.fire(ArtifactDeleted.of(groupId, artifactId));
}
outboxEvent.fire(ArtifactDeleted.of(groupId, artifactId));

return versions;
});
Expand Down Expand Up @@ -1195,7 +1191,7 @@ public void updateArtifactMetaData(String groupId, String artifactId,
modified = true;
if (rowCount == 0) {
throw new ArtifactNotFoundException(groupId, artifactId);
} else if (supportsDatabaseEvents()) {
} else {
outboxEvent.fire(ArtifactMetadataUpdated.of(groupId, artifactId, metaData));
}
}
Expand Down Expand Up @@ -3529,13 +3525,15 @@ public String createSnapshot(String location) throws RegistryStorageException {

@Override
public String createEvent(OutboxEvent event) {
// Create outbox event
handles.withHandle(handle -> handle.createUpdate(sqlStatements.createOutboxEvent())
.bind(0, event.getId()).bind(1, event.getAggregateType()).bind(2, event.getAggregateId())
.bind(3, event.getType()).bind(4, event.getPayload().toString()).execute());
if (supportsDatabaseEvents()) {
// Create outbox event
handles.withHandle(handle -> handle.createUpdate(sqlStatements.createOutboxEvent())
.bind(0, event.getId()).bind(1, event.getAggregateType()).bind(2, event.getAggregateId())
.bind(3, event.getType()).bind(4, event.getPayload().toString()).execute());

deleteEvent(event.getId());
deleteEvent(event.getId());

}
return event.getId();
}

Expand Down

0 comments on commit dc83838

Please sign in to comment.