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:
withDefaultConfiguration()
withPlanCachingEnabled(Boolean)
(builder)withCustomColumnMappers(List)
(builder)withNormalizationLocale(Locale)
(builder)
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
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic class
Builder used to construct a standard implementation ofResultSetMapper
. -
Method Summary
Modifier and TypeMethodDescription<T> Optional
<T> map
(StatementContext<T> statementContext, ResultSet resultSet, Class<T> resultSetRowType, InstanceProvider instanceProvider) Maps the current row ofresultSet
to the result class indicated bystatementContext
.static ResultSetMapper.Builder
withCustomColumnMappers
(List<CustomColumnMapper> customColumnMappers) Acquires a builder for a concrete implementation of this interface, specifying aList
of custom column-specific mapping logic to apply, in priority order.static ResultSetMapper
Acquires a concrete implementation of this interface with out-of-the-box defaults.static ResultSetMapper.Builder
withNormalizationLocale
(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.static ResultSetMapper.Builder
withPlanCachingEnabled
(Boolean planCachingEnabled) Acquires a builder for a concrete implementation of this interface, specifying whether an internal "mapping plan" cache should be used to speed upResultSet
mapping.
-
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 ofresultSet
to the result class indicated bystatementContext
.- Type Parameters:
T
- result instance type token- Parameters:
statementContext
- current SQL contextresultSet
- provides raw row data to pull fromresultSetRowType
- the type to which theResultSet
row should be marshaledinstanceProvider
- instance-creation factory, used to instantiateresultSetRowType
row objects- Returns:
- an
Optional
containing an instance of the givenresultClass
, orOptional.empty()
to indicate anull
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 aList
of custom column-specific mapping logic to apply, in priority order.- Parameters:
customColumnMappers
- aList
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 upResultSet
mapping.- Parameters:
planCachingEnabled
- whether an internal "mapping plan" cache should be used to speed upResultSet
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
-