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 aResultSetto anOptional.T[]mapToArray(java.sql.ResultSet set)Maps aResultSetto an array.java.util.List<T>mapToList(java.sql.ResultSet set)Maps aResultSetto aList.<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 aResultSetto aMap.java.util.stream.Stream<T>mapToStream(java.sql.ResultSet set)Maps aResultSetto aStream.
-
Constructor Details
-
Method Details
-
map
Maps aResultSetto anOptional. Should be used when only one result is expected from the database. If any column cannot be set, aRuntimeExceptionis thrown. -
mapToList
Maps aResultSetto aList. -
mapToStream
Maps aResultSetto aStream.- Specified by:
mapToStreamin interfaceMappable<T>- Parameters:
set- TheResultSetto get the data from.- Returns:
- A
Streamcontaining theResultSets data. - Throws:
java.sql.SQLException- In case theResultSetcan't be read.- See Also:
mapInternal(ResultSet, Object, BiConsumer, Function)
-
mapToArray
Maps aResultSetto an array.- Specified by:
mapToArrayin interfaceMappable<T>- Parameters:
set- TheResultSetto get the data from.- Returns:
- An array containing the
ResultSets data. - Throws:
java.sql.SQLException- In case theResultSetcan'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.SQLExceptionMaps aResultSetto aMap.- Specified by:
mapToMapin interfaceMappable<T>- Type Parameters:
K- The type of the keys in the map.V- The type of the values in the map.- Parameters:
set- TheResultSetto get the data from.keyMapping- The key function of the map.valueMapping- The value function of the map.- Returns:
- A
Mapcontaining theResultSets data. - Throws:
java.sql.SQLException- In case theResultSetcan't be read.
-