From e05120cc932a168b9718f69fbb793aeb6518e815 Mon Sep 17 00:00:00 2001 From: holgerhagen Date: Wed, 3 Nov 2021 15:39:43 +0100 Subject: [PATCH] TSK-1757: Added lock for update to custom attribute initialization. --- .../taskana/common/test/util/ParallelThreadHelper.java | 4 ++++ .../taskana/common/internal/ConfigurationMapper.java | 10 ++++++++-- .../common/internal/ConfigurationServiceImpl.java | 5 +++-- .../config/ConfigurationServiceImplAccTest.java | 2 +- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/common/taskana-common-test/src/main/java/pro/taskana/common/test/util/ParallelThreadHelper.java b/common/taskana-common-test/src/main/java/pro/taskana/common/test/util/ParallelThreadHelper.java index 2012aaeae..bd8a938d9 100644 --- a/common/taskana-common-test/src/main/java/pro/taskana/common/test/util/ParallelThreadHelper.java +++ b/common/taskana-common-test/src/main/java/pro/taskana/common/test/util/ParallelThreadHelper.java @@ -8,6 +8,10 @@ import pro.taskana.common.api.exceptions.SystemException; public class ParallelThreadHelper { + private ParallelThreadHelper() { + throw new IllegalStateException("Utility class"); + } + public static void runInThread(Runnable runnable, int threadCount) throws Exception { Thread[] threads = new Thread[threadCount]; diff --git a/lib/taskana-core/src/main/java/pro/taskana/common/internal/ConfigurationMapper.java b/lib/taskana-core/src/main/java/pro/taskana/common/internal/ConfigurationMapper.java index ae8d55ee8..105319d5c 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/common/internal/ConfigurationMapper.java +++ b/lib/taskana-core/src/main/java/pro/taskana/common/internal/ConfigurationMapper.java @@ -14,8 +14,14 @@ public interface ConfigurationMapper { @Insert("INSERT INTO CONFIGURATION(ENFORCE_SECURITY) VALUES (#{securityEnabled})") void setSecurityEnabled(@Param("securityEnabled") boolean securityEnabled); - @Select("SELECT CUSTOM_ATTRIBUTES FROM CONFIGURATION") - Map getAllCustomAttributes(); + @Select( + "") + Map getAllCustomAttributes(boolean lockForUpdate); @Update("UPDATE CONFIGURATION SET CUSTOM_ATTRIBUTES = #{customAttributes}") void setAllCustomAttributes(@Param("customAttributes") Map customAttributes); diff --git a/lib/taskana-core/src/main/java/pro/taskana/common/internal/ConfigurationServiceImpl.java b/lib/taskana-core/src/main/java/pro/taskana/common/internal/ConfigurationServiceImpl.java index f4720543c..6b6ecc817 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/common/internal/ConfigurationServiceImpl.java +++ b/lib/taskana-core/src/main/java/pro/taskana/common/internal/ConfigurationServiceImpl.java @@ -47,7 +47,7 @@ public class ConfigurationServiceImpl implements ConfigurationService { internalTaskanaEngine.executeInDatabaseConnection( CheckedRunnable.wrap( () -> { - if (mapper.getAllCustomAttributes() == null) { + if (mapper.getAllCustomAttributes(true) == null) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("custom attributes are not set. Setting default value"); } @@ -58,7 +58,8 @@ public class ConfigurationServiceImpl implements ConfigurationService { @Override public Map getAllCustomAttributes() { - return internalTaskanaEngine.executeInDatabaseConnection(mapper::getAllCustomAttributes); + return internalTaskanaEngine.executeInDatabaseConnection( + () -> mapper.getAllCustomAttributes(false)); } @Override diff --git a/lib/taskana-core/src/test/java/acceptance/config/ConfigurationServiceImplAccTest.java b/lib/taskana-core/src/test/java/acceptance/config/ConfigurationServiceImplAccTest.java index 2a40e5168..8cc153546 100644 --- a/lib/taskana-core/src/test/java/acceptance/config/ConfigurationServiceImplAccTest.java +++ b/lib/taskana-core/src/test/java/acceptance/config/ConfigurationServiceImplAccTest.java @@ -41,7 +41,7 @@ public class ConfigurationServiceImplAccTest { ConfigurationServiceImpl.class, "defaultCustomAttributes.json")) .toMap(); - Map allCustomAttributes = configurationMapper.getAllCustomAttributes(); + Map allCustomAttributes = configurationMapper.getAllCustomAttributes(false); assertThat(allCustomAttributes).isEqualTo(expectedCustomAttributes); }