Annotation Interface ApiQuery


@Retention(RUNTIME) @Target(METHOD) public @interface ApiQuery
Specifies an explicit query string to be executed by the proxy-api-controller interceptor instead of relying on the automatic JPQL generation.

When this annotation is absent the framework generates a JPQL query dynamically from the method's ApiFind binding and the parameters present in the request. When @ApiQuery is present, its value() is used as-is (either as a native SQL or JPQL string depending on the jpql() flag).

Native SQL example


 @GetMapping("/products/custom")
 @ApiQuery("SELECT * FROM product WHERE active = true")
 List<ProductDto> findActive();
 

JPQL example


 @GetMapping("/products/custom")
 @ApiQuery(value = "SELECT p FROM Product p WHERE p.active = true", jpql = true)
 List<ProductDto> findActive();
 
Author:
Francesco Baldi
See Also:
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    The query string to execute.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    boolean
    When true, the value() is treated as a JPQL query and the automatic query-building pipeline is used.
    Default ordering to apply when the caller has not specified a sort key.
  • Element Details

    • value

      String value
      The query string to execute. For native SQL queries this must be a valid SQL statement; for JPQL queries (jpql() = true) it must be a valid JPQL statement.
      Returns:
      the query string; must not be blank when jpql() is false
    • jpql

      boolean jpql
      When true, the value() is treated as a JPQL query and the automatic query-building pipeline is used. When false (default), value() is executed as a native SQL query.
      Returns:
      true for JPQL mode, false for native SQL mode
      Default:
      false
    • orderBy

      DefaultOrderBy[] orderBy
      Default ordering to apply when the caller has not specified a sort key. Each entry maps to one ORDER BY clause item.
      Returns:
      the default order-by clauses; empty array means no default ordering
      Default:
      {}