|
|
@ -15,6 +15,7 @@ |
|
|
*/ |
|
|
*/ |
|
|
package org.thingsboard.server.dao.sql.query; |
|
|
package org.thingsboard.server.dao.sql.query; |
|
|
|
|
|
|
|
|
|
|
|
import jakarta.annotation.PostConstruct; |
|
|
import lombok.Getter; |
|
|
import lombok.Getter; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
@ -60,6 +61,7 @@ import java.util.HashMap; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.Map; |
|
|
import java.util.Map; |
|
|
import java.util.Optional; |
|
|
import java.util.Optional; |
|
|
|
|
|
import java.util.Set; |
|
|
import java.util.UUID; |
|
|
import java.util.UUID; |
|
|
import java.util.stream.Collectors; |
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
@ -318,6 +320,11 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { |
|
|
.replace("$in", "from").replace("$out", "to") |
|
|
.replace("$in", "from").replace("$out", "to") |
|
|
.replace("$rootIdCondition", "in (:relation_root_ids)"); |
|
|
.replace("$rootIdCondition", "in (:relation_root_ids)"); |
|
|
|
|
|
|
|
|
|
|
|
private static final String NULLS_ORDER_DEFAULT = "default"; |
|
|
|
|
|
private static final String NULLS_ORDER_FIRST = "nulls_first"; |
|
|
|
|
|
private static final String NULLS_ORDER_LAST = "nulls_last"; |
|
|
|
|
|
private static final Set<String> ACCEPTED_NULLS_ORDER_STRATEGIES = Set.of(NULLS_ORDER_DEFAULT, NULLS_ORDER_FIRST, NULLS_ORDER_LAST); |
|
|
|
|
|
|
|
|
@Getter |
|
|
@Getter |
|
|
@Value("${sql.relations.max_level:50}") |
|
|
@Value("${sql.relations.max_level:50}") |
|
|
int maxLevelAllowed; //This value has to be reasonable small to prevent infinite recursion as early as possible
|
|
|
int maxLevelAllowed; //This value has to be reasonable small to prevent infinite recursion as early as possible
|
|
|
@ -336,6 +343,15 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { |
|
|
this.queryLog = queryLog; |
|
|
this.queryLog = queryLog; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@PostConstruct |
|
|
|
|
|
void validateNullsOrderStrategy() { |
|
|
|
|
|
if (!ACCEPTED_NULLS_ORDER_STRATEGIES.contains(nullsOrderStrategy)) { |
|
|
|
|
|
log.error("Invalid value '{}' for sql.entity_data_query_nulls_order_strategy. Accepted values are: {}. Falling back to '{}'.", |
|
|
|
|
|
nullsOrderStrategy, ACCEPTED_NULLS_ORDER_STRATEGIES, NULLS_ORDER_DEFAULT); |
|
|
|
|
|
nullsOrderStrategy = NULLS_ORDER_DEFAULT; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public long countEntitiesByQuery(TenantId tenantId, CustomerId customerId, EntityCountQuery query) { |
|
|
public long countEntitiesByQuery(TenantId tenantId, CustomerId customerId, EntityCountQuery query) { |
|
|
EntityType entityType = resolveEntityType(query.getEntityFilter()); |
|
|
EntityType entityType = resolveEntityType(query.getEntityFilter()); |
|
|
@ -532,8 +548,8 @@ public class DefaultEntityQueryRepository implements EntityQueryRepository { |
|
|
|
|
|
|
|
|
private String resolveNullsOrder() { |
|
|
private String resolveNullsOrder() { |
|
|
return switch (nullsOrderStrategy) { |
|
|
return switch (nullsOrderStrategy) { |
|
|
case "nulls_first" -> " NULLS FIRST"; |
|
|
case NULLS_ORDER_FIRST -> " NULLS FIRST"; |
|
|
case "nulls_last" -> " NULLS LAST"; |
|
|
case NULLS_ORDER_LAST -> " NULLS LAST"; |
|
|
default -> ""; |
|
|
default -> ""; |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|