Class EntityMapper<E extends BaseEntity>
java.lang.Object
com.github.collinalpert.java2db.mappers.EntityMapper<E>
- All Implemented Interfaces:
Mappable<E>
public class EntityMapper<E extends BaseEntity> extends Object implements Mappable<E>
Default mapper for converting a
ResultSet to the respective Java entity.- Author:
- Collin Alpert
-
Constructor Summary
Constructors Constructor Description EntityMapper(Class<E> clazz) -
Method Summary
Modifier and Type Method Description Optional<E>map(ResultSet set)Maps aResultSetwith a single row to a Java entity.E[]mapToArray(ResultSet set)Maps aResultSetwith multiple rows to an array of Java entities.List<E>mapToList(ResultSet set)Maps aResultSetwith multiple rows to a list of Java entities.<K, V> Map<K,V>mapToMap(ResultSet set, Function<E,K> keyMapping, Function<E,V> valueMapping)Maps aResultSetto aMap.Set<E>mapToSet(ResultSet set)Maps aResultSetto aSet.Stream<E>mapToStream(ResultSet set)Maps aResultSetwith multiple rows to aStreamof Java entities.
-
Constructor Details
-
Method Details
-
map
Maps aResultSetwith a single row to a Java entity.- Specified by:
mapin interfaceMappable<E extends BaseEntity>- Parameters:
set- TheResultSetto map.- Returns:
- An Optional which contains the Java entity if the query was successful.
- Throws:
SQLException- if theResultSet.next()call does not work as expected or if the entity fields cannot be set.
-
mapToList
Maps aResultSetwith multiple rows to a list of Java entities.- Specified by:
mapToListin interfaceMappable<E extends BaseEntity>- Parameters:
set- TheResultSetto map.- Returns:
- A list of Java entities.
- Throws:
SQLException- if theResultSet.next()call does not work as expected or if the entity fields cannot be set.
-
mapToStream
Maps aResultSetwith multiple rows to aStreamof Java entities.- Specified by:
mapToStreamin interfaceMappable<E extends BaseEntity>- Parameters:
set- TheResultSetto map.- Returns:
- A
Streamof Java entities. - Throws:
SQLException- if theResultSet.next()call does not work as expected or if the entity fields cannot be set.
-
mapToArray
Maps aResultSetwith multiple rows to an array of Java entities.- Specified by:
mapToArrayin interfaceMappable<E extends BaseEntity>- Parameters:
set- TheResultSetto map.- Returns:
- An array of Java entities.
- Throws:
SQLException- if theResultSet.next()call does not work as expected or if the entity fields cannot be set.
-
mapToMap
public <K, V> Map<K,V> mapToMap(ResultSet set, Function<E,K> keyMapping, Function<E,V> valueMapping) throws SQLExceptionMaps aResultSetto aMap.- Specified by:
mapToMapin interfaceMappable<E extends BaseEntity>- 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.
-
mapToSet
Maps aResultSetto aSet.- Specified by:
mapToSetin interfaceMappable<E extends BaseEntity>- Parameters:
set- TheResultSetto get the data from.- Returns:
- A
Setcontaining theResultSets data. - Throws:
SQLException- In case theResultSetcan't be read.
-