FINERACT-1724 - Transaction handling fix

- [x] Fix Fetch new transaction
This commit is contained in:
Janos Haber
2023-03-28 00:34:22 +02:00
committed by Adam Saghy
parent 92838e5fff
commit ae8ad4b689
2 changed files with 2 additions and 18 deletions
@@ -89,17 +89,11 @@ public class CommandSourceService {
} }
} }
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true)
public CommandSource findCommandSource(CommandWrapper wrapper, String idempotencyKey) { public CommandSource findCommandSource(CommandWrapper wrapper, String idempotencyKey) {
return commandSourceRepository.findByActionNameAndEntityNameAndIdempotencyKey(wrapper.actionName(), wrapper.entityName(), return commandSourceRepository.findByActionNameAndEntityNameAndIdempotencyKey(wrapper.actionName(), wrapper.entityName(),
idempotencyKey); idempotencyKey);
} }
public CommandSource findCommandSourceNoTransaction(CommandWrapper wrapper, String idempotencyKey) {
return commandSourceRepository.findByActionNameAndEntityNameAndIdempotencyKey(wrapper.actionName(), wrapper.entityName(),
idempotencyKey);
}
private CommandSource getInitialCommandSource(CommandWrapper wrapper, JsonCommand jsonCommand, AppUser maker, String idempotencyKey) { private CommandSource getInitialCommandSource(CommandWrapper wrapper, JsonCommand jsonCommand, AppUser maker, String idempotencyKey) {
CommandSource commandSourceResult; CommandSource commandSourceResult;
if (jsonCommand.commandId() != null) { if (jsonCommand.commandId() != null) {
@@ -109,22 +109,12 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
try { try {
result = findCommandHandler(wrapper).processCommand(command); result = findCommandHandler(wrapper).processCommand(command);
} catch (Throwable t) { // NOSONAR } catch (Throwable t) { // NOSONAR
CommandSource source; CommandSource source = commandSourceService.findCommandSource(wrapper, idempotencyKey);
if (BatchRequestContextHolder.getEnclosingTransaction().isPresent()) {
source = commandSourceService.findCommandSourceNoTransaction(wrapper, idempotencyKey);
} else {
source = commandSourceService.findCommandSource(wrapper, idempotencyKey);
}
commandSourceService.saveFailed(source); commandSourceService.saveFailed(source);
publishHookErrorEvent(wrapper, command, t); publishHookErrorEvent(wrapper, command, t);
throw t; throw t;
} }
CommandSource initialCommandSource; CommandSource initialCommandSource = commandSourceService.findCommandSource(wrapper, idempotencyKey);
if (BatchRequestContextHolder.getEnclosingTransaction().isPresent()) {
initialCommandSource = commandSourceService.findCommandSourceNoTransaction(wrapper, idempotencyKey);
} else {
initialCommandSource = commandSourceService.findCommandSource(wrapper, idempotencyKey);
}
initialCommandSource.setResult(toApiJsonSerializer.serializeResult(result)); initialCommandSource.setResult(toApiJsonSerializer.serializeResult(result));
initialCommandSource.updateResourceId(result.getResourceId()); initialCommandSource.updateResourceId(result.getResourceId());