Browse Source

Remove device from cache in case null value cached in the distributed redis

pull/4088/head
Volodymyr Babak 6 years ago
committed by Andrew Shvayka
parent
commit
5391d296f3
  1. 14
      dao/src/main/java/org/thingsboard/server/dao/device/DeviceServiceImpl.java

14
dao/src/main/java/org/thingsboard/server/dao/device/DeviceServiceImpl.java

@ -203,6 +203,8 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
} catch (Exception t) { } catch (Exception t) {
ConstraintViolationException e = extractConstraintViolationException(t).orElse(null); ConstraintViolationException e = extractConstraintViolationException(t).orElse(null);
if (e != null && e.getConstraintName() != null && e.getConstraintName().equalsIgnoreCase("device_name_unq_key")) { if (e != null && e.getConstraintName() != null && e.getConstraintName().equalsIgnoreCase("device_name_unq_key")) {
// remove device from cache in case null value cached in the distributed redis.
removeDeviceFromCache(device.getTenantId(), device.getName());
throw new DataValidationException("Device with such name already exists!"); throw new DataValidationException("Device with such name already exists!");
} else { } else {
throw t; throw t;
@ -281,13 +283,17 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
} }
deleteEntityRelations(tenantId, deviceId); deleteEntityRelations(tenantId, deviceId);
removeDeviceFromCache(tenantId, device.getName());
deviceDao.removeById(tenantId, deviceId.getId());
}
private void removeDeviceFromCache(TenantId tenantId, String name) {
List<Object> list = new ArrayList<>(); List<Object> list = new ArrayList<>();
list.add(device.getTenantId()); list.add(tenantId);
list.add(device.getName()); list.add(name);
Cache cache = cacheManager.getCache(DEVICE_CACHE); Cache cache = cacheManager.getCache(DEVICE_CACHE);
cache.evict(list); cache.evict(list);
deviceDao.removeById(tenantId, deviceId.getId());
} }
@Override @Override

Loading…
Cancel
Save