Class LlmDataQuerySerializer

java.lang.Object
io.jmix.reports.llm.impl.LlmDataQuerySerializer

@Component("report_LlmDataQuerySerializer") public class LlmDataQuerySerializer extends Object
Reads and writes the document a generated query is stored as in DataSet.getLlmGeneratedQuery().

A document says what the query text declares and nothing about the run that will execute it: an LlmQueryParameter carries no value, and what it says about the run offering it — multi-valued, optional — is transient and stays out of the document. One stored query therefore serves every run.

  • Field Details

    • REGENERATE_HINT

      protected static final String REGENERATE_HINT
      See Also:
    • gson

      protected final com.google.gson.Gson gson
      HTML escaping is off: a query is full of >, < and =, which Gson escapes by default, writing them as unicode escapes into the document the report XML carries. Nothing reads them that way except the people looking at an exported report or at its diff.
  • Constructor Details

    • LlmDataQuerySerializer

      public LlmDataQuerySerializer()
  • Method Details

    • toJson

      public String toJson(LlmDataQuery query)
      Parameters:
      query - query to store
      Returns:
      the query as a JSON document
    • fromJson

      public @Nullable LlmDataQuery fromJson(@Nullable String json)
      Reads a stored query back.
      Parameters:
      json - stored document, or null
      Returns:
      the query, or null if nothing is stored yet
      Throws:
      LlmDataQueryException - if the document cannot be read or carries no query text
    • retainNonNull

      protected <T> List<T> retainNonNull(@Nullable List<T> values)
    • retainNamedParameters

      protected List<LlmQueryParameter> retainNamedParameters(@Nullable List<LlmQueryParameter> parameters)
      Keeps the parameters that can actually be bound — a stored parameter without a name is useless — and gives one whose type the document omitted an empty type rather than none, which the constructor rejects.
    • assemble

      public LlmDataQuery assemble(String jpql, List<String> resultProperties, @Nullable LlmDataQuery previous)
      Assembles the document of a query edited by hand out of its text and its columns.

      The parameters are not edited but re-derived from the text the way the add-on validates queries by (LlmQueryParameterNames.referencedIn(java.lang.String)), so a hand-written :name is declared by the act of writing it and a removed one disappears; a parameter the previous document declared keeps its Java type, and one that appears with the edit has none to keep — the loader types every argument from the run's own dictionary anyway. The explanation and the warnings of the query being replaced are carried over: they describe what the model produced, and an edit does not make them false, only incomplete.

      Parameters:
      jpql - query text as edited
      resultProperties - column names in select-clause order
      previous - query being replaced, or null if there is none
      Returns:
      the assembled query, ready to be stored with toJson(LlmDataQuery)