public class DefaultRecordMapper<R extends Record,E> extends java.lang.Object implements RecordMapper<R,E>
RecordMapper
types.
The mapping algorithm is this:
<E>
is an array type:
The resulting array is of the nature described in Record.intoArray()
.
Arrays more specific than Object[]
can be specified as well,
e.g. String[]
. If conversion to the element type of more
specific arrays fails, a MappingException
is thrown, wrapping
conversion exceptions.
<E>
is a field "value type" and <R>
has exactly one column:
Any Java type available from SQLDataType
qualifies as a well-known
"value type" that can be converted from a single-field Record1
. The
following rules apply:
<E>
is a reference type like String
,
Integer
, Long
, Timestamp
, etc., then converting from
<R>
to <E>
is mere convenience for calling
Record.getValue(int, Class)
with fieldIndex = 0
<E>
is a primitive type, the mapping result will be
the corresponding wrapper type. null
will map to the primitive
type's initialisation value, e.g. 0
for int
,
0.0
for double
, false
for
boolean
.Column
annotations are found on the provided <E>
, only those are
used:
<E>
contains single-argument instance methods of any
visibility annotated with Column
, those methods are invoked<E>
contains no-argument instance methods of any
visibility starting with getXXX
or isXXX
, annotated
with Column
, then matching setXXX()
instance
methods of any visibility are invoked<E>
contains instance member fields of any visibility
annotated with Column
, those members are setColumn.name()
must match Field.getName()
. All other
annotation attributes are ignored
Column
annotations, or jOOQ can't find the
javax.persistence
API on the classpath, jOOQ will map
Record
values by naming convention:
If Field.getName()
is MY_field
(case-sensitive!), then
this field's value will be set on all of these (regardless of visibility):
MY_field(...)
myField(...)
setMY_field(...)
setMyField(...)
MY_field
myField
If Field.getName()
is MY_field.MY_nested_field
(case-sensitive!), then this field's value will be considered a nested value
MY_nested_field
, which is set on a nested POJO that is passed to
all of these (regardless of visibility):
MY_field(...)
myField(...)
setMY_field(...)
setMyField(...)
MY_field
myField
ConstructorProperties
is available, that one is
used
ConstructorProperties
annotation is used
to match constructor arguments against POJO members or getters.Record
values onto constructor arguments.Record
values onto constructor arguments.
Class.getDeclaredConstructors()
Abstract types are instantiated using Java reflection Proxy
mechanisms. The returned proxy will wrap a HashMap
containing
properties mapped by getters and setters of the supplied type. Methods (even
JPA-annotated ones) other than standard POJO getters and setters are not
supported. Details can be seen in Reflect.as(Class)
.
<E>
must provide a default or a "matching" constructor.
Non-public default constructors are made accessible using
AccessibleObject.setAccessible(boolean)
null
, this will
result in setting the primitive type's default value (zero for numbers, or
false
for booleans). Hence, there is no way of distinguishing
null
and 0
in that case.
This mapper is returned by the DefaultRecordMapperProvider
. You can
override this behaviour by specifying your own custom
RecordMapperProvider
in Configuration.recordMapperProvider()
RecordMapper
,
DefaultRecordMapperProvider
,
Configuration
Constructor and Description |
---|
DefaultRecordMapper(RecordType<R> rowType,
java.lang.Class<? extends E> type) |
Modifier and Type | Method and Description |
---|---|
E |
map(R record)
A callback method indicating that the next record has been fetched.
|
public DefaultRecordMapper(RecordType<R> rowType, java.lang.Class<? extends E> type)
public final E map(R record)
RecordMapper
map
in interface RecordMapper<R extends Record,E>
record
- The record to be mapped. This is never null.Copyright © 2015. All Rights Reserved.