Class FieldMapper<T>

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

public class FieldMapper<T>
extends java.lang.Object
implements Mappable<T>
Author:
Collin Alpert
  • Constructor Summary

    Constructors 
    Constructor Description
    FieldMapper​(java.lang.Class<T> underlyingClass)  
  • Method Summary

    Modifier and Type Method Description
    java.util.Optional<T> map​(java.sql.ResultSet set)
    Maps a ResultSet to an Optional.
    T[] mapToArray​(java.sql.ResultSet set)
    Maps a ResultSet to an array.
    java.util.List<T> mapToList​(java.sql.ResultSet set)
    Maps a ResultSet to a List.
    <K,​ V> java.util.Map<K,​V> mapToMap​(java.sql.ResultSet set, java.util.function.Function<T,​K> keyMapping, java.util.function.Function<T,​V> valueMapping)
    Maps a ResultSet to a Map.
    java.util.stream.Stream<T> mapToStream​(java.sql.ResultSet set)
    Maps a ResultSet to a Stream.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.github.collinalpert.java2db.mappers.Mappable

    mapToMap
  • Constructor Details

    • FieldMapper

      public FieldMapper​(java.lang.Class<T> underlyingClass)
  • Method Details

    • map

      public java.util.Optional<T> map​(java.sql.ResultSet set) throws java.sql.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:
      java.sql.SQLException - In case the ResultSet can't be read.
    • mapToList

      public java.util.List<T> mapToList​(java.sql.ResultSet set) throws java.sql.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:
      java.sql.SQLException - In case the ResultSet can't be read.
      See Also:
      mapInternal(ResultSet, Object, BiConsumer, Function)
    • mapToStream

      public java.util.stream.Stream<T> mapToStream​(java.sql.ResultSet set) throws java.sql.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:
      java.sql.SQLException - In case the ResultSet can't be read.
      See Also:
      mapInternal(ResultSet, Object, BiConsumer, Function)
    • mapToArray

      public T[] mapToArray​(java.sql.ResultSet set) throws java.sql.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:
      java.sql.SQLException - In case the ResultSet can't be read.
      See Also:
      mapInternal(ResultSet, Object, BiConsumer, Function)
    • mapToMap

      public <K,​ V> java.util.Map<K,​V> mapToMap​(java.sql.ResultSet set, java.util.function.Function<T,​K> keyMapping, java.util.function.Function<T,​V> valueMapping) throws java.sql.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:
      java.sql.SQLException - In case the ResultSet can't be read.