Search in sources :

Example 1 with EntitySubtypeEntity

use of org.thingsboard.server.dao.model.EntitySubtypeEntity in project thingsboard by thingsboard.

the class CassandraDeviceDao method findTenantDeviceTypesAsync.

@Override
public ListenableFuture<List<EntitySubtype>> findTenantDeviceTypesAsync(UUID tenantId) {
    Select select = select().from(ENTITY_SUBTYPE_COLUMN_FAMILY_NAME);
    Select.Where query = select.where();
    query.and(eq(ENTITY_SUBTYPE_TENANT_ID_PROPERTY, tenantId));
    query.and(eq(ENTITY_SUBTYPE_ENTITY_TYPE_PROPERTY, EntityType.DEVICE));
    query.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel());
    ResultSetFuture resultSetFuture = executeAsyncRead(query);
    return Futures.transform(resultSetFuture, new Function<ResultSet, List<EntitySubtype>>() {

        @Nullable
        @Override
        public List<EntitySubtype> apply(@Nullable ResultSet resultSet) {
            Result<EntitySubtypeEntity> result = cluster.getMapper(EntitySubtypeEntity.class).map(resultSet);
            if (result != null) {
                List<EntitySubtype> entitySubtypes = new ArrayList<>();
                result.all().forEach((entitySubtypeEntity) -> entitySubtypes.add(entitySubtypeEntity.toEntitySubtype()));
                return entitySubtypes;
            } else {
                return Collections.emptyList();
            }
        }
    });
}
Also used : java.util(java.util) QueryBuilder(com.datastax.driver.core.querybuilder.QueryBuilder) Function(com.google.common.base.Function) CassandraAbstractSearchTextDao(org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao) Result(com.datastax.driver.mapping.Result) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) DeviceEntity(org.thingsboard.server.dao.model.nosql.DeviceEntity) Device(org.thingsboard.server.common.data.Device) ResultSetFuture(com.datastax.driver.core.ResultSetFuture) NoSqlDao(org.thingsboard.server.dao.util.NoSqlDao) Futures(com.google.common.util.concurrent.Futures) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) ResultSet(com.datastax.driver.core.ResultSet) EntityType(org.thingsboard.server.common.data.EntityType) DaoUtil(org.thingsboard.server.dao.DaoUtil) EntitySubtypeEntity(org.thingsboard.server.dao.model.EntitySubtypeEntity) Select(com.datastax.driver.core.querybuilder.Select) EntitySubtype(org.thingsboard.server.common.data.EntitySubtype) Statement(com.datastax.driver.core.Statement) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) Nullable(javax.annotation.Nullable) ModelConstants(org.thingsboard.server.dao.model.ModelConstants) ResultSetFuture(com.datastax.driver.core.ResultSetFuture) Select(com.datastax.driver.core.querybuilder.Select) ResultSet(com.datastax.driver.core.ResultSet) Nullable(javax.annotation.Nullable) Result(com.datastax.driver.mapping.Result)

Example 2 with EntitySubtypeEntity

use of org.thingsboard.server.dao.model.EntitySubtypeEntity in project thingsboard by thingsboard.

the class CassandraDeviceDao method save.

@Override
public Device save(Device domain) {
    Device savedDevice = super.save(domain);
    EntitySubtype entitySubtype = new EntitySubtype(savedDevice.getTenantId(), EntityType.DEVICE, savedDevice.getType());
    EntitySubtypeEntity entitySubtypeEntity = new EntitySubtypeEntity(entitySubtype);
    Statement saveStatement = cluster.getMapper(EntitySubtypeEntity.class).saveQuery(entitySubtypeEntity);
    executeWrite(saveStatement);
    return savedDevice;
}
Also used : Device(org.thingsboard.server.common.data.Device) EntitySubtypeEntity(org.thingsboard.server.dao.model.EntitySubtypeEntity) Statement(com.datastax.driver.core.Statement) EntitySubtype(org.thingsboard.server.common.data.EntitySubtype)

Example 3 with EntitySubtypeEntity

use of org.thingsboard.server.dao.model.EntitySubtypeEntity in project thingsboard by thingsboard.

the class CassandraAssetDao method save.

@Override
public Asset save(Asset domain) {
    Asset savedAsset = super.save(domain);
    EntitySubtype entitySubtype = new EntitySubtype(savedAsset.getTenantId(), EntityType.ASSET, savedAsset.getType());
    EntitySubtypeEntity entitySubtypeEntity = new EntitySubtypeEntity(entitySubtype);
    Statement saveStatement = cluster.getMapper(EntitySubtypeEntity.class).saveQuery(entitySubtypeEntity);
    executeWrite(saveStatement);
    return savedAsset;
}
Also used : EntitySubtypeEntity(org.thingsboard.server.dao.model.EntitySubtypeEntity) Statement(com.datastax.driver.core.Statement) Asset(org.thingsboard.server.common.data.asset.Asset) EntitySubtype(org.thingsboard.server.common.data.EntitySubtype)

Example 4 with EntitySubtypeEntity

use of org.thingsboard.server.dao.model.EntitySubtypeEntity in project thingsboard by thingsboard.

the class CassandraAssetDao method findTenantAssetTypesAsync.

@Override
public ListenableFuture<List<EntitySubtype>> findTenantAssetTypesAsync(UUID tenantId) {
    Select select = select().from(ENTITY_SUBTYPE_COLUMN_FAMILY_NAME);
    Select.Where query = select.where();
    query.and(eq(ENTITY_SUBTYPE_TENANT_ID_PROPERTY, tenantId));
    query.and(eq(ENTITY_SUBTYPE_ENTITY_TYPE_PROPERTY, EntityType.ASSET));
    query.setConsistencyLevel(cluster.getDefaultReadConsistencyLevel());
    ResultSetFuture resultSetFuture = executeAsyncRead(query);
    return Futures.transform(resultSetFuture, new Function<ResultSet, List<EntitySubtype>>() {

        @Nullable
        @Override
        public List<EntitySubtype> apply(@Nullable ResultSet resultSet) {
            Result<EntitySubtypeEntity> result = cluster.getMapper(EntitySubtypeEntity.class).map(resultSet);
            if (result != null) {
                List<EntitySubtype> entitySubtypes = new ArrayList<>();
                result.all().forEach((entitySubtypeEntity) -> entitySubtypes.add(entitySubtypeEntity.toEntitySubtype()));
                return entitySubtypes;
            } else {
                return Collections.emptyList();
            }
        }
    });
}
Also used : java.util(java.util) QueryBuilder(com.datastax.driver.core.querybuilder.QueryBuilder) Function(com.google.common.base.Function) CassandraAbstractSearchTextDao(org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao) Result(com.datastax.driver.mapping.Result) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ResultSetFuture(com.datastax.driver.core.ResultSetFuture) NoSqlDao(org.thingsboard.server.dao.util.NoSqlDao) Futures(com.google.common.util.concurrent.Futures) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) AssetEntity(org.thingsboard.server.dao.model.nosql.AssetEntity) ResultSet(com.datastax.driver.core.ResultSet) EntityType(org.thingsboard.server.common.data.EntityType) DaoUtil(org.thingsboard.server.dao.DaoUtil) EntitySubtypeEntity(org.thingsboard.server.dao.model.EntitySubtypeEntity) Select(com.datastax.driver.core.querybuilder.Select) EntitySubtype(org.thingsboard.server.common.data.EntitySubtype) Statement(com.datastax.driver.core.Statement) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) Nullable(javax.annotation.Nullable) Asset(org.thingsboard.server.common.data.asset.Asset) ModelConstants(org.thingsboard.server.dao.model.ModelConstants) ResultSetFuture(com.datastax.driver.core.ResultSetFuture) Select(com.datastax.driver.core.querybuilder.Select) ResultSet(com.datastax.driver.core.ResultSet) Nullable(javax.annotation.Nullable) Result(com.datastax.driver.mapping.Result)

Aggregations

Statement (com.datastax.driver.core.Statement)4 EntitySubtype (org.thingsboard.server.common.data.EntitySubtype)4 EntitySubtypeEntity (org.thingsboard.server.dao.model.EntitySubtypeEntity)4 ResultSet (com.datastax.driver.core.ResultSet)2 ResultSetFuture (com.datastax.driver.core.ResultSetFuture)2 QueryBuilder (com.datastax.driver.core.querybuilder.QueryBuilder)2 Select (com.datastax.driver.core.querybuilder.Select)2 Result (com.datastax.driver.mapping.Result)2 Function (com.google.common.base.Function)2 Futures (com.google.common.util.concurrent.Futures)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 java.util (java.util)2 Nullable (javax.annotation.Nullable)2 Slf4j (lombok.extern.slf4j.Slf4j)2 Component (org.springframework.stereotype.Component)2 Device (org.thingsboard.server.common.data.Device)2 EntityType (org.thingsboard.server.common.data.EntityType)2 Asset (org.thingsboard.server.common.data.asset.Asset)2 TextPageLink (org.thingsboard.server.common.data.page.TextPageLink)2 DaoUtil (org.thingsboard.server.dao.DaoUtil)2