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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classCombined outcome of the validate-and-repair operation. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected JpqlRepairServiceprotected JpqlValidationServiceprotected static final Stringprotected static final Stringprotected static final Stringstatic final Stringstatic final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected @Nullable JpqlValidationIssuecheckRepairedColumns(List<String> resultProperties, String originalJpql, String repairedJpql) Checks that a repaired query still returns the requested columns, position by position.protected @Nullable JpqlValidationIssuecheckResultProperties(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).protected JpqlValidationResultfailedWith(JpqlValidationResult validationResult, JpqlValidationIssue issue) protected intindexOfIgnoreCase(List<@Nullable String> aliases, String name) protected GeneratedJpqlResultprotected List<GeneratedJpqlParameter> toGeneratedParameters(@Nullable List<JpqlExecutionParameter> parameters) validateAndRepair(JpqlExecutionRequest request) Validates the query from the request and repairs it if the first validation fails.
-
Field Details
-
RESULT_PROPERTIES_MISMATCH_CODE
- See Also:
-
RESULT_PROPERTIES_UNREADABLE_CODE
- See Also:
-
RESULT_PROPERTIES_GUIDANCE
- See Also:
-
REPAIRED_QUERY_GUIDANCE
- See Also:
-
REPAIRED_QUERY_UNREADABLE_GUIDANCE
- See Also:
-
jpqlRepairService
-
jpqlValidationService
-
-
Constructor Details
-
JpqlValidationAndRepairService
public JpqlValidationAndRepairService()
-
-
Method Details
-
validateAndRepair
public JpqlValidationAndRepairService.OperationResult validateAndRepair(JpqlExecutionRequest request) 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 namesjpql- validated query- Returns:
- the mismatch issue, or
nullif 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 namesoriginalJpql- query as requested, before the repairrepairedJpql- repaired query- Returns:
- the issue that refuses the repair, or
nullif the repaired query keeps the columns
-
indexOfIgnoreCase
-
failedWith
protected JpqlValidationResult failedWith(JpqlValidationResult validationResult, JpqlValidationIssue issue) -
toGeneratedJpqlResult
-
toGeneratedParameters
protected List<GeneratedJpqlParameter> toGeneratedParameters(@Nullable List<JpqlExecutionParameter> parameters)
-