dao: existsById, existsByIdAsync added
This commit is contained in:
parent
76a8f32c21
commit
753371cc2e
@ -30,6 +30,10 @@ public interface Dao<T> {
|
||||
|
||||
ListenableFuture<T> findByIdAsync(TenantId tenantId, UUID id);
|
||||
|
||||
boolean existsById(TenantId tenantId, UUID id);
|
||||
|
||||
ListenableFuture<Boolean> existsByIdAsync(TenantId tenantId, UUID id);
|
||||
|
||||
T save(TenantId tenantId, T t);
|
||||
|
||||
boolean removeById(TenantId tenantId, UUID id);
|
||||
|
||||
@ -80,6 +80,18 @@ public abstract class JpaAbstractDao<E extends BaseEntity<D>, D>
|
||||
return service.submit(() -> DaoUtil.getData(getCrudRepository().findById(key)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsById(TenantId tenantId, UUID key) {
|
||||
log.debug("Exists by key {}", key);
|
||||
return getCrudRepository().existsById(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListenableFuture<Boolean> existsByIdAsync(TenantId tenantId, UUID key) {
|
||||
log.debug("Exists by key async {}", key);
|
||||
return service.submit(() -> getCrudRepository().existsById(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean removeById(TenantId tenantId, UUID id) {
|
||||
|
||||
@ -27,8 +27,9 @@ import org.thingsboard.server.dao.AbstractJpaDaoTest;
|
||||
import org.thingsboard.server.dao.service.AbstractServiceTest;
|
||||
import org.thingsboard.server.dao.tenant.TenantDao;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
@ -75,4 +76,19 @@ public class JpaTenantDaoTest extends AbstractJpaDaoTest {
|
||||
tenantDao.save(AbstractServiceTest.SYSTEM_TENANT_ID, tenant);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DatabaseSetup("classpath:dbunit/empty_dataset.xml")
|
||||
public void testIsExistsTenantById() {
|
||||
final UUID uuid = Uuids.timeBased();
|
||||
final TenantId tenantId = new TenantId(uuid);
|
||||
assertThat(tenantDao.existsById(tenantId, uuid)).as("Is tenant exists before save").isFalse();
|
||||
|
||||
final Tenant tenant = new Tenant();
|
||||
tenant.setId(tenantId);
|
||||
tenant.setTitle("Tenant " + uuid);
|
||||
tenantDao.save(AbstractServiceTest.SYSTEM_TENANT_ID, tenant);
|
||||
|
||||
assertThat(tenantDao.existsById(tenantId, uuid)).as("Is tenant exists after save").isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user