[3.3.2] Fix bug while deleting devices with relations to one another (#5310)
* Fix bug while deleting devices with relations to one another * Change log level from error to debug * Made try catch block more precise
This commit is contained in:
parent
69e2f0c115
commit
0026857e27
@ -27,6 +27,7 @@ import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.Caching;
|
||||
import org.springframework.dao.ConcurrencyFailureException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
@ -201,6 +202,7 @@ public class BaseRelationService implements RelationService {
|
||||
}
|
||||
|
||||
relationDao.deleteOutboundRelations(tenantId, entityId);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -262,11 +264,14 @@ public class BaseRelationService implements RelationService {
|
||||
boolean delete(TenantId tenantId, Cache cache, EntityRelation relation, boolean deleteFromDb) {
|
||||
cacheEviction(relation, cache);
|
||||
if (deleteFromDb) {
|
||||
try {
|
||||
return relationDao.deleteRelation(tenantId, relation);
|
||||
} else {
|
||||
return false;
|
||||
} catch (ConcurrencyFailureException e) {
|
||||
log.debug("Concurrency exception while deleting relations [{}]", relation, e);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void cacheEviction(EntityRelation relation, Cache cache) {
|
||||
List<Object> fromToTypeAndTypeGroup = new ArrayList<>();
|
||||
|
||||
@ -18,6 +18,7 @@ package org.thingsboard.server.dao.sql.relation;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.ConcurrencyFailureException;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
@ -163,12 +164,17 @@ public class JpaRelationDao extends JpaAbstractDaoListeningExecutorService imple
|
||||
|
||||
@Override
|
||||
public boolean deleteOutboundRelations(TenantId tenantId, EntityId entity) {
|
||||
boolean relationExistsBeforeDelete = relationRepository
|
||||
boolean relationExistsBeforeDelete = false;
|
||||
try {
|
||||
relationExistsBeforeDelete = relationRepository
|
||||
.findAllByFromIdAndFromType(entity.getId(), entity.getEntityType().name())
|
||||
.size() > 0;
|
||||
if (relationExistsBeforeDelete) {
|
||||
relationRepository.deleteByFromIdAndFromType(entity.getId(), entity.getEntityType().name());
|
||||
}
|
||||
} catch (ConcurrencyFailureException e) {
|
||||
log.debug("Concurrency exception while deleting relations [{}]", entity, e);
|
||||
}
|
||||
return relationExistsBeforeDelete;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user