Package org.jdbi.v3.core.mapper.reflect
Class ConstructorMapper<T>
java.lang.Object
org.jdbi.v3.core.mapper.reflect.ConstructorMapper<T>
- All Implemented Interfaces:
RowMapper<T>
A row mapper which maps the fields in a result set into a constructor. The default implementation will perform a case insensitive mapping between the
constructor parameter names and the column labels, also considering camel-case to underscores conversion.
This mapper respects Nested
annotations on constructor parameters.
Constructor parameters annotated as @Nullable
may be omitted from the result set without error. Any annotation named "Nullable" can be used, no
matter which package it is from.
-
Method Summary
Modifier and TypeMethodDescriptionstatic RowMapperFactory
Use the only declared constructor to map a class.static RowMapperFactory
Use the only declared constructor to map a class.static RowMapperFactory
factory
(Constructor<?> constructor) Use aConstructor<T>
to map its declaring type.static RowMapperFactory
factory
(Constructor<?> constructor, String prefix) Use aConstructor<T>
to map its declaring type.map
(ResultSet rs, StatementContext ctx) Map the current row of the result set.static <T> RowMapper
<T> Return a ConstructorMapper for the given type.static <T> RowMapper
<T> Return a ConstructorMapper for the given type and prefix.static <T> RowMapper
<T> of
(Constructor<T> constructor) Return a ConstructorMapper using the given constructorstatic <T> RowMapper
<T> of
(Constructor<T> constructor, String prefix) Instantiate a ConstructorMapper using the given constructor and prefixspecialize
(ResultSet rs, StatementContext ctx) Returns a specialized row mapper, optimized for the given result set.
-
Method Details
-
factory
Use the only declared constructor to map a class.- Parameters:
clazz
- the class to find a constructor of- Returns:
- the factory
-
factory
Use the only declared constructor to map a class.- Parameters:
clazz
- the class to find a constructor ofprefix
- a prefix for the parameter names- Returns:
- the factory
-
factory
Use aConstructor<T>
to map its declaring type.- Parameters:
constructor
- the constructor to invoke- Returns:
- the factory
-
factory
Use aConstructor<T>
to map its declaring type.- Parameters:
constructor
- the constructor to invokeprefix
- a prefix to the constructor parameter names- Returns:
- the factory
-
of
Return a ConstructorMapper for the given type.- Type Parameters:
T
- the type to map- Parameters:
type
- the mapped type- Returns:
- the mapper
-
of
Return a ConstructorMapper for the given type and prefix.- Type Parameters:
T
- the type to map- Parameters:
type
- the mapped typeprefix
- the column name prefix- Returns:
- the mapper
-
of
Return a ConstructorMapper using the given constructor- Type Parameters:
T
- the type to map- Parameters:
constructor
- the constructor to be used in mapping- Returns:
- the mapper
-
of
Instantiate a ConstructorMapper using the given constructor and prefix- Type Parameters:
T
- the type to map- Parameters:
constructor
- the constructor to be used in mappingprefix
- the column name prefix- Returns:
- the mapper
-
map
Description copied from interface:RowMapper
Map the current row of the result set. This method should not cause the result set to advance; allow Jdbi to do that, please.- Specified by:
map
in interfaceRowMapper<T>
- Parameters:
rs
- the result set being iteratedctx
- the statement context- Returns:
- the value to produce for this row
- Throws:
SQLException
- if anything goes wrong go ahead and let this percolate; Jdbi will handle it
-
specialize
Description copied from interface:RowMapper
Returns a specialized row mapper, optimized for the given result set.Before mapping the result set from a SQL statement; Jdbi will first call this method to obtain a specialized instance. The returned mapper will then be used to map the result set rows, and discarded.
Implementing this method is optional; the default implementation returns
this
. Implementors might choose to override this method to improve performance, e.g. by matching up column names to properties once for the entire result set, rather than repeating the process for every row.- Specified by:
specialize
in interfaceRowMapper<T>
- Parameters:
rs
- the result set to specialize overctx
- the statement context to specialize over- Returns:
- a row mapper equivalent to this one, possibly specialized.
- Throws:
SQLException
- if anything goes wrong go ahead and let this percolate; Jdbi will handle it- See Also:
-