Class JpqlParameterConversionService

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

@NullMarked @Component("aitls_JpqlParameterConversionService") public class JpqlParameterConversionService extends Object
Converts raw JPQL parameter values to the Java types expected by the query.

Each JpqlExecutionParameter carries a declared type name and an untyped value (typically a string or a number as produced by the LLM). This service resolves the target Java class and coerces the value to it, supporting common JDK types and any type known to the DatatypeRegistry. Values whose type cannot be resolved are passed through unchanged.

  • Field Details

  • Constructor Details

    • JpqlParameterConversionService

      public JpqlParameterConversionService()
  • Method Details

    • convert

      public Map<String,Object> convert(@Nullable List<JpqlExecutionParameter> parameters)
      Converts a list of parameters to a name-to-value map of execution-ready values, preserving order.

      Parameters whose value converts to null are skipped rather than bound.

      Parameters:
      parameters - parameters to convert
      Returns:
      map of parameter names to converted values; parameters with a null value are omitted
    • convert

      public @Nullable Object convert(JpqlExecutionParameter parameter)
      Converts a single parameter's value to its declared Java type.

      Collection values (used for IN clauses) are converted element by element to the declared type, so e.g. a list of UUID strings becomes a list of UUIDs.

      Parameters:
      parameter - parameter whose value is converted
      Returns:
      the converted value, or null if the parameter value is null
      Throws:
      IllegalArgumentException - if the value cannot be parsed as the declared type
    • convertScalar

      protected @Nullable Object convertScalar(Object value, Class<?> targetClass)
      Converts a single scalar value to the target type, leaving it unchanged when it is already an instance of the target type or cannot be coerced.
      Parameters:
      value - scalar value to convert
      targetClass - type to convert the value to
      Returns:
      the converted value
      Throws:
      IllegalArgumentException - if the value cannot be parsed as the target type
    • convertCollection

      protected List<Object> convertCollection(Collection<?> values, Class<?> targetClass)
      Converts every element of a collection parameter to the target type, preserving order and null elements.
      Parameters:
      values - collection values to convert (e.g. the operands of an IN clause)
      targetClass - type to convert each element to
      Returns:
      a list of converted elements
    • convertStringValue

      protected @Nullable Object convertStringValue(String value, Class<?> targetClass)
    • convertNumberValue

      protected @Nullable Object convertNumberValue(Number value, Class<?> targetClass)
    • resolveJavaClass

      protected @Nullable Class<?> resolveJavaClass(@Nullable String type)
    • resolveJavaClassByName

      protected @Nullable Class<?> resolveJavaClassByName(String type)