Class BaseMapper<E extends BaseEntity>
- java.lang.Object
-
- com.github.collinalpert.java2db.mappers.BaseMapper<E>
-
- All Implemented Interfaces:
Mappable<E>
public class BaseMapper<E extends BaseEntity> extends Object implements Mappable<E>
Default mapper for converting aResultSetto the respective Java entity.- Author:
- Collin Alpert
-
-
Constructor Summary
Constructors Constructor Description BaseMapper(Class<E> clazz)
-
Method Summary
Modifier and Type Method Description Optional<E>map(ResultSet set, Map<String,String> aliases)Maps aResultSetwith a single row to a Java entity.E[]mapToArray(ResultSet set, Map<String,String> aliases)Maps aResultSetwith multiple rows to an array of Java entities.List<E>mapToList(ResultSet set, Map<String,String> aliases)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, Map<String,String> aliases)Maps aResultSetto aMap.Stream<E>mapToStream(ResultSet set, Map<String,String> aliases)Maps aResultSetwith multiple rows to aStreamof Java entities.
-
-
-
Method Detail
-
map
public Optional<E> map(ResultSet set, Map<String,String> aliases) throws SQLException
Maps aResultSetwith a single row to a Java entity.- Specified by:
mapin interfaceMappable<E extends BaseEntity>- Parameters:
set- TheResultSetto map.aliases- A map of column aliases needed to retrieve column data from theResultSet.- 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
public List<E> mapToList(ResultSet set, Map<String,String> aliases) throws SQLException
Maps aResultSetwith multiple rows to a list of Java entities.- Specified by:
mapToListin interfaceMappable<E extends BaseEntity>- Parameters:
set- TheResultSetto map.aliases- A map of column aliases needed to retrieve column data from theResultSet.- 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
public Stream<E> mapToStream(ResultSet set, Map<String,String> aliases) throws SQLException
Maps aResultSetwith multiple rows to aStreamof Java entities.- Specified by:
mapToStreamin interfaceMappable<E extends BaseEntity>- Parameters:
set- TheResultSetto map.aliases- A map of column aliases needed to retrieve column data from theResultSet.- 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
public E[] mapToArray(ResultSet set, Map<String,String> aliases) throws SQLException
Maps aResultSetwith multiple rows to an array of Java entities.- Specified by:
mapToArrayin interfaceMappable<E extends BaseEntity>- Parameters:
set- TheResultSetto map.aliases- A map of column aliases needed to retrieve column data from theResultSet.- 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, Map<String,String> aliases) throws SQLException
Maps 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.aliases- A map of column aliases needed to retrieve column data from theResultSet.- Returns:
- A
Mapcontaining theResultSets data. - Throws:
SQLException- In case theResultSetcan't be read.
-
-