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(@Nullable 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, or null
      targetClass - type to convert the value to
      Returns:
      the converted value, or null if value is null
      Throws:
      IllegalArgumentException - if the value cannot be parsed as the target type
    • convertCollection

      protected List<@Nullable Object> convertCollection(Collection<?> values, Class<?> targetClass)
      Converts every element of a collection parameter to the target type, preserving order.

      A null element is kept as null — that is an explicit null in the source (e.g. produced by the LLM), and it is legitimate to bind it. If a non-null element instead converts to null — i.e. the conversion silently lost the value — this is treated as a conversion failure and reported, so it cannot quietly become a NULL operand that never matches in the IN clause.

      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; an element is null only if it was null to begin with
      Throws:
      IllegalArgumentException - if a non-null element converts to null, or if an element cannot be parsed as the target type
    • 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)
    • resolveRegisteredDatatypeClass

      protected @Nullable Class<?> resolveRegisteredDatatypeClass(String type)
      Resolves a type name against the DatatypeRegistry, matching a registered datatype by its Java class name (simple or fully qualified).
      Parameters:
      type - declared type name (a Java class simple name or fully qualified name)
      Returns:
      the matching registered datatype's Java class, or null if none matches