Browse Source

Entity View Cache

pull/6536/head
Andrii Shvaika 4 years ago
parent
commit
0ff53a928d
  1. 63
      dao/src/main/java/org/thingsboard/server/dao/entityview/EntityViewCacheKey.java
  2. 40
      dao/src/main/java/org/thingsboard/server/dao/entityview/EntityViewCacheValue.java
  3. 34
      dao/src/main/java/org/thingsboard/server/dao/entityview/EntityViewCaffeineCache.java
  4. 2
      dao/src/main/java/org/thingsboard/server/dao/entityview/EntityViewDao.java
  5. 35
      dao/src/main/java/org/thingsboard/server/dao/entityview/EntityViewEvictEvent.java
  6. 50
      dao/src/main/java/org/thingsboard/server/dao/entityview/EntityViewRedisCache.java
  7. 104
      dao/src/main/java/org/thingsboard/server/dao/entityview/EntityViewServiceImpl.java
  8. 6
      dao/src/main/java/org/thingsboard/server/dao/sql/entityview/JpaEntityViewDao.java
  9. 15
      dao/src/main/java/org/thingsboard/server/dao/tenant/TenantProfileCacheKey.java
  10. 15
      dao/src/main/java/org/thingsboard/server/dao/tenant/TenantProfileEvictEvent.java
  11. 2
      dao/src/main/java/org/thingsboard/server/dao/tenant/TenantProfileRedisCache.java
  12. 2
      dao/src/main/java/org/thingsboard/server/dao/tenant/TenantProfileServiceImpl.java

63
dao/src/main/java/org/thingsboard/server/dao/entityview/EntityViewCacheKey.java

@ -0,0 +1,63 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.dao.entityview;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.thingsboard.server.cache.CacheKeyUtil;
import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.id.EntityViewId;
import org.thingsboard.server.common.data.id.TenantId;
import java.io.Serializable;
@Getter
@EqualsAndHashCode
@Builder
public class EntityViewCacheKey implements Serializable {
private final TenantId tenantId;
private final String name;
private final EntityId entityId;
private final EntityViewId entityViewId;
private EntityViewCacheKey(TenantId tenantId, String name, EntityId entityId, EntityViewId entityViewId) {
this.tenantId = tenantId;
this.name = name;
this.entityId = entityId;
this.entityViewId = entityViewId;
}
public static EntityViewCacheKey byName(TenantId tenantId, String name) {
return new EntityViewCacheKey(tenantId, name, null, null);
}
public static EntityViewCacheKey byEntityId(TenantId tenantId, EntityId entityId) {
return new EntityViewCacheKey(tenantId, null, entityId, null);
}
public static EntityViewCacheKey byId(EntityViewId id) {
return new EntityViewCacheKey(null, null, null, id);
}
@Override
public String toString() {
return CacheKeyUtil.toString(tenantId, name, entityId, entityViewId);
}
}

40
dao/src/main/java/org/thingsboard/server/dao/entityview/EntityViewCacheValue.java

@ -0,0 +1,40 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.dao.entityview;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.thingsboard.server.cache.CacheKeyUtil;
import org.thingsboard.server.common.data.EntityView;
import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.id.EntityViewId;
import org.thingsboard.server.common.data.id.TenantId;
import java.io.Serializable;
import java.util.List;
@Getter
@EqualsAndHashCode
@Builder
public class EntityViewCacheValue implements Serializable {
private static final long serialVersionUID = 1959004642076413174L;
private final EntityView entityView;
private final List<EntityView> entityViews;
}

34
dao/src/main/java/org/thingsboard/server/dao/entityview/EntityViewCaffeineCache.java

@ -0,0 +1,34 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.dao.entityview;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Service;
import org.thingsboard.server.common.data.CacheConstants;
import org.thingsboard.server.common.data.asset.Asset;
import org.thingsboard.server.dao.asset.AssetCacheKey;
import org.thingsboard.server.dao.cache.CaffeineTbTransactionalCache;
@ConditionalOnProperty(prefix = "cache", value = "type", havingValue = "caffeine", matchIfMissing = true)
@Service("EntityViewCache")
public class EntityViewCaffeineCache extends CaffeineTbTransactionalCache<EntityViewCacheKey, EntityViewCacheValue> {
public EntityViewCaffeineCache(CacheManager cacheManager) {
super(cacheManager, CacheConstants.ENTITY_VIEW_CACHE);
}
}

2
dao/src/main/java/org/thingsboard/server/dao/entityview/EntityViewDao.java

@ -144,7 +144,7 @@ public interface EntityViewDao extends Dao<EntityView> {
*/ */
PageData<EntityViewInfo> findEntityViewInfosByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, PageLink pageLink); PageData<EntityViewInfo> findEntityViewInfosByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, PageLink pageLink);
ListenableFuture<List<EntityView>> findEntityViewsByTenantIdAndEntityIdAsync(UUID tenantId, UUID entityId); List<EntityView> findEntityViewsByTenantIdAndEntityId(UUID tenantId, UUID entityId);
/** /**
* Find tenants entity view types. * Find tenants entity view types.

35
dao/src/main/java/org/thingsboard/server/dao/entityview/EntityViewEvictEvent.java

@ -0,0 +1,35 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.dao.entityview;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.id.EntityViewId;
import org.thingsboard.server.common.data.id.TenantId;
@Data
@RequiredArgsConstructor
class EntityViewEvictEvent {
private final TenantId tenantId;
private final EntityViewId id;
private final EntityId newEntityId;
private final EntityId oldEntityId;
private final String newName;
private final String oldName;
}

50
dao/src/main/java/org/thingsboard/server/dao/entityview/EntityViewRedisCache.java

@ -0,0 +1,50 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.dao.entityview;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.SerializationException;
import org.springframework.stereotype.Service;
import org.thingsboard.server.cache.CacheSpecsMap;
import org.thingsboard.server.cache.TBRedisCacheConfiguration;
import org.thingsboard.server.common.data.CacheConstants;
import org.thingsboard.server.common.data.asset.Asset;
import org.thingsboard.server.dao.asset.AssetCacheKey;
import org.thingsboard.server.dao.cache.RedisTbTransactionalCache;
@ConditionalOnProperty(prefix = "cache", value = "type", havingValue = "redis")
@Service("EntityViewCache")
public class EntityViewRedisCache extends RedisTbTransactionalCache<EntityViewCacheKey, EntityViewCacheValue> {
public EntityViewRedisCache(TBRedisCacheConfiguration configuration, CacheSpecsMap cacheSpecsMap, RedisConnectionFactory connectionFactory) {
super(CacheConstants.ENTITY_VIEW_CACHE, cacheSpecsMap, connectionFactory, configuration, new RedisSerializer<>() {
private final RedisSerializer<Object> java = RedisSerializer.java();
@Override
public byte[] serialize(EntityViewCacheValue attributeKvEntry) throws SerializationException {
return java.serialize(attributeKvEntry);
}
@Override
public EntityViewCacheValue deserialize(byte[] bytes) throws SerializationException {
return (EntityViewCacheValue) java.deserialize(bytes);
}
});
}
}

104
dao/src/main/java/org/thingsboard/server/dao/entityview/EntityViewServiceImpl.java

@ -16,20 +16,20 @@
package org.thingsboard.server.dao.entityview; package org.thingsboard.server.dao.entityview;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.MoreExecutors;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.event.TransactionalEventListener;
import org.thingsboard.server.common.data.EntitySubtype; import org.thingsboard.server.common.data.EntitySubtype;
import org.thingsboard.server.common.data.EntityType; import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.EntityView; import org.thingsboard.server.common.data.EntityView;
import org.thingsboard.server.common.data.EntityViewInfo; import org.thingsboard.server.common.data.EntityViewInfo;
import org.thingsboard.server.common.data.StringUtils;
import org.thingsboard.server.common.data.edge.Edge; import org.thingsboard.server.common.data.edge.Edge;
import org.thingsboard.server.common.data.entityview.EntityViewSearchQuery; import org.thingsboard.server.common.data.entityview.EntityViewSearchQuery;
import org.thingsboard.server.common.data.id.CustomerId; import org.thingsboard.server.common.data.id.CustomerId;
@ -42,22 +42,20 @@ import org.thingsboard.server.common.data.page.PageLink;
import org.thingsboard.server.common.data.relation.EntityRelation; import org.thingsboard.server.common.data.relation.EntityRelation;
import org.thingsboard.server.common.data.relation.EntitySearchDirection; import org.thingsboard.server.common.data.relation.EntitySearchDirection;
import org.thingsboard.server.common.data.relation.RelationTypeGroup; import org.thingsboard.server.common.data.relation.RelationTypeGroup;
import org.thingsboard.server.dao.entity.AbstractEntityService; import org.thingsboard.server.dao.entity.AbstractCachedEntityService;
import org.thingsboard.server.dao.exception.DataValidationException; import org.thingsboard.server.dao.exception.DataValidationException;
import org.thingsboard.server.dao.service.DataValidator; import org.thingsboard.server.dao.service.DataValidator;
import org.thingsboard.server.dao.service.PaginatedRemover; import org.thingsboard.server.dao.service.PaginatedRemover;
import org.thingsboard.server.dao.sql.JpaExecutorService;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.thingsboard.server.common.data.CacheConstants.ENTITY_VIEW_CACHE;
import static org.thingsboard.server.dao.service.Validator.validateId; import static org.thingsboard.server.dao.service.Validator.validateId;
import static org.thingsboard.server.dao.service.Validator.validatePageLink; import static org.thingsboard.server.dao.service.Validator.validatePageLink;
import static org.thingsboard.server.dao.service.Validator.validateString; import static org.thingsboard.server.dao.service.Validator.validateString;
@ -67,7 +65,7 @@ import static org.thingsboard.server.dao.service.Validator.validateString;
*/ */
@Service @Service
@Slf4j @Slf4j
public class EntityViewServiceImpl extends AbstractEntityService implements EntityViewService { public class EntityViewServiceImpl extends AbstractCachedEntityService<EntityViewCacheKey, EntityViewCacheValue, EntityViewEvictEvent> implements EntityViewService {
public static final String INCORRECT_TENANT_ID = "Incorrect tenantId "; public static final String INCORRECT_TENANT_ID = "Incorrect tenantId ";
public static final String INCORRECT_PAGE_LINK = "Incorrect page link "; public static final String INCORRECT_PAGE_LINK = "Incorrect page link ";
@ -79,40 +77,54 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti
private EntityViewDao entityViewDao; private EntityViewDao entityViewDao;
@Autowired @Autowired
private CacheManager cacheManager; private DataValidator<EntityView> entityViewValidator;
@Autowired @Autowired
private DataValidator<EntityView> entityViewValidator; protected JpaExecutorService service;
@TransactionalEventListener(classes = EntityViewEvictEvent.class)
@Override @Override
public EntityView saveEntityView(EntityView entityView) { public void handleEvictEvent(EntityViewEvictEvent event) {
log.trace("Executing save entity view [{}]", entityView); List<EntityViewCacheKey> keys = new ArrayList<>(5);
entityViewValidator.validate(entityView, EntityView::getTenantId); keys.add(EntityViewCacheKey.byName(event.getTenantId(), event.getNewName()));
keys.add(EntityViewCacheKey.byId(event.getId()));
if (entityView.getId() != null) { keys.add(EntityViewCacheKey.byEntityId(event.getTenantId(), event.getNewEntityId()));
EntityView oldEntityView = entityViewDao.findById(entityView.getTenantId(), entityView.getUuidId()); if (event.getOldEntityId() != null && !event.getOldEntityId().equals(event.getNewEntityId())) {
evictCache(oldEntityView); keys.add(EntityViewCacheKey.byEntityId(event.getTenantId(), event.getOldEntityId()));
}
if (StringUtils.isNotEmpty(event.getOldName()) && !event.getOldName().equals(event.getNewName())) {
keys.add(EntityViewCacheKey.byName(event.getTenantId(), event.getOldName()));
} }
cache.evict(keys);
}
return entityViewDao.save(entityView.getTenantId(), entityView); @Transactional(propagation = Propagation.SUPPORTS)
@Override
public EntityView saveEntityView(EntityView entityView) {
log.trace("Executing save entity view [{}]", entityView);
EntityView old = entityViewValidator.validate(entityView, EntityView::getTenantId);
EntityView saved = entityViewDao.save(entityView.getTenantId(), entityView);
publishEvictEvent(new EntityViewEvictEvent(saved.getTenantId(), saved.getId(), saved.getEntityId(), old != null ? old.getEntityId() : null, saved.getName(), old != null ? old.getName() : null));
return saved;
} }
@Transactional(propagation = Propagation.SUPPORTS)
@Override @Override
public EntityView assignEntityViewToCustomer(TenantId tenantId, EntityViewId entityViewId, CustomerId customerId) { public EntityView assignEntityViewToCustomer(TenantId tenantId, EntityViewId entityViewId, CustomerId customerId) {
EntityView entityView = findEntityViewById(tenantId, entityViewId); EntityView entityView = findEntityViewById(tenantId, entityViewId);
evictCache(entityView);
entityView.setCustomerId(customerId); entityView.setCustomerId(customerId);
return saveEntityView(entityView); return saveEntityView(entityView);
} }
@Transactional(propagation = Propagation.SUPPORTS)
@Override @Override
public EntityView unassignEntityViewFromCustomer(TenantId tenantId, EntityViewId entityViewId) { public EntityView unassignEntityViewFromCustomer(TenantId tenantId, EntityViewId entityViewId) {
EntityView entityView = findEntityViewById(tenantId, entityViewId); EntityView entityView = findEntityViewById(tenantId, entityViewId);
evictCache(entityView);
entityView.setCustomerId(null); entityView.setCustomerId(null);
return saveEntityView(entityView); return saveEntityView(entityView);
} }
@Transactional(propagation = Propagation.SUPPORTS)
@Override @Override
public void unassignCustomerEntityViews(TenantId tenantId, CustomerId customerId) { public void unassignCustomerEntityViews(TenantId tenantId, CustomerId customerId) {
log.trace("Executing unassignCustomerEntityViews, tenantId [{}], customerId [{}]", tenantId, customerId); log.trace("Executing unassignCustomerEntityViews, tenantId [{}], customerId [{}]", tenantId, customerId);
@ -128,21 +140,23 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti
return entityViewDao.findEntityViewInfoById(tenantId, entityViewId.getId()); return entityViewDao.findEntityViewInfoById(tenantId, entityViewId.getId());
} }
@Cacheable(cacheNames = ENTITY_VIEW_CACHE, key = "{#entityViewId}")
@Override @Override
public EntityView findEntityViewById(TenantId tenantId, EntityViewId entityViewId) { public EntityView findEntityViewById(TenantId tenantId, EntityViewId entityViewId) {
log.trace("Executing findEntityViewById [{}]", entityViewId); log.trace("Executing findEntityViewById [{}]", entityViewId);
validateId(entityViewId, INCORRECT_ENTITY_VIEW_ID + entityViewId); validateId(entityViewId, INCORRECT_ENTITY_VIEW_ID + entityViewId);
return entityViewDao.findById(tenantId, entityViewId.getId()); return cache.getAndPutInTransaction(EntityViewCacheKey.byId(entityViewId),
() -> entityViewDao.findById(tenantId, entityViewId.getId())
, EntityViewCacheValue::getEntityView, v -> new EntityViewCacheValue(v, null), true);
} }
@Cacheable(cacheNames = ENTITY_VIEW_CACHE, key = "{#tenantId, #name}")
@Override @Override
public EntityView findEntityViewByTenantIdAndName(TenantId tenantId, String name) { public EntityView findEntityViewByTenantIdAndName(TenantId tenantId, String name) {
log.trace("Executing findEntityViewByTenantIdAndName [{}][{}]", tenantId, name); log.trace("Executing findEntityViewByTenantIdAndName [{}][{}]", tenantId, name);
validateId(tenantId, INCORRECT_TENANT_ID + tenantId); validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
Optional<EntityView> entityViewOpt = entityViewDao.findEntityViewByTenantIdAndName(tenantId.getId(), name); return cache.getAndPutInTransaction(EntityViewCacheKey.byName(tenantId, name),
return entityViewOpt.orElse(null); () -> entityViewDao.findEntityViewByTenantIdAndName(tenantId.getId(), name).orElse(null)
, EntityViewCacheValue::getEntityView, v -> new EntityViewCacheValue(v, null), true);
} }
@Override @Override
@ -265,41 +279,20 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti
validateId(tenantId, INCORRECT_TENANT_ID + tenantId); validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
validateId(entityId.getId(), "Incorrect entityId" + entityId); validateId(entityId.getId(), "Incorrect entityId" + entityId);
List<Object> tenantIdAndEntityId = new ArrayList<>(); return service.submit(() -> cache.getAndPutInTransaction(EntityViewCacheKey.byEntityId(tenantId, entityId),
tenantIdAndEntityId.add(tenantId); () -> entityViewDao.findEntityViewsByTenantIdAndEntityId(tenantId.getId(), entityId.getId()),
tenantIdAndEntityId.add(entityId); EntityViewCacheValue::getEntityViews, v -> new EntityViewCacheValue(null, v), true));
Cache cache = cacheManager.getCache(ENTITY_VIEW_CACHE);
@SuppressWarnings("unchecked")
List<EntityView> fromCache = cache.get(tenantIdAndEntityId, List.class);
if (fromCache != null) {
return Futures.immediateFuture(fromCache);
} else {
ListenableFuture<List<EntityView>> entityViewsFuture = entityViewDao.findEntityViewsByTenantIdAndEntityIdAsync(tenantId.getId(), entityId.getId());
Futures.addCallback(entityViewsFuture,
new FutureCallback<List<EntityView>>() {
@Override
public void onSuccess(@Nullable List<EntityView> result) {
cache.putIfAbsent(tenantIdAndEntityId, result);
}
@Override
public void onFailure(Throwable t) {
log.error("Error while finding entity views by tenantId and entityId", t);
}
}, MoreExecutors.directExecutor());
return entityViewsFuture;
}
} }
@Transactional(propagation = Propagation.SUPPORTS)
@Override @Override
public void deleteEntityView(TenantId tenantId, EntityViewId entityViewId) { public void deleteEntityView(TenantId tenantId, EntityViewId entityViewId) {
log.trace("Executing deleteEntityView [{}]", entityViewId); log.trace("Executing deleteEntityView [{}]", entityViewId);
validateId(entityViewId, INCORRECT_ENTITY_VIEW_ID + entityViewId); validateId(entityViewId, INCORRECT_ENTITY_VIEW_ID + entityViewId);
deleteEntityRelations(tenantId, entityViewId); deleteEntityRelations(tenantId, entityViewId);
EntityView entityView = entityViewDao.findById(tenantId, entityViewId.getId()); EntityView entityView = entityViewDao.findById(tenantId, entityViewId.getId());
evictCache(entityView);
entityViewDao.removeById(tenantId, entityViewId.getId()); entityViewDao.removeById(tenantId, entityViewId.getId());
publishEvictEvent(new EntityViewEvictEvent(entityView.getTenantId(), entityView.getId(), entityView.getEntityId(), null, entityView.getName(), null));
} }
@Override @Override
@ -410,11 +403,4 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti
unassignEntityViewFromCustomer(tenantId, new EntityViewId(entity.getUuidId())); unassignEntityViewFromCustomer(tenantId, new EntityViewId(entity.getUuidId()));
} }
}; };
private void evictCache(EntityView entityView) {
Cache cache = cacheManager.getCache(ENTITY_VIEW_CACHE);
cache.evict(Arrays.asList(entityView.getTenantId(), entityView.getEntityId()));
cache.evict(Arrays.asList(entityView.getTenantId(), entityView.getName()));
cache.evict(Arrays.asList(entityView.getId()));
}
} }

6
dao/src/main/java/org/thingsboard/server/dao/sql/entityview/JpaEntityViewDao.java

@ -157,9 +157,9 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity,
} }
@Override @Override
public ListenableFuture<List<EntityView>> findEntityViewsByTenantIdAndEntityIdAsync(UUID tenantId, UUID entityId) { public List<EntityView> findEntityViewsByTenantIdAndEntityId(UUID tenantId, UUID entityId) {
return service.submit(() -> DaoUtil.convertDataList( return DaoUtil.convertDataList(
entityViewRepository.findAllByTenantIdAndEntityId(tenantId, entityId))); entityViewRepository.findAllByTenantIdAndEntityId(tenantId, entityId));
} }
@Override @Override

15
dao/src/main/java/org/thingsboard/server/dao/tenant/TenantProfileCacheKey.java

@ -1,3 +1,18 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.dao.tenant; package org.thingsboard.server.dao.tenant;
import lombok.Data; import lombok.Data;

15
dao/src/main/java/org/thingsboard/server/dao/tenant/TenantProfileEvictEvent.java

@ -1,3 +1,18 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.dao.tenant; package org.thingsboard.server.dao.tenant;
import lombok.Data; import lombok.Data;

2
dao/src/main/java/org/thingsboard/server/dao/tenant/TenantProfileRedisCache.java

@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,

2
dao/src/main/java/org/thingsboard/server/dao/tenant/TenantProfileServiceImpl.java

@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,

Loading…
Cancel
Save