Merge pull request #11371 from thingsboard/fix/key-dictionary-transactional

Fix zero attribute key
This commit is contained in:
Viacheslav Klimov 2024-08-06 19:42:18 +03:00 committed by GitHub
commit af0b367f7b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -15,11 +15,13 @@
*/
package org.thingsboard.server.dao.sqlts.dictionary;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.exception.ConstraintViolationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.thingsboard.server.dao.dictionary.KeyDictionaryDao;
import org.thingsboard.server.dao.model.sqlts.dictionary.KeyDictionaryCompositeKey;
import org.thingsboard.server.dao.model.sqlts.dictionary.KeyDictionaryEntry;
@ -34,14 +36,15 @@ import java.util.concurrent.locks.ReentrantLock;
@Component
@Slf4j
@SqlDao
@RequiredArgsConstructor
public class JpaKeyDictionaryDao extends JpaAbstractDaoListeningExecutorService implements KeyDictionaryDao {
private final KeyDictionaryRepository keyDictionaryRepository;
private final ConcurrentMap<String, Integer> keyDictionaryMap = new ConcurrentHashMap<>();
protected static final ReentrantLock creationLock = new ReentrantLock();
@Autowired
private KeyDictionaryRepository keyDictionaryRepository;
private static final ReentrantLock creationLock = new ReentrantLock();
@Transactional(propagation = Propagation.NOT_SUPPORTED)
@Override
public Integer getOrSaveKeyId(String strKey) {
Integer keyId = keyDictionaryMap.get(strKey);