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 classBuilder 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 ofresultSetto the result class indicated bystatementContext.static ResultSetMapper.BuilderwithCustomColumnMappers(List<CustomColumnMapper> customColumnMappers) Acquires a builder for a concrete implementation of this interface, specifying aListof custom column-specific mapping logic to apply, in priority order.static ResultSetMapperAcquires a concrete implementation of this interface with out-of-the-box defaults.static ResultSetMapper.BuilderwithNormalizationLocale(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.BuilderwithPlanCachingEnabled(Boolean planCachingEnabled) Acquires a builder for a concrete implementation of this interface, specifying whether an internal "mapping plan" cache should be used to speed upResultSetmapping.
-
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 ofresultSetto 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 theResultSetrow should be marshaledinstanceProvider- instance-creation factory, used to instantiateresultSetRowTyperow objects- Returns:
- an
Optionalcontaining an instance of the givenresultClass, orOptional.empty()to indicate anullvalue - 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
Builderfor a concrete implementation
-
withCustomColumnMappers
@Nonnull static ResultSetMapper.Builder withCustomColumnMappers(@Nonnull List<CustomColumnMapper> customColumnMappers) Acquires a builder for a concrete implementation of this interface, specifying aListof custom column-specific mapping logic to apply, in priority order.- Parameters:
customColumnMappers- aListof custom column-specific mapping logic to apply, in priority order- Returns:
- a
Builderfor 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 upResultSetmapping.- Parameters:
planCachingEnabled- whether an internal "mapping plan" cache should be used to speed upResultSetmapping- Returns:
- a
Builderfor 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
-