Class SqlAttributesFilter

java.lang.Object
org.forgerock.openig.sql.SqlAttributesFilter
All Implemented Interfaces:
Filter

public class SqlAttributesFilter extends Object implements Filter
Executes a SQL query through a prepared statement and exposes its first result. Parameters in the prepared statement are derived from expressions. The query result is exposed in a SqlAttributesContext or in a Map object, whose location is specified by the target expression (the latter is deprecated).

If the query yields no result, then the resulting map will be empty.

Two behaviors are currently available for this filter:

  • (deprecated) The SQL query execution is performed lazily and the result is stored into the defined target; the query execution does not occur until the first attempt to access a value in the target. This defers the overhead of connection pool, network and database query processing until a value is first required. This also means that the parameters expressions will not be evaluated until the map is first accessed.
  • The SQL query execution is done asynchronously within this filter and the result is stored in a SqlAttributesContext; This means the SQL query is always performed, and thus this filter must be placed right before the component using the data.
See Also:
  • Constructor Details

    • SqlAttributesFilter

      @Deprecated(since="2024.9.0", forRemoval=true) public SqlAttributesFilter(DataSource dataSource, LeftValueExpression<Map> target, String preparedStatement)
      Deprecated, for removal: This API element is subject to removal in a future version.
      use SqlAttributesFilter(DataSource, String, ScheduledExecutorService) instead.
      Builds a new SqlAttributesFilter that will execute the given SQL statement on the given DataSource, placing the results in a Map<String,Object> in a SqlAttributesContext or, in the specified target if set. Using this constructor, this Map will always be lazily loaded.
      Parameters:
      dataSource - JDBC data source
      target - Expression that yields the target object that will contain the mapped results, may be null.
      preparedStatement - The parameterized SQL query to execute, with ? parameter placeholders
  • Method Details

    • filter

      public Promise<Response,NeverThrowsException> filter(Context context, Request request, Handler next)
      Description copied from interface: Filter
      Filters the request and/or response of an exchange. To pass the request to the next filter or handler in the chain, the filter calls next.handle(context, request).

      This method may elect not to pass the request to the next filter or handler, and instead handle the request itself. It can achieve this by merely avoiding a call to next.handle(context, request) and creating its own response object. The filter is also at liberty to replace a response with another of its own by intercepting the response returned by the next handler.

      Specified by:
      filter in interface Filter
      Parameters:
      context - The request context.
      request - The request.
      next - The next filter or handler in the chain to handle the request.
      Returns:
      A Promise representing the response to be returned to the client.
    • getParameters

      public List<Expression<?>> getParameters()
      Returns the list of parameters to evaluate and include in the execution of the prepared statement.
      Returns:
      the list of parameters to evaluate and include in the execution of the prepared statement.