Package org.jdbi.v3.core.mapper
Class MapMapper
- java.lang.Object
-
- org.jdbi.v3.core.mapper.MapMapper
-
- All Implemented Interfaces:
RowMapper<java.util.Map<java.lang.String,java.lang.Object>>
public class MapMapper extends java.lang.Object implements RowMapper<java.util.Map<java.lang.String,java.lang.Object>>
Yo dawg, I heard you like maps, so I made you a mapper that maps rows intoMap<String,Object>. Map keys are column names, while map values are the values in those columns. Map keys are converted to lowercase by default.- See Also:
GenericMapMapperFactory
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.function.Function<StatementContext,java.util.function.UnaryOperator<java.lang.String>>caseStrategyDeprecated.remove
-
Constructor Summary
Constructors Constructor Description MapMapper()Constructs a new MapMapper and delegates case control to MapMappers.MapMapper(boolean toLowerCase)Deprecated.useMapMappers.setCaseChange(UnaryOperator)instead.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static java.util.List<java.lang.String>getColumnNames(java.sql.ResultSet rs, java.util.function.UnaryOperator<java.lang.String> caseChange)java.util.Map<java.lang.String,java.lang.Object>map(java.sql.ResultSet rs, StatementContext ctx)Map the current row of the result set.RowMapper<java.util.Map<java.lang.String,java.lang.Object>>specialize(java.sql.ResultSet rs, StatementContext ctx)Returns a specialized row mapper, optimized for the given result set.
-
-
-
Field Detail
-
caseStrategy
@Deprecated private final java.util.function.Function<StatementContext,java.util.function.UnaryOperator<java.lang.String>> caseStrategy
Deprecated.remove
-
-
Constructor Detail
-
MapMapper
public MapMapper()
Constructs a new MapMapper and delegates case control to MapMappers.
-
MapMapper
@Deprecated public MapMapper(boolean toLowerCase)
Deprecated.useMapMappers.setCaseChange(UnaryOperator)instead.Constructs a new MapMapper- Parameters:
toLowerCase- if true, column names are converted to lowercase in the mappedMap. If false, nothing is done. Use the other constructor to delegate case control to MapMappers instead.
-
-
Method Detail
-
map
public java.util.Map<java.lang.String,java.lang.Object> map(java.sql.ResultSet rs, StatementContext ctx) throws java.sql.SQLExceptionDescription copied from interface:RowMapperMap 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:
mapin interfaceRowMapper<java.util.Map<java.lang.String,java.lang.Object>>- Parameters:
rs- the result set being iteratedctx- the statement context- Returns:
- the value to produce for this row
- Throws:
java.sql.SQLException- if anything goes wrong go ahead and let this percolate; Jdbi will handle it
-
specialize
public RowMapper<java.util.Map<java.lang.String,java.lang.Object>> specialize(java.sql.ResultSet rs, StatementContext ctx) throws java.sql.SQLException
Description copied from interface:RowMapperReturns 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:
specializein interfaceRowMapper<java.util.Map<java.lang.String,java.lang.Object>>- 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:
java.sql.SQLException- if anything goes wrong go ahead and let this percolate; Jdbi will handle it- See Also:
for an example of specialization.
-
getColumnNames
private static java.util.List<java.lang.String> getColumnNames(java.sql.ResultSet rs, java.util.function.UnaryOperator<java.lang.String> caseChange) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
-