Class JpqlValidationAndRepairService

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

@NullMarked @Component("aitls_JpqlValidationAndRepairService") public class JpqlValidationAndRepairService extends Object
Validates a generated JPQL query and repairs it when validation fails.

The query is validated, then repaired if needed and validated again. The combined outcome — the (possibly repaired) query, the final validation result and the repair details — is returned as an JpqlValidationAndRepairService.OperationResult, which also reports whether the operation ultimately failed. The rows of the final query are keyed by the requested result properties, so the outcome fails when the requested names do not match the select clause, or when a repair dropped, added or moved a selected value.

  • Field Details

  • Constructor Details

    • JpqlValidationAndRepairService

      public JpqlValidationAndRepairService()
  • Method Details

    • validateAndRepair

      Validates the query from the request and repairs it if the first validation fails.
      Parameters:
      request - execution request carrying the query, its parameters and result properties
      Returns:
      outcome with the final query
    • checkResultProperties

      protected @Nullable JpqlValidationIssue checkResultProperties(List<String> resultProperties, String jpql)
      Checks that the requested column names describe the query's columns: one name per selected value and, at every position where the value is aliased, the alias itself (ignoring case). A value without an alias accepts any name.
      Parameters:
      resultProperties - requested column names
      jpql - validated query
      Returns:
      the mismatch issue, or null if the names match the query
    • checkRepairedColumns

      protected @Nullable JpqlValidationIssue checkRepairedColumns(List<String> resultProperties, String originalJpql, String repairedJpql)
      Checks that a repaired query still returns the requested columns, position by position. The rows are keyed by the requested names, so at every position the repair may rename the alias (as it does with a reserved word) or correct the expression (as it does with a misspelled attribute), but not both at once, and it may not drop, add or move a column: the value would land under a name that means something else.
      Parameters:
      resultProperties - requested column names
      originalJpql - query as requested, before the repair
      repairedJpql - repaired query
      Returns:
      the issue that refuses the repair, or null if the repaired query keeps the columns
    • indexOfIgnoreCase

      protected int indexOfIgnoreCase(List<@Nullable String> aliases, String name)
    • failedWith

      protected JpqlValidationResult failedWith(JpqlValidationResult validationResult, JpqlValidationIssue issue)
    • toGeneratedJpqlResult

      protected GeneratedJpqlResult toGeneratedJpqlResult(JpqlExecutionRequest request)
    • toGeneratedParameters

      protected List<GeneratedJpqlParameter> toGeneratedParameters(@Nullable List<JpqlExecutionParameter> parameters)