diff --git a/src/main/java/com/epam/ta/reportportal/dao/IntegrationTypeRepository.java b/src/main/java/com/epam/ta/reportportal/dao/IntegrationTypeRepository.java index 0384f8aa7..bc141445c 100644 --- a/src/main/java/com/epam/ta/reportportal/dao/IntegrationTypeRepository.java +++ b/src/main/java/com/epam/ta/reportportal/dao/IntegrationTypeRepository.java @@ -20,9 +20,13 @@ import com.epam.ta.reportportal.entity.integration.IntegrationType; import java.util.List; import java.util.Optional; + +import org.springframework.data.jpa.repository.Lock; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; +import javax.persistence.LockModeType; + /** * Repository for {@link com.epam.ta.reportportal.entity.integration.IntegrationType} entity * @@ -30,6 +34,23 @@ */ public interface IntegrationTypeRepository extends ReportPortalRepository { + /** + * Find {@link IntegrationType} by id with pessimistic locking to provide synchronization + * + * @param id {@link IntegrationType#getId()} + * @return @return The {@link Optional} of the {@link IntegrationType} + */ + @Query(value = "SELECT * FROM integration_type WHERE id = :id FOR UPDATE", nativeQuery = true) + Optional findByIdForUpdate(@Param("id") Long id); + + /** + * Retrieve all {@link IntegrationType} with pessimistic locking to provide synchronization + * + * @return The {@link List} of the {@link IntegrationType} + */ + @Lock(LockModeType.PESSIMISTIC_WRITE) + List findAllByIdOrderById(); + /** * Retrieve all {@link IntegrationType} by {@link IntegrationType#integrationGroup} *