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 {
     // TODO: pull data from resultSet and apply to a new instance of T
     return Optional.empty();
   }
 };
Since:
1.0.0
Author:
Mark Allen
  • Method Details

    • map

      @Nonnull <T> 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

      @Nonnull static ResultSetMapper.Builder withNormalizationLocale(@Nonnull Locale normalizationLocale)
      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

      @Nonnull static ResultSetMapper.Builder withCustomColumnMappers(@Nonnull List<CustomColumnMapper> customColumnMappers)
      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

      @Nonnull static ResultSetMapper.Builder withPlanCachingEnabled(@Nonnull Boolean planCachingEnabled)
      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.
      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