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>
- Author:
- Collin Alpert
-
Constructor Summary
Constructors Constructor Description FieldMapper(Class<T> underlyingClass) -
Method Summary
Modifier and Type Method Description Optional<T>map(ResultSet set)Maps aResultSetto anOptional.T[]mapToArray(ResultSet set)Maps aResultSetto an array.List<T>mapToList(ResultSet set)Maps aResultSetto aList.<K, V> Map<K,V>mapToMap(ResultSet set, Function<T,K> keyMapping, Function<T,V> valueMapping)Maps aResultSetto aMap.Stream<T>mapToStream(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.- Specified by:
mapin interfaceMappable<T>- Parameters:
set- TheResultSetto get the data from.- Returns:
- An
Optionalcontaining theResultSets data. - Throws:
SQLException- In case theResultSetcan't be read.
-
mapToList
Maps aResultSetto aList.- Specified by:
mapToListin interfaceMappable<T>- Parameters:
set- TheResultSetto get the data from.- Returns:
- A
Listcontaining theResultSets data. - Throws:
SQLException- In case theResultSetcan't be read.- See Also:
mapInternal(ResultSet, Object, BiConsumer, Function)
-
mapToStream
Maps aResultSetto aStream.- Specified by:
mapToStreamin interfaceMappable<T>- Parameters:
set- TheResultSetto get the data from.- Returns:
- A
Streamcontaining theResultSets data. - Throws:
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:
SQLException- In case theResultSetcan'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 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:
SQLException- In case theResultSetcan't be read.
-