Interface CustomColumnMapper


public interface CustomColumnMapper
Enables per-column ResultSet mapping customization via ResultSetMapper.
Since:
3.0.0
Author:
Mark Allen
  • 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 a ResultSet column: given a resultSetValue, optionally return an instance of targetType instead.

      This method is only invoked when resultSetValue is non-null.

      Parameters:
      statementContext - current SQL context
      resultSet - the ResultSet from which data was read
      resultSetValue - the already-read value from the ResultSet, to be optionally converted to an instance of targetType
      targetType - the type to which the resultSetValue should be converted
      columnIndex - 1-based column index
      columnLabel - normalized column label, if available
      instanceProvider - 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 or CustomColumnMapper.MappingResult.fallback() if Pyranid should fall back to the registered ResultSetMapper mapping behavior.
      Throws:
      SQLException - if an error occurs during mapping
    • appliesTo

      @Nonnull Boolean appliesTo(@Nonnull TargetType targetType)
      Specifies which types this mapper should handle.

      For example, if this mapper should apply when marshaling to MyCustomType, this method could return targetType.matchesClass(MyCustomType.class).

      For parameterized types like List<UUID>, this method could return targetType.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.