Commit a58db6b7ecaa36d1d4b86be5e79ec1c736486f91

Authored by YevhenBondarenko
Committed by Andrew Shvayka
1 parent 0ed07256

added query delete to JavaAttributeDao

... ... @@ -15,9 +15,11 @@
15 15 */
16 16 package org.thingsboard.server.dao.sql.attributes;
17 17
  18 +import org.springframework.data.jpa.repository.Modifying;
18 19 import org.springframework.data.jpa.repository.Query;
19 20 import org.springframework.data.repository.CrudRepository;
20 21 import org.springframework.data.repository.query.Param;
  22 +import org.springframework.transaction.annotation.Transactional;
21 23 import org.thingsboard.server.common.data.EntityType;
22 24 import org.thingsboard.server.dao.model.sql.AttributeKvCompositeKey;
23 25 import org.thingsboard.server.dao.model.sql.AttributeKvEntity;
... ... @@ -34,5 +36,16 @@ public interface AttributeKvRepository extends CrudRepository<AttributeKvEntity,
34 36 List<AttributeKvEntity> findAllByEntityTypeAndEntityIdAndAttributeType(@Param("entityType") EntityType entityType,
35 37 @Param("entityId") String entityId,
36 38 @Param("attributeType") String attributeType);
  39 +
  40 + @Transactional
  41 + @Modifying
  42 + @Query("DELETE FROM AttributeKvEntity a WHERE a.id.entityType = :entityType " +
  43 + "AND a.id.entityId = :entityId " +
  44 + "AND a.id.attributeType = :attributeType " +
  45 + "AND a.id.attributeKey = :attributeKey")
  46 + void delete(@Param("entityType") EntityType entityType,
  47 + @Param("entityId") String entityId,
  48 + @Param("attributeType") String attributeType,
  49 + @Param("attributeKey") String attributeKey);
37 50 }
38 51
... ...
... ... @@ -138,16 +138,10 @@ public class JpaAttributeDao extends JpaAbstractDaoListeningExecutorService impl
138 138
139 139 @Override
140 140 public ListenableFuture<List<Void>> removeAll(TenantId tenantId, EntityId entityId, String attributeType, List<String> keys) {
141   - List<AttributeKvEntity> entitiesToDelete = keys
142   - .stream()
143   - .map(key -> {
144   - AttributeKvEntity entityToDelete = new AttributeKvEntity();
145   - entityToDelete.setId(new AttributeKvCompositeKey(entityId.getEntityType(), fromTimeUUID(entityId.getId()), attributeType, key));
146   - return entityToDelete;
147   - }).collect(Collectors.toList());
148   -
149 141 return service.submit(() -> {
150   - attributeKvRepository.deleteAll(entitiesToDelete);
  142 + keys.forEach(key ->
  143 + attributeKvRepository.delete(entityId.getEntityType(), UUIDConverter.fromTimeUUID(entityId.getId()), attributeType, key)
  144 + );
151 145 return null;
152 146 });
153 147 }
... ...