Changed transaction handling for ImExporters

deploy_packages_to_gitea
Jens Pelzetter 2023-01-26 19:02:50 +01:00
parent 9a6fcf8804
commit 4b6bd259eb
1 changed files with 8 additions and 1 deletions

View File

@ -34,6 +34,8 @@ import java.util.stream.Collectors;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.transaction.Transactional; import javax.transaction.Transactional;
/** /**
@ -50,6 +52,9 @@ public abstract class AbstractEntityImExporter<T extends Exportable> {
private final ObjectMapper objectMapper; private final ObjectMapper objectMapper;
@Inject
private EntityManager entityManager;
/** /**
* A set of entities which should be processed before this implementation is * A set of entities which should be processed before this implementation is
* used. We can't use an annotation for this because we can't access the * used. We can't use an annotation for this because we can't access the
@ -147,7 +152,7 @@ public abstract class AbstractEntityImExporter<T extends Exportable> {
* @see #updateExistingEntity(org.libreccm.imexport.Exportable, * @see #updateExistingEntity(org.libreccm.imexport.Exportable,
* org.libreccm.imexport.Exportable) * org.libreccm.imexport.Exportable)
*/ */
@Transactional(Transactional.TxType.REQUIRED) @Transactional(Transactional.TxType.REQUIRES_NEW)
public T importEntity(final String data) throws ImportExpection { public T importEntity(final String data) throws ImportExpection {
try { try {
final T importedEntity = objectMapper.readValue(data, final T importedEntity = objectMapper.readValue(data,
@ -158,6 +163,8 @@ public abstract class AbstractEntityImExporter<T extends Exportable> {
if (existingEntityResult.isPresent()) { if (existingEntityResult.isPresent()) {
final T existingEntity = existingEntityResult.get(); final T existingEntity = existingEntityResult.get();
updateExistingEntity(existingEntity, importedEntity); updateExistingEntity(existingEntity, importedEntity);
return existingEntity; return existingEntity;
} else { } else {
saveImportedEntity(importedEntity); saveImportedEntity(importedEntity);