Optimize DAO layer for Widget Bundles
This commit is contained in:
parent
7992491c92
commit
5ede741892
@ -30,6 +30,9 @@ import org.thingsboard.server.dao.sql.JpaAbstractDao;
|
|||||||
import org.thingsboard.server.dao.util.SqlDao;
|
import org.thingsboard.server.dao.util.SqlDao;
|
||||||
import org.thingsboard.server.dao.widget.WidgetsBundleDao;
|
import org.thingsboard.server.dao.widget.WidgetsBundleDao;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -92,44 +95,32 @@ public class JpaWidgetsBundleDao extends JpaAbstractDao<WidgetsBundleEntity, Wid
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageData<WidgetsBundle> findAllTenantWidgetsBundlesByTenantId(UUID tenantId, boolean fullSearch, PageLink pageLink) {
|
public PageData<WidgetsBundle> findAllTenantWidgetsBundlesByTenantId(UUID tenantId, boolean fullSearch, PageLink pageLink) {
|
||||||
|
return findTenantWidgetsBundlesByTenantIds(Arrays.asList(tenantId, NULL_UUID), fullSearch, pageLink);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageData<WidgetsBundle> findTenantWidgetsBundlesByTenantId(UUID tenantId, boolean fullSearch, PageLink pageLink) {
|
||||||
|
return findTenantWidgetsBundlesByTenantIds(Collections.singletonList(tenantId), fullSearch, pageLink);
|
||||||
|
}
|
||||||
|
|
||||||
|
private PageData<WidgetsBundle> findTenantWidgetsBundlesByTenantIds(List<UUID> tenantIds, boolean fullSearch, PageLink pageLink) {
|
||||||
if (fullSearch) {
|
if (fullSearch) {
|
||||||
return DaoUtil.toPageData(
|
return DaoUtil.toPageData(
|
||||||
widgetsBundleRepository
|
widgetsBundleRepository
|
||||||
.findAllTenantWidgetsBundlesByTenantIdFullSearch(
|
.findAllTenantWidgetsBundlesByTenantIdFullSearch(
|
||||||
tenantId,
|
tenantIds,
|
||||||
NULL_UUID,
|
|
||||||
pageLink.getTextSearch(),
|
pageLink.getTextSearch(),
|
||||||
DaoUtil.toPageable(pageLink)));
|
DaoUtil.toPageable(pageLink)));
|
||||||
} else {
|
} else {
|
||||||
return DaoUtil.toPageData(
|
return DaoUtil.toPageData(
|
||||||
widgetsBundleRepository
|
widgetsBundleRepository
|
||||||
.findAllTenantWidgetsBundlesByTenantId(
|
.findAllTenantWidgetsBundlesByTenantId(
|
||||||
tenantId,
|
tenantIds,
|
||||||
NULL_UUID,
|
|
||||||
pageLink.getTextSearch(),
|
pageLink.getTextSearch(),
|
||||||
DaoUtil.toPageable(pageLink)));
|
DaoUtil.toPageable(pageLink)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public PageData<WidgetsBundle> findTenantWidgetsBundlesByTenantId(UUID tenantId, boolean fullSearch, PageLink pageLink) {
|
|
||||||
if (fullSearch) {
|
|
||||||
return DaoUtil.toPageData(
|
|
||||||
widgetsBundleRepository
|
|
||||||
.findTenantWidgetsBundlesByTenantIdFullSearch(
|
|
||||||
tenantId,
|
|
||||||
Objects.toString(pageLink.getTextSearch(), ""),
|
|
||||||
DaoUtil.toPageable(pageLink)));
|
|
||||||
} else {
|
|
||||||
return DaoUtil.toPageData(
|
|
||||||
widgetsBundleRepository
|
|
||||||
.findTenantWidgetsBundlesByTenantId(
|
|
||||||
tenantId,
|
|
||||||
Objects.toString(pageLink.getTextSearch(), ""),
|
|
||||||
DaoUtil.toPageable(pageLink)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WidgetsBundle findByTenantIdAndExternalId(UUID tenantId, UUID externalId) {
|
public WidgetsBundle findByTenantIdAndExternalId(UUID tenantId, UUID externalId) {
|
||||||
return DaoUtil.getData(widgetsBundleRepository.findByTenantIdAndExternalId(tenantId, externalId));
|
return DaoUtil.getData(widgetsBundleRepository.findByTenantIdAndExternalId(tenantId, externalId));
|
||||||
|
|||||||
@ -23,6 +23,7 @@ import org.springframework.data.repository.query.Param;
|
|||||||
import org.thingsboard.server.dao.ExportableEntityRepository;
|
import org.thingsboard.server.dao.ExportableEntityRepository;
|
||||||
import org.thingsboard.server.dao.model.sql.WidgetsBundleEntity;
|
import org.thingsboard.server.dao.model.sql.WidgetsBundleEntity;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,15 +67,14 @@ public interface WidgetsBundleRepository extends JpaRepository<WidgetsBundleEnti
|
|||||||
@Param("textSearch") String textSearch,
|
@Param("textSearch") String textSearch,
|
||||||
Pageable pageable);
|
Pageable pageable);
|
||||||
|
|
||||||
@Query("SELECT wb FROM WidgetsBundleEntity wb WHERE wb.tenantId IN (:tenantId, :nullTenantId) " +
|
@Query("SELECT wb FROM WidgetsBundleEntity wb WHERE wb.tenantId IN (:tenantIds) " +
|
||||||
"AND (:textSearch IS NULL OR ilike(wb.title, CONCAT('%', :textSearch, '%')) = true)")
|
"AND (:textSearch IS NULL OR ilike(wb.title, CONCAT('%', :textSearch, '%')) = true)")
|
||||||
Page<WidgetsBundleEntity> findAllTenantWidgetsBundlesByTenantId(@Param("tenantId") UUID tenantId,
|
Page<WidgetsBundleEntity> findAllTenantWidgetsBundlesByTenantId(@Param("tenantIds") List<UUID> tenantIds,
|
||||||
@Param("nullTenantId") UUID nullTenantId,
|
|
||||||
@Param("textSearch") String textSearch,
|
@Param("textSearch") String textSearch,
|
||||||
Pageable pageable);
|
Pageable pageable);
|
||||||
|
|
||||||
@Query(nativeQuery = true,
|
@Query(nativeQuery = true,
|
||||||
value = "SELECT * FROM widgets_bundle wb WHERE wb.tenant_id IN (:tenantId, :nullTenantId) " +
|
value = "SELECT * FROM widgets_bundle wb WHERE wb.tenant_id IN (:tenantIds) " +
|
||||||
"AND (wb.title ILIKE CONCAT('%', :textSearch, '%') " +
|
"AND (wb.title ILIKE CONCAT('%', :textSearch, '%') " +
|
||||||
"OR wb.description ILIKE CONCAT('%', :textSearch, '%') " +
|
"OR wb.description ILIKE CONCAT('%', :textSearch, '%') " +
|
||||||
"OR wb.id in (SELECT wbw.widgets_bundle_id FROM widgets_bundle_widget wbw, widget_type wtd " +
|
"OR wb.id in (SELECT wbw.widgets_bundle_id FROM widgets_bundle_widget wbw, widget_type wtd " +
|
||||||
@ -82,7 +82,7 @@ public interface WidgetsBundleRepository extends JpaRepository<WidgetsBundleEnti
|
|||||||
"AND (wtd.name ILIKE CONCAT('%', :textSearch, '%') " +
|
"AND (wtd.name ILIKE CONCAT('%', :textSearch, '%') " +
|
||||||
"OR wtd.description ILIKE CONCAT('%', :textSearch, '%') " +
|
"OR wtd.description ILIKE CONCAT('%', :textSearch, '%') " +
|
||||||
"OR lower(wtd.tags\\:\\:text)\\:\\:text[] && string_to_array(lower(:textSearch), ' '))))",
|
"OR lower(wtd.tags\\:\\:text)\\:\\:text[] && string_to_array(lower(:textSearch), ' '))))",
|
||||||
countQuery = "SELECT count(*) FROM widgets_bundle wb WHERE wb.tenant_id IN (:tenantId, :nullTenantId) " +
|
countQuery = "SELECT count(*) FROM widgets_bundle wb WHERE wb.tenant_id IN (:tenantIds) " +
|
||||||
"AND (wb.title ILIKE CONCAT('%', :textSearch, '%') " +
|
"AND (wb.title ILIKE CONCAT('%', :textSearch, '%') " +
|
||||||
"OR wb.description ILIKE CONCAT('%', :textSearch, '%') " +
|
"OR wb.description ILIKE CONCAT('%', :textSearch, '%') " +
|
||||||
"OR wb.id in (SELECT wbw.widgets_bundle_id FROM widgets_bundle_widget wbw, widget_type wtd " +
|
"OR wb.id in (SELECT wbw.widgets_bundle_id FROM widgets_bundle_widget wbw, widget_type wtd " +
|
||||||
@ -91,30 +91,7 @@ public interface WidgetsBundleRepository extends JpaRepository<WidgetsBundleEnti
|
|||||||
"OR wtd.description ILIKE CONCAT('%', :textSearch, '%') " +
|
"OR wtd.description ILIKE CONCAT('%', :textSearch, '%') " +
|
||||||
"OR lower(wtd.tags\\:\\:text)\\:\\:text[] && string_to_array(lower(:textSearch), ' '))))"
|
"OR lower(wtd.tags\\:\\:text)\\:\\:text[] && string_to_array(lower(:textSearch), ' '))))"
|
||||||
)
|
)
|
||||||
Page<WidgetsBundleEntity> findAllTenantWidgetsBundlesByTenantIdFullSearch(@Param("tenantId") UUID tenantId,
|
Page<WidgetsBundleEntity> findAllTenantWidgetsBundlesByTenantIdFullSearch(@Param("tenantIds") List<UUID> tenantIds,
|
||||||
@Param("nullTenantId") UUID nullTenantId,
|
|
||||||
@Param("textSearch") String textSearch,
|
|
||||||
Pageable pageable);
|
|
||||||
|
|
||||||
@Query(nativeQuery = true,
|
|
||||||
value = "SELECT * FROM widgets_bundle wb WHERE wb.tenant_id IN (:tenantId) " +
|
|
||||||
"AND (wb.title ILIKE CONCAT('%', :textSearch, '%') " +
|
|
||||||
"OR wb.description ILIKE CONCAT('%', :textSearch, '%') " +
|
|
||||||
"OR wb.id in (SELECT wbw.widgets_bundle_id FROM widgets_bundle_widget wbw, widget_type wtd " +
|
|
||||||
"WHERE wtd.id = wbw.widget_type_id " +
|
|
||||||
"AND (wtd.name ILIKE CONCAT('%', :textSearch, '%') " +
|
|
||||||
"OR wtd.description ILIKE CONCAT('%', :textSearch, '%') " +
|
|
||||||
"OR lower(wtd.tags\\:\\:text)\\:\\:text[] && string_to_array(lower(:textSearch), ' '))))",
|
|
||||||
countQuery = "SELECT count(*) FROM widgets_bundle wb WHERE wb.tenant_id IN (:tenantId, :nullTenantId) " +
|
|
||||||
"AND (wb.title ILIKE CONCAT('%', :textSearch, '%') " +
|
|
||||||
"OR wb.description ILIKE CONCAT('%', :textSearch, '%') " +
|
|
||||||
"OR wb.id in (SELECT wbw.widgets_bundle_id FROM widgets_bundle_widget wbw, widget_type wtd " +
|
|
||||||
"WHERE wtd.id = wbw.widget_type_id " +
|
|
||||||
"AND (wtd.name ILIKE CONCAT('%', :textSearch, '%') " +
|
|
||||||
"OR wtd.description ILIKE CONCAT('%', :textSearch, '%') " +
|
|
||||||
"OR lower(wtd.tags\\:\\:text)\\:\\:text[] && string_to_array(lower(:textSearch), ' '))))"
|
|
||||||
)
|
|
||||||
Page<WidgetsBundleEntity> findTenantWidgetsBundlesByTenantIdFullSearch(@Param("tenantId") UUID tenantId,
|
|
||||||
@Param("textSearch") String textSearch,
|
@Param("textSearch") String textSearch,
|
||||||
Pageable pageable);
|
Pageable pageable);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user