Merge branch 'master' of github.com:thingsboard/thingsboard
This commit is contained in:
commit
db6c1075eb
@ -30,6 +30,10 @@ public interface Dao<T> {
|
|||||||
|
|
||||||
ListenableFuture<T> findByIdAsync(TenantId tenantId, UUID id);
|
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);
|
T save(TenantId tenantId, T t);
|
||||||
|
|
||||||
boolean removeById(TenantId tenantId, UUID id);
|
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)));
|
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
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public boolean removeById(TenantId tenantId, UUID id) {
|
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.service.AbstractServiceTest;
|
||||||
import org.thingsboard.server.dao.tenant.TenantDao;
|
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;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -75,4 +76,19 @@ public class JpaTenantDaoTest extends AbstractJpaDaoTest {
|
|||||||
tenantDao.save(AbstractServiceTest.SYSTEM_TENANT_ID, tenant);
|
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