Class JpqlExecutionService

java.lang.Object
io.jmix.aitools.dataload.execution.JpqlExecutionService

@Component("aitls_JpqlExecutionService") public class JpqlExecutionService extends Object
Validates, repairs and executes a generated JPQL query, returning the fetched rows.
  • Field Details

  • Constructor Details

    • JpqlExecutionService

      public JpqlExecutionService()
  • Method Details

    • execute

      public JpqlExecutionResult execute(JpqlExecutionRequest request)
      Validates, repairs if needed and executes the query described by the request.

      This method runs the full pipeline: it validates and (if needed) repairs the query, enforces data-access constraints, converts the parameters to their Java types and runs the query through UnconstrainedDataManager.loadValues(io.jmix.core.ValueLoadContext). One extra row is fetched to detect whether more results are available.

      Parameters:
      request - query to execute together with its parameters and paging hints
      Returns:
      result with the fetched rows on success, or with validation/execution failure details
    • toExecutionParameters

      protected List<JpqlExecutionParameter> toExecutionParameters(GeneratedJpqlResult generatedJpqlResult)
    • resolveDeniedSelectedIndexes

      protected List<Integer> resolveDeniedSelectedIndexes(String jpqlQuery)
      Resolves the positions of the selected columns the current user is not allowed to read.
      Parameters:
      jpqlQuery - query whose data access is being checked
      Returns:
      positions (in select-clause order) of the denied columns, or an empty list if access checking is unavailable or all selected columns are readable
      Throws:
      AccessDeniedException - if the current user cannot read the queried entity
    • retainPermittedProperties

      protected List<String> retainPermittedProperties(List<String> resultProperties, List<Integer> deniedSelectedIndexes)
      Returns the result properties that stay readable, dropping the ones at the denied select positions so the inaccessible columns are omitted from the result.
      Parameters:
      resultProperties - result property names in select-clause order
      deniedSelectedIndexes - positions of the denied columns
      Returns:
      the retained property names, in their original order
    • retainProperties

      protected List<Map<String,Object>> retainProperties(List<Map<String,Object>> rows, List<String> resultProperties, List<String> retainedProperties)
      Rebuilds each row keeping only the retained properties, in their original order.
      Parameters:
      rows - fetched rows keyed by all result properties
      resultProperties - all result property names the rows are keyed by
      retainedProperties - property names to keep in the output rows
      Returns:
      rows containing only the retained properties, or the original rows if nothing is dropped
    • executeQuery

      protected JpqlExecutionService.ExecutionRows executeQuery(JpqlExecutionRequest request, GeneratedJpqlResult generatedJpqlResult, Map<String,Object> executionParameters, Integer maxResults, @Nullable Integer firstResult)
    • toValueRow

      protected Map<String,Object> toValueRow(KeyValueEntity keyValueEntity, List<String> resultProperties)
    • getEffectiveMaxResult

      protected Integer getEffectiveMaxResult(@Nullable Integer maxResults)
    • createExecutionRows

      protected JpqlExecutionService.ExecutionRows createExecutionRows(List<Map<String,Object>> rows, boolean hasMore)