Package de.chojo.sadu.mapper
Class RowMapperRegistry
java.lang.Object
de.chojo.sadu.mapper.RowMapperRegistry
Class to register
RowMapper
to map rows to objects.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfind
(Class<T> clazz, ResultSetMetaData meta, MapperConfig config) Searches for a matching mapper for this result set.find
(Class<T> clazz, ResultSet set, MapperConfig config) Searches for a matching mapper for this result set.<T> RowMapper<T>
findOrWildcard
(Class<T> clazz, ResultSetMetaData meta, MapperConfig config) Finds a mapper for a class for the matching column names.<T> RowMapper<T>
findOrWildcard
(Class<T> clazz, ResultSet set, MapperConfig config) Searches for a matching mapper for this result set.Registers a new mapper for a class.Registers new mapper.<V> void
Registers row mapper of a class if they contain a constructor or static method annotated withMappingProvider
Registers new mapper.Gets the wild card mapper if registered.
-
Constructor Details
-
RowMapperRegistry
public RowMapperRegistry()
-
-
Method Details
-
register
Registers a new mapper for a class.A class can only have one mapper per column combination.
- Parameters:
rowMapper
- the mapper to register- Throws:
MappingAlreadyRegisteredException
- when a mapping with the same column name exists already
-
register
Registers new mapper.A class can only have one mapper per column combination.
- Parameters:
rowMapper
- one or more mapper to register- Throws:
MappingAlreadyRegisteredException
- when a mapping with the same column name exists already
-
register
Registers new mapper.A class can only have one mapper per column combination.
- Parameters:
rowMapper
- one or more mapper to register- Throws:
MappingAlreadyRegisteredException
- when a mapping with the same column name exists already
-
wildcard
Gets the wild card mapper if registered.- Type Parameters:
T
- type of mapper- Parameters:
clazz
- class to get the mapper- Returns:
- mapper if exists
-
find
public <T> Optional<RowMapper<T>> find(Class<T> clazz, ResultSet set, MapperConfig config) throws SQLException Searches for a matching mapper for this result set.A mapper is matching when all columns the mapper needs are present in the result set.
The mapper with the most matching columns will be returned.
- Type Parameters:
T
- return type of mapper- Parameters:
clazz
- clazz to find a mapper forset
- result set to find a matching mapper- Returns:
- mapper when found
- Throws:
SQLException
-
find
Searches for a matching mapper for this result set.A mapper is matching when all columns the mapper needs are present in the result set.
The mapper with the most matching columns will be returned.
- Type Parameters:
T
- return type of mapper- Parameters:
clazz
- clazz to find a mapper formeta
- result set meta to find a matching mapper- Returns:
- mapper when found
-
findOrWildcard
public <T> RowMapper<T> findOrWildcard(Class<T> clazz, ResultSet set, MapperConfig config) throws MappingException, SQLException Searches for a matching mapper for this result set.A mapper is matching when all columns the mapper needs are present in the result set.
The mapper with the most matching columns will be returned.
- Type Parameters:
T
- return type of mapper- Parameters:
clazz
- clazz to find a mapper forset
- result set to find a matching mapperconfig
- mapper config- Returns:
- mapper when found
- Throws:
MappingException
- when no mapper was found for this class and no wildcard mapper is registered.SQLException
-
findOrWildcard
public <T> RowMapper<T> findOrWildcard(Class<T> clazz, ResultSetMetaData meta, MapperConfig config) throws MappingException, SQLException Finds a mapper for a class for the matching column names. If no mapper was found a possible wildcard mapper will be returned.- Type Parameters:
T
- type of row mapper- Parameters:
clazz
- clazzmeta
- meta- Returns:
- row mapper when found
- Throws:
MappingException
- when no mapper was found for this class and no wildcard mapper is registered.SQLException
- if a database access error occurs
-
register
Registers row mapper of a class if they contain a constructor or static method annotated withMappingProvider
- Type Parameters:
V
- type of class to be registered- Parameters:
clazz
- clazz to be registered- Throws:
InvalidMappingException
- when no mapping was found.
-