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) {
return commandSourceRepository.findByActionNameAndEntityNameAndIdempotencyKey(wrapper.actionName(), wrapper.entityName(),
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) {
CommandSource commandSourceResult;
if (jsonCommand.commandId() != null) {
@@ -109,22 +109,12 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
try {
result = findCommandHandler(wrapper).processCommand(command);
} catch (Throwable t) { // NOSONAR
CommandSource source;
if (BatchRequestContextHolder.getEnclosingTransaction().isPresent()) {
source = commandSourceService.findCommandSourceNoTransaction(wrapper, idempotencyKey);
} else {
source = commandSourceService.findCommandSource(wrapper, idempotencyKey);
}
CommandSource source = commandSourceService.findCommandSource(wrapper, idempotencyKey);
commandSourceService.saveFailed(source);
publishHookErrorEvent(wrapper, command, t);
throw t;
}
CommandSource initialCommandSource;
if (BatchRequestContextHolder.getEnclosingTransaction().isPresent()) {
initialCommandSource = commandSourceService.findCommandSourceNoTransaction(wrapper, idempotencyKey);
} else {
initialCommandSource = commandSourceService.findCommandSource(wrapper, idempotencyKey);
}
CommandSource initialCommandSource = commandSourceService.findCommandSource(wrapper, idempotencyKey);
initialCommandSource.setResult(toApiJsonSerializer.serializeResult(result));
initialCommandSource.updateResourceId(result.getResourceId());