Changed transaction handling for ImExporters
parent
9a6fcf8804
commit
4b6bd259eb
|
|
@ -34,6 +34,8 @@ import java.util.stream.Collectors;
|
|||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
|
|
@ -49,6 +51,9 @@ import javax.transaction.Transactional;
|
|||
public abstract class AbstractEntityImExporter<T extends Exportable> {
|
||||
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
@Inject
|
||||
private EntityManager entityManager;
|
||||
|
||||
/**
|
||||
* A set of entities which should be processed before this implementation is
|
||||
|
|
@ -147,7 +152,7 @@ public abstract class AbstractEntityImExporter<T extends Exportable> {
|
|||
* @see #updateExistingEntity(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 {
|
||||
try {
|
||||
final T importedEntity = objectMapper.readValue(data,
|
||||
|
|
@ -158,6 +163,8 @@ public abstract class AbstractEntityImExporter<T extends Exportable> {
|
|||
if (existingEntityResult.isPresent()) {
|
||||
final T existingEntity = existingEntityResult.get();
|
||||
updateExistingEntity(existingEntity, importedEntity);
|
||||
|
||||
|
||||
return existingEntity;
|
||||
} else {
|
||||
saveImportedEntity(importedEntity);
|
||||
|
|
|
|||
Loading…
Reference in New Issue