Browse Source

removed checks for 0 value

pull/14536/head
dshvaika 10 months ago
parent
commit
2c04943984
  1. 7
      dao/src/main/java/org/thingsboard/server/dao/sqlts/dictionary/JpaKeyDictionaryDao.java

7
dao/src/main/java/org/thingsboard/server/dao/sqlts/dictionary/JpaKeyDictionaryDao.java

@ -51,9 +51,7 @@ public class JpaKeyDictionaryDao extends JpaAbstractDaoListeningExecutorService
return cached; return cached;
} }
var compositeKey = new KeyDictionaryCompositeKey(strKey); var compositeKey = new KeyDictionaryCompositeKey(strKey);
Optional<Integer> existingId = keyDictionaryRepository.findById(compositeKey) Optional<Integer> existingId = keyDictionaryRepository.findById(compositeKey).map(KeyDictionaryEntry::getKeyId);
.map(KeyDictionaryEntry::getKeyId)
.filter(id -> id != 0);
if (existingId.isPresent()) { if (existingId.isPresent()) {
return cacheAndReturn(strKey, existingId.get()); return cacheAndReturn(strKey, existingId.get());
} }
@ -64,13 +62,12 @@ public class JpaKeyDictionaryDao extends JpaAbstractDaoListeningExecutorService
return fromCache; return fromCache;
} }
Integer keyId = keyDictionaryRepository.upsertAndGetKeyId(strKey); Integer keyId = keyDictionaryRepository.upsertAndGetKeyId(strKey);
if (keyId != null && keyId != 0) { if (keyId != null) {
return cacheAndReturn(strKey, keyId); return cacheAndReturn(strKey, keyId);
} }
log.warn("upsertAndGetKeyId returned: [{}] for key: [{}], falling back to findById", keyId, strKey); log.warn("upsertAndGetKeyId returned: [{}] for key: [{}], falling back to findById", keyId, strKey);
keyId = keyDictionaryRepository.findById(compositeKey) keyId = keyDictionaryRepository.findById(compositeKey)
.map(KeyDictionaryEntry::getKeyId) .map(KeyDictionaryEntry::getKeyId)
.filter(id -> id != 0)
.orElseThrow(() -> new IllegalStateException( .orElseThrow(() -> new IllegalStateException(
"Failed to resolve keyId for string key: " + strKey + " after fallback.")); "Failed to resolve keyId for string key: " + strKey + " after fallback."));
return cacheAndReturn(strKey, keyId); return cacheAndReturn(strKey, keyId);

Loading…
Cancel
Save