Class DefaultJpqlRepairer

java.lang.Object
io.jmix.aitools.dataload.repair.impl.DefaultJpqlRepairer
All Implemented Interfaces:
JpqlRepairer, org.springframework.beans.factory.InitializingBean

public class DefaultJpqlRepairer extends Object implements JpqlRepairer, org.springframework.beans.factory.InitializingBean
Default JpqlRepairer that re-prompts the LLM with the previous query and its validation issues, then parses the corrected JPQL from the model's JSON reply.
  • Field Details

    • jpqlRepairerPromptProvider

      @Autowired protected JpqlRepairerPromptProvider jpqlRepairerPromptProvider
    • chatClientFactory

      @Autowired protected ChatClientFactory chatClientFactory
    • objectMapper

      protected tools.jackson.databind.ObjectMapper objectMapper
  • Constructor Details

    • DefaultJpqlRepairer

      public DefaultJpqlRepairer()
  • Method Details

    • afterPropertiesSet

      public void afterPropertiesSet()
      Initializes the JSON object mapper after the bean is created.
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
    • repair

      @NullMarked public @Nullable GeneratedJpqlResult repair(JpqlRepairRequest request)
      Description copied from interface: JpqlRepairer
      Attempts to repair the invalid query described by the request.
      Specified by:
      repair in interface JpqlRepairer
      Parameters:
      request - repair request with the current query
      Returns:
      query draft, or null if no repaired result could be produced
    • formatValidationIssues

      protected String formatValidationIssues(List<JpqlValidationIssue> issues)
    • formatRepairGuidance

      protected String formatRepairGuidance(List<JpqlValidationIssue> issues)
    • executePrompt

      protected @Nullable GeneratedJpqlResult executePrompt(JpqlRepairRequest request)
      Re-prompts the model with the previous query and its validation issues and parses the corrected query from the reply.

      Returns null when the reply yields no query draft (empty, or no parseable JSON object). The caller then keeps the original validation issues instead of failing with a technical error, and the raw reply is logged.

      Parameters:
      request - repair request with the previous query and its validation issues
      Returns:
      repaired query draft, or null if the reply could not be parsed
    • readPromptTemplate

      protected String readPromptTemplate()
    • mapToGeneratedJpqlResult

      protected GeneratedJpqlResult mapToGeneratedJpqlResult(GeneratedJpqlPayload payload)
    • toGeneratedJpqlParameter

      protected @Nullable GeneratedJpqlParameter toGeneratedJpqlParameter(GeneratedJpqlParameterPayload payload)
      Maps a parameter payload to a GeneratedJpqlParameter, or returns null to skip it when the model provided no parameter name (such a parameter cannot be bound).
      Parameters:
      payload - raw parameter payload from the model
      Returns:
      mapped parameter, or null if it has no usable name
    • createObjectMapper

      protected tools.jackson.databind.ObjectMapper createObjectMapper()
    • toJson

      protected String toJson(Object object)