TSK-1757: Added lock for update to custom attribute initialization.
This commit is contained in:
parent
1df190d1da
commit
e05120cc93
|
@ -8,6 +8,10 @@ import pro.taskana.common.api.exceptions.SystemException;
|
||||||
|
|
||||||
public class ParallelThreadHelper {
|
public class ParallelThreadHelper {
|
||||||
|
|
||||||
|
private ParallelThreadHelper() {
|
||||||
|
throw new IllegalStateException("Utility class");
|
||||||
|
}
|
||||||
|
|
||||||
public static void runInThread(Runnable runnable, int threadCount) throws Exception {
|
public static void runInThread(Runnable runnable, int threadCount) throws Exception {
|
||||||
Thread[] threads = new Thread[threadCount];
|
Thread[] threads = new Thread[threadCount];
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,14 @@ public interface ConfigurationMapper {
|
||||||
@Insert("INSERT INTO CONFIGURATION(ENFORCE_SECURITY) VALUES (#{securityEnabled})")
|
@Insert("INSERT INTO CONFIGURATION(ENFORCE_SECURITY) VALUES (#{securityEnabled})")
|
||||||
void setSecurityEnabled(@Param("securityEnabled") boolean securityEnabled);
|
void setSecurityEnabled(@Param("securityEnabled") boolean securityEnabled);
|
||||||
|
|
||||||
@Select("SELECT CUSTOM_ATTRIBUTES FROM CONFIGURATION")
|
@Select(
|
||||||
Map<String, Object> getAllCustomAttributes();
|
"<script> SELECT CUSTOM_ATTRIBUTES FROM CONFIGURATION "
|
||||||
|
+ "<if test='lockForUpdate == true'>"
|
||||||
|
+ "FETCH FIRST ROW ONLY FOR UPDATE "
|
||||||
|
+ "<if test=\"_databaseId == 'db2'\">WITH RS USE AND KEEP UPDATE LOCKS </if> "
|
||||||
|
+ "</if>"
|
||||||
|
+ "</script>")
|
||||||
|
Map<String, Object> getAllCustomAttributes(boolean lockForUpdate);
|
||||||
|
|
||||||
@Update("UPDATE CONFIGURATION SET CUSTOM_ATTRIBUTES = #{customAttributes}")
|
@Update("UPDATE CONFIGURATION SET CUSTOM_ATTRIBUTES = #{customAttributes}")
|
||||||
void setAllCustomAttributes(@Param("customAttributes") Map<String, ?> customAttributes);
|
void setAllCustomAttributes(@Param("customAttributes") Map<String, ?> customAttributes);
|
||||||
|
|
|
@ -47,7 +47,7 @@ public class ConfigurationServiceImpl implements ConfigurationService {
|
||||||
internalTaskanaEngine.executeInDatabaseConnection(
|
internalTaskanaEngine.executeInDatabaseConnection(
|
||||||
CheckedRunnable.wrap(
|
CheckedRunnable.wrap(
|
||||||
() -> {
|
() -> {
|
||||||
if (mapper.getAllCustomAttributes() == null) {
|
if (mapper.getAllCustomAttributes(true) == null) {
|
||||||
if (LOGGER.isDebugEnabled()) {
|
if (LOGGER.isDebugEnabled()) {
|
||||||
LOGGER.debug("custom attributes are not set. Setting default value");
|
LOGGER.debug("custom attributes are not set. Setting default value");
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,8 @@ public class ConfigurationServiceImpl implements ConfigurationService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> getAllCustomAttributes() {
|
public Map<String, Object> getAllCustomAttributes() {
|
||||||
return internalTaskanaEngine.executeInDatabaseConnection(mapper::getAllCustomAttributes);
|
return internalTaskanaEngine.executeInDatabaseConnection(
|
||||||
|
() -> mapper.getAllCustomAttributes(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class ConfigurationServiceImplAccTest {
|
||||||
ConfigurationServiceImpl.class, "defaultCustomAttributes.json"))
|
ConfigurationServiceImpl.class, "defaultCustomAttributes.json"))
|
||||||
.toMap();
|
.toMap();
|
||||||
|
|
||||||
Map<String, Object> allCustomAttributes = configurationMapper.getAllCustomAttributes();
|
Map<String, Object> allCustomAttributes = configurationMapper.getAllCustomAttributes(false);
|
||||||
|
|
||||||
assertThat(allCustomAttributes).isEqualTo(expectedCustomAttributes);
|
assertThat(allCustomAttributes).isEqualTo(expectedCustomAttributes);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue