Class FieldMapper<T>

java.lang.Object
com.github.collinalpert.java2db.mappers.FieldMapper<T>
All Implemented Interfaces:
Mappable<T>

public class FieldMapper<T>
extends Object
implements Mappable<T>
Maps a ResultSet into fields of an object or into simple types.
Author:
Collin Alpert
  • Constructor Details

  • Method Details

    • map

      public Optional<T> map​(ResultSet set) throws SQLException
      Maps a ResultSet to an Optional. Should be used when only one result is expected from the database. If any column cannot be set, a RuntimeException is thrown.
      Specified by:
      map in interface Mappable<T>
      Parameters:
      set - The ResultSet to get the data from.
      Returns:
      An Optional containing the ResultSets data.
      Throws:
      SQLException - In case the ResultSet can't be read.
    • mapToList

      public List<T> mapToList​(ResultSet set) throws SQLException
      Maps a ResultSet to a List.
      Specified by:
      mapToList in interface Mappable<T>
      Parameters:
      set - The ResultSet to get the data from.
      Returns:
      A List containing the ResultSets data.
      Throws:
      SQLException - In case the ResultSet can't be read.
      See Also:
      mapInternal(ResultSet, Object, BiConsumer, Function)
    • mapToStream

      public Stream<T> mapToStream​(ResultSet set) throws SQLException
      Maps a ResultSet to a Stream.
      Specified by:
      mapToStream in interface Mappable<T>
      Parameters:
      set - The ResultSet to get the data from.
      Returns:
      A Stream containing the ResultSets data.
      Throws:
      SQLException - In case the ResultSet can't be read.
      See Also:
      mapInternal(ResultSet, Object, BiConsumer, Function)
    • mapToArray

      public T[] mapToArray​(ResultSet set) throws SQLException
      Maps a ResultSet to an array.
      Specified by:
      mapToArray in interface Mappable<T>
      Parameters:
      set - The ResultSet to get the data from.
      Returns:
      An array containing the ResultSets data.
      Throws:
      SQLException - In case the ResultSet can't be read.
      See Also:
      mapInternal(ResultSet, Object, BiConsumer, Function)
    • mapToMap

      public <K,​ V> Map<K,​V> mapToMap​(ResultSet set, Function<T,​K> keyMapping, Function<T,​V> valueMapping) throws SQLException
      Maps a ResultSet to a Map.
      Specified by:
      mapToMap in interface Mappable<T>
      Type Parameters:
      K - The type of the keys in the map.
      V - The type of the values in the map.
      Parameters:
      set - The ResultSet to get the data from.
      keyMapping - The key function of the map.
      valueMapping - The value function of the map.
      Returns:
      A Map containing the ResultSets data.
      Throws:
      SQLException - In case the ResultSet can't be read.
    • mapToSet

      public Set<T> mapToSet​(ResultSet set) throws SQLException
      Maps a ResultSet to a Set.
      Specified by:
      mapToSet in interface Mappable<T>
      Parameters:
      set - The ResultSet to get the data from.
      Returns:
      A Set containing the ResultSets data.
      Throws:
      SQLException - In case the ResultSet can't be read.