fixed delete attributes query

This commit is contained in:
YevhenBondarenko 2024-07-02 12:38:07 +02:00
parent 6162060e88
commit 7fa7528546
2 changed files with 8 additions and 5 deletions

View File

@ -35,10 +35,10 @@ public interface AttributeKvRepository extends JpaRepository<AttributeKvEntity,
@Transactional
@Modifying
@Query(value = "DELETE FROM attribute_kv WHERE entity_id = :entityId " +
"AND attribute_type = :attributeType " +
"AND attribute_key = :attributeKey RETURNING nextval('attribute_kv_version_seq')", nativeQuery = true)
Long delete(@Param("entityId") UUID entityId,
@Query("DELETE FROM AttributeKvEntity a WHERE a.id.entityId = :entityId " +
"AND a.id.attributeType = :attributeType " +
"AND a.id.attributeKey = :attributeKey")
void delete(@Param("entityId") UUID entityId,
@Param("attributeType") int attributeType,
@Param("attributeKey") int attributeKey);

View File

@ -206,12 +206,15 @@ public class JpaAttributeDao extends JpaAbstractDaoListeningExecutorService impl
return futuresList;
}
@Transactional
@Override
public List<ListenableFuture<TbPair<String, Long>>> removeAllWithVersions(TenantId tenantId, EntityId entityId, AttributeScope attributeScope, List<String> keys) {
List<ListenableFuture<TbPair<String, Long>>> futuresList = new ArrayList<>(keys.size());
for (String key : keys) {
futuresList.add(service.submit(() -> {
Long version = attributeKvRepository.delete(entityId.getId(), attributeScope.getId(), keyDictionaryDao.getOrSaveKeyId(key));
Long version = jdbcTemplate.query("DELETE FROM attribute_kv WHERE entity_id = ? AND attribute_type = ? " +
"AND attribute_key = ? RETURNING nextval('attribute_kv_version_seq')",
rs -> rs.next() ? rs.getLong(1) : null, entityId.getId(), attributeScope.getId(), keyDictionaryDao.getOrSaveKeyId(key));
return TbPair.of(key, version);
}));
}