diff --git a/data-index/data-index-storage/data-index-storage-jpa-common/src/main/java/org/kie/kogito/index/jpa/storage/AbstractStorage.java b/data-index/data-index-storage/data-index-storage-jpa-common/src/main/java/org/kie/kogito/index/jpa/storage/AbstractStorage.java index 4d339888e3..de426fc4ef 100644 --- a/data-index/data-index-storage/data-index-storage-jpa-common/src/main/java/org/kie/kogito/index/jpa/storage/AbstractStorage.java +++ b/data-index/data-index-storage/data-index-storage-jpa-common/src/main/java/org/kie/kogito/index/jpa/storage/AbstractStorage.java @@ -18,7 +18,6 @@ */ package org.kie.kogito.index.jpa.storage; -import java.util.ConcurrentModificationException; import java.util.Map; import java.util.function.Function; @@ -27,8 +26,6 @@ import io.quarkus.hibernate.orm.panache.PanacheRepositoryBase; -import jakarta.persistence.LockModeType; -import jakarta.persistence.PersistenceException; import jakarta.transaction.Transactional; import static java.util.stream.Collectors.toMap; @@ -54,19 +51,7 @@ protected AbstractStorage(PanacheRepositoryBase repository, Class model @Override @Transactional public V put(K key, V value) { - //Pessimistic lock is used to lock the row to handle concurrency with an exiting registry - E persistedEntity = repository.findById(key, LockModeType.PESSIMISTIC_WRITE); - E newEntity = mapToEntity.apply(value); - if (persistedEntity != null) { - repository.getEntityManager().merge(newEntity); - } else { - try { - //to handle concurrency in case of a new registry persist flush and throw an exception to allow retry on the caller side - repository.persistAndFlush(newEntity); - } catch (PersistenceException e) { - throw new ConcurrentModificationException(e); - } - } + repository.getEntityManager().merge(mapToEntity.apply(value)); return value; } diff --git a/data-index/data-index-storage/data-index-storage-jpa-common/src/main/java/org/kie/kogito/index/jpa/storage/ProcessDefinitionEntityStorage.java b/data-index/data-index-storage/data-index-storage-jpa-common/src/main/java/org/kie/kogito/index/jpa/storage/ProcessDefinitionEntityStorage.java index db641e4de5..e22670c665 100644 --- a/data-index/data-index-storage/data-index-storage-jpa-common/src/main/java/org/kie/kogito/index/jpa/storage/ProcessDefinitionEntityStorage.java +++ b/data-index/data-index-storage/data-index-storage-jpa-common/src/main/java/org/kie/kogito/index/jpa/storage/ProcessDefinitionEntityStorage.java @@ -18,20 +18,14 @@ */ package org.kie.kogito.index.jpa.storage; -import java.util.Optional; - import org.kie.kogito.index.jpa.mapper.ProcessDefinitionEntityMapper; import org.kie.kogito.index.jpa.model.ProcessDefinitionEntity; import org.kie.kogito.index.jpa.model.ProcessDefinitionEntityRepository; import org.kie.kogito.index.model.ProcessDefinition; import org.kie.kogito.index.model.ProcessDefinitionKey; -import io.quarkus.hibernate.orm.panache.PanacheRepositoryBase; - import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; -import jakarta.persistence.EntityManager; -import jakarta.persistence.LockModeType; import jakarta.transaction.Transactional; @ApplicationScoped @@ -42,7 +36,7 @@ protected ProcessDefinitionEntityStorage() { @Inject public ProcessDefinitionEntityStorage(ProcessDefinitionEntityRepository repository, ProcessDefinitionEntityMapper mapper) { - super(new RepositoryAdapter(repository), ProcessDefinition.class, ProcessDefinitionEntity.class, mapper::mapToModel, mapper::mapToEntity, e -> new ProcessDefinitionKey(e.getId(), + super(repository, ProcessDefinition.class, ProcessDefinitionEntity.class, mapper::mapToModel, mapper::mapToEntity, e -> new ProcessDefinitionKey(e.getId(), e.getVersion())); } @@ -52,37 +46,4 @@ public boolean containsKey(ProcessDefinitionKey key) { return getRepository().count("id = ?1 and version = ?2", key.getId(), key.getVersion()) == 1; } - public static class RepositoryAdapter implements PanacheRepositoryBase { - - ProcessDefinitionEntityRepository repository; - - public RepositoryAdapter(ProcessDefinitionEntityRepository repository) { - this.repository = repository; - } - - @Override - public boolean deleteById(ProcessDefinitionKey key) { - return repository.deleteById(key); - } - - @Override - public Optional findByIdOptional(ProcessDefinitionKey key) { - return repository.findByIdOptional(key); - } - - @Override - public ProcessDefinitionEntity findById(ProcessDefinitionKey s, LockModeType lockModeType) { - return repository.findById(s, lockModeType); - } - - @Override - public void persist(ProcessDefinitionEntity entity) { - repository.persist(entity); - } - - @Override - public EntityManager getEntityManager() { - return repository.getEntityManager(); - } - } }