Interface ResultSetMapper

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

Contract for mapping a ResultSet row to the specified type.

A production-ready concrete implementation is available via the following static methods:

How to acquire an instance:

 // With out-of-the-box defaults
ResultSetMapper default = ResultSetMapper.withDefaultConfiguration();

// Customized
ResultSetMapper custom = ResultSetMapper.withPlanCachingEnabled(false)
 .customColumnMappers(List.of(...))
 .normalizationLocale(Locale.forLanguageTag("pt-BR"))
 .build();
Or, implement your own:
 ResultSetMapper myImpl = new ResultSetMapper() {
  @NonNull
  @Override
  public <T> Optional<T> map(
    @NonNull StatementContext<T> statementContext,
    @NonNull ResultSet resultSet,
    @NonNull Class<T> resultSetRowType,
    @NonNull InstanceProvider instanceProvider
  ) throws SQLException {
    // Pull data from resultSet and apply to a new instance of T
    return Optional.empty();
  }
};
Since:
1.0.0
Author:
Mark Allen
  • Field Details

  • Method Details

    • map

      <T> @NonNull Optional<T> map(@NonNull StatementContext<T> statementContext, @NonNull ResultSet resultSet, @NonNull Class<T> resultSetRowType, @NonNull InstanceProvider instanceProvider) throws SQLException
      Maps the current row of resultSet to the result class indicated by statementContext.
      Type Parameters:
      T - result instance type token
      Parameters:
      statementContext - current SQL context
      resultSet - provides raw row data to pull from
      resultSetRowType - the type to which the ResultSet row should be marshaled
      instanceProvider - instance-creation factory, used to instantiate resultSetRowType row objects
      Returns:
      an Optional containing an instance of the given resultClass, or Optional.empty() to indicate a null value
      Throws:
      SQLException - if an error occurs during mapping
    • withNormalizationLocale

      Acquires a builder for a concrete implementation of this interface, specifying the locale to use when massaging JDBC column names for matching against Java property names.
      Parameters:
      normalizationLocale - the locale to use when massaging JDBC column names for matching against Java property names
      Returns:
      a Builder for a concrete implementation
    • withCustomColumnMappers

      Acquires a builder for a concrete implementation of this interface, specifying a List of custom column-specific mapping logic to apply, in priority order.
      Parameters:
      customColumnMappers - a List of custom column-specific mapping logic to apply, in priority order
      Returns:
      a Builder for a concrete implementation
    • withPlanCachingEnabled

      Acquires a builder for a concrete implementation of this interface, specifying whether an internal "mapping plan" cache should be used to speed up ResultSet mapping.

      Disabling plan caching is primarily useful for highly dynamic schemas; the non-planned path allocates per-row maps and does more reflection.

      Parameters:
      planCachingEnabled - whether an internal "mapping plan" cache should be used to speed up ResultSet mapping
      Returns:
      a Builder for a concrete implementation
    • withDefaultConfiguration

      Acquires a concrete implementation of this interface with out-of-the-box defaults.

      The returned instance is thread-safe.

      Returns:
      a concrete implementation of this interface with out-of-the-box defaults