public class ClassMapper<T> extends Object implements ResultSetRowMapper<T>
The mapped target class must be a top-level class and it must have a default or no-arg constructor.
public class User { private int id; private String name; private UUID uuid; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; }
TypeMismatchException
,
ResultSetRowMapper
,
Name
,
MapWith
,
Converter
Modifier and Type | Field and Description |
---|---|
protected static Map<Class<Converter<Object,Object>>,Converter<Object,Object>> |
converterMap |
protected Map<String,PropertyDescriptor> |
descriptorMap |
protected PropertyDescriptor[] |
descriptors |
protected Class<T> |
target |
Constructor and Description |
---|
ClassMapper(@NotNull Class<T> target)
Constructs a new ClassMapper which maps the given bean class.
|
Modifier and Type | Method and Description |
---|---|
<S,R> ClassMapper<T> |
addConverter(Converter<S,R> converter)
Adds a new converter for this (and future ones) ClassMapper instance.
|
protected void |
assignColumnToProperty(ResultSetMetaData metaData,
PropertyDescriptor[] descriptors,
int columnCount) |
protected PropertyDescriptor[] |
getDescriptors(Class<T> target) |
boolean |
isDefaultNullValueForPrimitives()
Return whether we're defaulting Java primitives in the case of mapping a null value from corresponding database fields.
|
T |
map(@NotNull ResultSet resultSet,
int rowNumber)
Implementations will tell how to map EACH row of the ResultSet.
|
protected T |
newInstance(Class<T> target) |
static <S> @NotNull ClassMapper<S> |
of(Class<S> type) |
Map<Class<?>,Object> |
primitives() |
protected @Nullable MapWith |
retrieveAnnotations(Method method) |
protected @Nullable Converter<Object,Object> |
retrieveConverter(Method method) |
ClassMapper<T> |
setDefaultNullValueForPrimitives(boolean defaultNullValueForPrimitives)
Set whether we're defaulting Java primitives in the case of mapping a null value from corresponding database fields.
|
protected void |
setValue(T bean,
PropertyDescriptor descriptor,
Object value) |
protected static final Map<Class<Converter<Object,Object>>,Converter<Object,Object>> converterMap
protected final PropertyDescriptor[] descriptors
protected final Map<String,PropertyDescriptor> descriptorMap
@Nullable public T map(@NotNull @NotNull ResultSet resultSet, int rowNumber) throws SQLException
ResultSetRowMapper
ResultSet.next()
call is not needed: this method should only map values of the current row.map
in interface ResultSetRowMapper<T>
resultSet
- the ResultSet, already initializedrowNumber
- the number of the current rowSQLException
- if the implementation's trying to get column values in the wrong waypublic ClassMapper<T> setDefaultNullValueForPrimitives(boolean defaultNullValueForPrimitives)
public boolean isDefaultNullValueForPrimitives()
public <S,R> ClassMapper<T> addConverter(Converter<S,R> converter)
S
- the type to convertR
- the desired typeconverter
- the converter implementationprotected T newInstance(Class<T> target) throws SQLException
SQLException
protected PropertyDescriptor[] getDescriptors(Class<T> target) throws SQLException
SQLException
protected void setValue(T bean, PropertyDescriptor descriptor, Object value) throws TypeMismatchException
TypeMismatchException
protected void assignColumnToProperty(ResultSetMetaData metaData, PropertyDescriptor[] descriptors, int columnCount) throws SQLException
SQLException
@Nullable protected @Nullable Converter<Object,Object> retrieveConverter(Method method)
@NotNull public static <S> @NotNull ClassMapper<S> of(Class<S> type)
Copyright © 2021. All rights reserved.