@ -19,7 +19,7 @@ import com.datastax.oss.driver.api.core.uuid.Uuids;
import com.google.common.collect.Lists ;
import com.google.common.util.concurrent.ListenableFuture ;
import lombok.extern.slf4j.Slf4j ;
import org.springframework.data.repository.Crud Repository ;
import org.springframework.data.jpa.repository.Jpa Repository ;
import org.springframework.transaction.annotation.Transactional ;
import org.thingsboard.server.common.data.id.TenantId ;
import org.thingsboard.server.dao.Dao ;
@ -41,7 +41,7 @@ public abstract class JpaAbstractDao<E extends BaseEntity<D>, D>
protected abstract Class < E > getEntityClass ( ) ;
protected abstract Crud Repository< E , UUID > getCrud Repository ( ) ;
protected abstract Jpa Repository< E , UUID > getRepository ( ) ;
protected void setSearchText ( E entity ) {
}
@ -63,52 +63,52 @@ public abstract class JpaAbstractDao<E extends BaseEntity<D>, D>
entity . setUuid ( uuid ) ;
entity . setCreatedTime ( Uuids . unixTimestamp ( uuid ) ) ;
}
entity = getCrud Repository ( ) . save ( entity ) ;
entity = getRepository ( ) . save ( entity ) ;
return DaoUtil . getData ( entity ) ;
}
@Override
public D findById ( TenantId tenantId , UUID key ) {
log . debug ( "Get entity by key {}" , key ) ;
Optional < E > entity = getCrud Repository ( ) . findById ( key ) ;
Optional < E > entity = getRepository ( ) . findById ( key ) ;
return DaoUtil . getData ( entity ) ;
}
@Override
public ListenableFuture < D > findByIdAsync ( TenantId tenantId , UUID key ) {
log . debug ( "Get entity by key async {}" , key ) ;
return service . submit ( ( ) - > DaoUtil . getData ( getCrud Repository ( ) . findById ( key ) ) ) ;
return service . submit ( ( ) - > DaoUtil . getData ( getRepository ( ) . findById ( key ) ) ) ;
}
@Override
public boolean existsById ( TenantId tenantId , UUID key ) {
log . debug ( "Exists by key {}" , key ) ;
return getCrud Repository ( ) . existsById ( key ) ;
return getRepository ( ) . existsById ( key ) ;
}
@Override
public ListenableFuture < Boolean > existsByIdAsync ( TenantId tenantId , UUID key ) {
log . debug ( "Exists by key async {}" , key ) ;
return service . submit ( ( ) - > getCrud Repository ( ) . existsById ( key ) ) ;
return service . submit ( ( ) - > getRepository ( ) . existsById ( key ) ) ;
}
@Override
@Transactional
public boolean removeById ( TenantId tenantId , UUID id ) {
getCrud Repository ( ) . deleteById ( id ) ;
getRepository ( ) . deleteById ( id ) ;
log . debug ( "Remove request: {}" , id ) ;
return ! getCrud Repository ( ) . existsById ( id ) ;
return ! getRepository ( ) . existsById ( id ) ;
}
@Transactional
public void removeAllByIds ( Collection < UUID > ids ) {
Crud Repository< E , UUID > repository = getCrud Repository ( ) ;
Jpa Repository< E , UUID > repository = getRepository ( ) ;
ids . forEach ( repository : : deleteById ) ;
}
@Override
public List < D > find ( TenantId tenantId ) {
List < E > entities = Lists . newArrayList ( getCrud Repository ( ) . findAll ( ) ) ;
List < E > entities = Lists . newArrayList ( getRepository ( ) . findAll ( ) ) ;
return DaoUtil . convertDataList ( entities ) ;
}
}