Interface CustomColumnMapper
public interface CustomColumnMapper
Enables per-column
ResultSet
mapping customization via ResultSetMapper
.- Since:
- 3.0.0
- Author:
- Mark Allen
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic class
Result of a custom column mapping attempt. -
Method Summary
Modifier and TypeMethodDescriptionappliesTo
(TargetType targetType) Specifies which types this mapper should handle.map
(StatementContext<?> statementContext, ResultSet resultSet, Object resultSetValue, TargetType targetType, Integer columnIndex, String columnLabel, InstanceProvider instanceProvider) Perform custom mapping of aResultSet
column: given aresultSetValue
, optionally return an instance oftargetType
instead.
-
Method Details
-
map
@Nonnull CustomColumnMapper.MappingResult map(@Nonnull StatementContext<?> statementContext, @Nonnull ResultSet resultSet, @Nonnull Object resultSetValue, @Nonnull TargetType targetType, @Nonnull Integer columnIndex, @Nullable String columnLabel, @Nonnull InstanceProvider instanceProvider) throws SQLException Perform custom mapping of aResultSet
column: given aresultSetValue
, optionally return an instance oftargetType
instead.This method is only invoked when
resultSetValue
is non-null.- Parameters:
statementContext
- current SQL contextresultSet
- theResultSet
from which data was readresultSetValue
- the already-read value from theResultSet
, to be optionally converted to an instance oftargetType
targetType
- the type to which theresultSetValue
should be convertedcolumnIndex
- 1-based column indexcolumnLabel
- normalized column label, if availableinstanceProvider
- instance-creation factory, may be used to instantiate values- Returns:
- the result of the custom column mapping operation - either
CustomColumnMapper.MappingResult.of(Object)
to indicate a successfully-mapped value orCustomColumnMapper.MappingResult.fallback()
if Pyranid should fall back to the registeredResultSetMapper
mapping behavior. - Throws:
SQLException
- if an error occurs during mapping
-
appliesTo
Specifies which types this mapper should handle.For example, if this mapper should apply when marshaling to
MyCustomType
, this method could returntargetType.matchesClass(MyCustomType.class)
.For parameterized types like
List<UUID>
, this method could returntargetType.matchesParameterizedType(List.class, UUID.class)
.- Parameters:
targetType
- the target type to evaluate - should this mapper handle it or not?- Returns:
true
if this mapper should handle the type,false
otherwise.
-