public class TableRecordImpl<R extends TableRecord<R>> extends Object implements TableRecord<R>
This type is for JOOQ INTERNAL USE only. Do not reference directly
Constructor and Description |
---|
TableRecordImpl(Table<R> table) |
Modifier and Type | Method and Description |
---|---|
void |
attach(Configuration c)
Attach this object to a new
Configuration |
boolean |
changed()
Check if this record has been changed from its original as fetched from
the database.
|
void |
changed(boolean changed)
Set all of this record's internal changed flags to the supplied value
If the
changed argument is false , the
Record.original() values will be reset to the corresponding "current"
values as well |
boolean |
changed(Field<?> field)
Check if a field's value has been changed from its original as fetched
from the database.
|
void |
changed(Field<?> field,
boolean changed)
Set this record's internal changed flag to the supplied value for a given
field.
|
boolean |
changed(int fieldIndex)
Check if a field's value has been changed from its original as fetched
from the database.
|
void |
changed(int fieldIndex,
boolean changed)
Set this record's internal changed flag to the supplied value for a given
field.
|
boolean |
changed(String fieldName)
Check if a field's value has been changed from its original as fetched
from the database.
|
void |
changed(String fieldName,
boolean changed)
Set this record's internal changed flag to the supplied value for a given
field.
|
int |
compareTo(Record that)
Compares this
Record with another Record
according to their natural ordering. |
Configuration |
configuration()
Get the underlying configuration
|
protected DSLContext |
create()
This method is used in generated code!
|
boolean |
equals(Object obj) |
<O extends UpdatableRecord<O>> |
fetchParent(ForeignKey<R,O> key)
Fetch a parent record of this record, given a foreign key
This returns a parent record referenced by this record through a given
foreign key.
|
<T> Field<T> |
field(Field<T> field)
Get a specific field from this Record.
|
Field<?> |
field(int index)
Get a specific field from this Record.
|
Field<?> |
field(String name)
Get a specific field from this Record.
|
Field<?>[] |
fields()
Get all fields from this Record.
|
Row |
fieldsRow()
Get this record's fields as a
Row |
void |
from(Object source)
Load data into this record from a source.
|
protected void |
from(Record source)
This method was implemented with [#799].
|
void |
fromArray(Object... array)
Load data from an array into this record
The argument array is expected to hold values for this record's field
indexes.
|
void |
fromMap(Map<String,?> map)
Load data from a map into this record
The argument map is expected to hold field-name / value pairs where
field-names correspond to actual field names as provided by
Record.field(String) . |
Table<R> |
getTable()
The table from which this record was read
|
<T> T |
getValue(Field<?> field,
Class<? extends T> type)
Get a converted value from this Record, providing a field.
|
<T> T |
getValue(Field<?> field,
Class<? extends T> type,
T defaultValue)
Get a converted value from this record, providing a field.
|
<T> T |
getValue(Field<T> field)
Get a value from this Record, providing a field.
|
<T,U> U |
getValue(Field<T> field,
Converter<? super T,U> converter)
Get a converted value from this Record, providing a field.
|
<T,U> U |
getValue(Field<T> field,
Converter<? super T,U> converter,
U defaultValue)
Get a converted value from this record, providing a field.
|
<T> T |
getValue(Field<T> field,
T defaultValue)
Get a value from this record, providing a field.
|
Object |
getValue(int index)
This method coincides with
Record.getValue(int) and
ArrayRecordImpl.getValue(int) |
<T> T |
getValue(int index,
Class<? extends T> type)
Get a converted value from this record, providing a field index.
|
<T> T |
getValue(int index,
Class<? extends T> type,
T defaultValue)
Get a converted value from this record, providing a field index.
|
<U> U |
getValue(int index,
Converter<?,U> converter)
Get a converted value from this record, providing a field index.
|
<U> U |
getValue(int index,
Converter<?,U> converter,
U defaultValue)
Get a converted value from this record, providing a field index.
|
Object |
getValue(int index,
Object defaultValue)
Get a value from this record, providing a field index.
|
Object |
getValue(String fieldName)
Get a value from this Record, providing a field name.
|
<T> T |
getValue(String fieldName,
Class<? extends T> type)
Get a converted value from this Record, providing a field name.
|
<T> T |
getValue(String fieldName,
Class<? extends T> type,
T defaultValue)
Get a converted value from this record, providing a field name.
|
<U> U |
getValue(String fieldName,
Converter<?,U> converter)
Get a converted value from this Record, providing a field name.
|
<U> U |
getValue(String fieldName,
Converter<?,U> converter,
U defaultValue)
Get a converted value from this record, providing a field name.
|
Object |
getValue(String fieldName,
Object defaultValue)
Get a value from this record, providing a field name.
|
int |
hashCode() |
<E> E |
into(Class<? extends E> type)
Map resulting records onto a custom type.
|
<E> E |
into(E object)
Map resulting records onto a custom type.
|
<R extends Record> |
into(Table<R> table)
Map resulting records onto a custom record type.
|
Object[] |
intoArray()
Convert this record into an array.
|
Map<String,Object> |
intoMap()
Return this record as a name/value map.
|
ResultSet |
intoResultSet()
Generate an in-memory JDBC
ResultSet containing the data of this
Record . |
<E> E |
map(RecordMapper<Record,E> mapper)
Map this record into a custom mapper callback
|
R |
original()
Get this record containing the original values as fetched from the
database.
|
<T> T |
original(Field<T> field)
Get an original value from this record as fetched from the database.
|
Object |
original(int fieldIndex)
Get an original value from this record as fetched from the database.
|
Object |
original(String fieldName)
Get an original value from this record as fetched from the database.
|
void |
reset()
|
void |
reset(Field<?> field)
Reset a given value to its
Record.original(Field) value and its
Record.changed(Field) flag to false . |
void |
reset(int fieldIndex)
|
void |
reset(String fieldName)
Reset a given value to its
Record.original(String) value and its
Record.changed(String) flag to false . |
<T> void |
setValue(Field<T> field,
T value)
Set a value into this record.
|
<T,U> void |
setValue(Field<T> field,
U value,
Converter<T,? super U> converter)
Set a value into this record.
|
protected void |
setValue(int index,
Object value)
Subclasses may type-unsafely set a value to a record index.
|
int |
size()
This method coincides with
Record.size() and
ArrayRecord.size() |
String |
toString() |
Row |
valuesRow()
Get this record's values as a
Row |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
changed, changed, changed, changed, changed, changed, changed, changed, compareTo, equals, field, field, field, fields, from, fromArray, fromMap, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, hashCode, into, into, into, intoArray, intoMap, intoResultSet, map, original, original, original, reset, reset, reset, reset, setValue, setValue, size
attach
public final Table<R> getTable()
TableRecord
getTable
in interface TableRecord<R extends TableRecord<R>>
public Row fieldsRow()
Record
Row
public Row valuesRow()
Record
Row
public final R original()
Record
Record values can be freely modified after having fetched a record from the database. Every record also references the originally fetched values. This method returns a new record containing those original values.
original
in interface Record
original
in interface TableRecord<R extends TableRecord<R>>
Record.original(Field)
,
Record.original(int)
,
Record.original(String)
public final <O extends UpdatableRecord<O>> O fetchParent(ForeignKey<R,O> key)
TableRecord
This returns a parent record referenced by this record through a given
foreign key. If no parent record was found, this returns
null
fetchParent
in interface TableRecord<R extends TableRecord<R>>
ForeignKey.fetchParent(Record)
,
ForeignKey.fetchParents(java.util.Collection)
,
ForeignKey.fetchParents(Record...)
public final <T> Field<T> field(Field<T> field)
Record
field
in interface Record
Row.field(Field)
public final Field<?> field(String name)
Record
field
in interface Record
Row.field(String)
public final Field<?> field(int index)
Record
field
in interface Record
Row.field(int)
public final Field<?>[] fields()
Record
fields
in interface Record
Row.fields()
public final int size()
Record.size()
and
ArrayRecord.size()
public final <T> T getValue(Field<T> field)
Record
public final <T> T getValue(Field<T> field, T defaultValue)
Record
public final <T> T getValue(Field<?> field, Class<? extends T> type)
Record
getValue
in interface Record
T
- The conversion type parameterfield
- The fieldtype
- The conversion typeConvert.convert(Object, Class)
public final <T> T getValue(Field<?> field, Class<? extends T> type, T defaultValue)
Record
getValue
in interface Record
T
- The conversion type parameterfield
- The fieldtype
- The conversion typedefaultValue
- The default value instead of null
null
Convert.convert(Object, Class)
public final <T,U> U getValue(Field<T> field, Converter<? super T,U> converter)
Record
getValue
in interface Record
T
- The database type parameterU
- The conversion type parameterfield
- The fieldconverter
- The data type converterConvert.convert(Object, Converter)
public final <T,U> U getValue(Field<T> field, Converter<? super T,U> converter, U defaultValue)
Record
getValue
in interface Record
T
- The database type parameterU
- The conversion type parameterfield
- The fieldconverter
- The data type converterdefaultValue
- The default value instead of null
null
Convert.convert(Object, Converter)
public final Object getValue(int index)
Record.getValue(int)
and
ArrayRecordImpl.getValue(int)
public final Object getValue(int index, Object defaultValue)
Record
public final <T> T getValue(int index, Class<? extends T> type)
Record
getValue
in interface Record
T
- The conversion type parameterindex
- The field's indextype
- The conversion typeConvert.convert(Object, Class)
public final <T> T getValue(int index, Class<? extends T> type, T defaultValue)
Record
getValue
in interface Record
T
- The conversion type parameterindex
- The field's indextype
- The conversion typedefaultValue
- The default value instead of null
null
Convert.convert(Object, Class)
public final <U> U getValue(int index, Converter<?,U> converter)
Record
getValue
in interface Record
U
- The conversion type parameterindex
- The field's indexconverter
- The data type converterConvert.convert(Object, Converter)
public final <U> U getValue(int index, Converter<?,U> converter, U defaultValue)
Record
getValue
in interface Record
U
- The conversion type parameterindex
- The field's indexconverter
- The data type converterdefaultValue
- The default value instead of null
null
Convert.convert(Object, Converter)
public final Object getValue(String fieldName)
Record
public final Object getValue(String fieldName, Object defaultValue)
Record
public final <T> T getValue(String fieldName, Class<? extends T> type)
Record
getValue
in interface Record
T
- The conversion type parameterfieldName
- The field's nametype
- The conversion typeConvert.convert(Object, Class)
public final <T> T getValue(String fieldName, Class<? extends T> type, T defaultValue)
Record
getValue
in interface Record
T
- The conversion type parameterfieldName
- The field's nametype
- The conversion typedefaultValue
- The default value instead of null
null
Convert.convert(Object, Class)
public final <U> U getValue(String fieldName, Converter<?,U> converter)
Record
getValue
in interface Record
U
- The conversion type parameterfieldName
- The field's nameconverter
- The data type converterConvert.convert(Object, Converter)
public final <U> U getValue(String fieldName, Converter<?,U> converter, U defaultValue)
Record
getValue
in interface Record
U
- The conversion type parameterfieldName
- The field's nameconverter
- The data type converterdefaultValue
- The default value instead of null
null
Convert.convert(Object, Converter)
public final <T> void setValue(Field<T> field, T value)
Record
public final <T,U> void setValue(Field<T> field, U value, Converter<T,? super U> converter)
Record
protected final void setValue(int index, Object value)
public final <T> T original(Field<T> field)
Record
Record values can be freely modified after having fetched a record from the database. Every record also references the originally fetched values. This method returns such an original value for a field.
original
in interface Record
Record.original()
public final Object original(int fieldIndex)
Record
Record values can be freely modified after having fetched a record from the database. Every record also references the originally fetched values. This method returns such an original value for a field.
original
in interface Record
Record.original()
public final Object original(String fieldName)
Record
Record values can be freely modified after having fetched a record from the database. Every record also references the originally fetched values. This method returns such an original value for a field.
original
in interface Record
Record.original()
public final boolean changed()
Record
If this returns false
, then it can be said that
record.equals(record.original())
is true.
changed
in interface Record
Record.original()
,
Record.changed(Field)
,
Record.changed(int)
,
Record.changed(String)
public final boolean changed(Field<?> field)
Record
changed
in interface Record
Record.changed()
,
Record.original(Field)
public final boolean changed(int fieldIndex)
Record
changed
in interface Record
Record.changed()
,
Record.original(int)
public final boolean changed(String fieldName)
Record
changed
in interface Record
Record.changed()
,
Record.original(String)
public final void changed(boolean changed)
Record
If the changed
argument is false
, the
Record.original()
values will be reset to the corresponding "current"
values as well
changed
in interface Record
Record.changed()
,
Record.changed(Field, boolean)
,
Record.changed(int, boolean)
,
Record.changed(String, boolean)
public final void changed(Field<?> field, boolean changed)
Record
If the changed
argument is false
, the
Record.original(Field)
value will be reset to the corresponding
"current" value as well
changed
in interface Record
Record.changed()
,
Record.changed(Field)
public final void changed(int fieldIndex, boolean changed)
Record
If the changed
argument is false
, the
Record.original(int)
value will be reset to the corresponding "current"
value as well
changed
in interface Record
Record.changed()
,
Record.changed(int)
public final void changed(String fieldName, boolean changed)
Record
If the changed
argument is false
, the
Record.original(String)
value will be reset to the corresponding
"current" value as well
changed
in interface Record
Record.changed()
,
Record.changed(String)
public final void reset()
Record
public final void reset(Field<?> field)
Record
Record.original(Field)
value and its
Record.changed(Field)
flag to false
.public final void reset(int fieldIndex)
Record
public final void reset(String fieldName)
Record
Record.original(String)
value and its
Record.changed(String)
flag to false
.public final Object[] intoArray()
Record
The resulting array has the same number of elements as this record has fields. The resulting array contains data as such:
// For arbitrary values of i
record.getValue(i) == record.intoArray()[i]
This is the same as calling into(Object[].class)
intoArray
in interface Record
Record.fromArray(Object...)
public final Map<String,Object> intoMap()
Record
This is the inverse operation to Record.fromMap(Map)
intoMap
in interface Record
Record.fromMap(Map)
public final <E> E into(Class<? extends E> type)
Record
The mapping algorithm is this:
type
is an array:
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 fails, a
MappingException
is thrown, wrapping conversion exceptions.
Column
annotations are found on the provided type
, only those are
used:
type
contains public single-argument instance methods
annotated with Column
, those methods are invokedtype
contains public no-argument instance methods
starting with getXXX
or isXXX
, annotated with
Column
, then matching public setXXX()
instance
methods are invokedtype
contains public instance member fields 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:
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()
Class.getDeclaredConstructors()
Abstract types are instanciated 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)
.
type
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.into
in interface Record
E
- The generic entity type.type
- The entity type.Record.from(Object)
public final <E> E into(E object)
Record
This is the same as Record.into(Class)
, except that no new object is
instanciated as a result. Instead, you can provide your own custom POJO
instance.
into
in interface Record
E
- The generic entity type.object
- The receiving bean.Record.from(Object)
public final <R extends Record> R into(Table<R> table)
Record
The mapping algorithm is this:
Record
values by equal field names:
table
argument with
Field.getName()
"MY_field"
(case-sensitive!), a
corresponding field with the same name in this record will be searched.Field.getName()
, then the first one returning true on
Field.equals(Object)
will be returned. (e.g. qualified field
names match)
Table.getRecordType()
must return a class of type
TableRecord
, which must provide a default constructor. Non-public
default constructors are made accessible using
AccessibleObject.setAccessible(boolean)
public final ResultSet intoResultSet()
Record
ResultSet
containing the data of this
Record
.
Use this as an adapter for JDBC-compliant code that expects a
ResultSet
to operate on, rather than a jOOQ Result
. The
returned ResultSet
allows for the following behaviour
according to the JDBC specification:
ResultSet.CLOSE_CURSORS_AT_COMMIT
: The cursors (i.e.
Statement
object) are no longer availableResultSet.CONCUR_READ_ONLY
: You cannot update the database
through this ResultSet
, as the underlying Result
object does not hold any open database refences anymoreResultSet.FETCH_FORWARD
: The fetch direction is forward only,
and cannot be changedResultSet.TYPE_SCROLL_INSENSITIVE
: You can use any of the
ResultSet
's scrolling methods, e.g. ResultSet.next()
or ResultSet.previous()
, etc.
You may use DSLContext.fetch(ResultSet)
to unwind this wrapper
again.
This is the same as creating a new Result
with this
Record
only, and then calling Result.intoResultSet()
on that Result
intoResultSet
in interface Record
ResultSet
public final <E> E map(RecordMapper<Record,E> mapper)
Record
public final void from(Object source)
Record
The mapping algorithm is this:
source
is an array
Loading of data is delegated to Record.fromArray(Object...)
source
is a Map
Loading of data is delegated to Record.fromMap(Map)
Column
annotations are found on the Class
of the provided source
, only those are used. Matching
candidates are:
Column
getXXX
or isXXX
, if there exists a matching public single-argument
setXXX()
instance method that is annotated with
Column
Column
Column.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 members by naming convention: If Field.getName()
is
MY_field
(case-sensitive!), then this field's value will be
fetched from the first of these:
MY_field()
myField()
getMY_field()
getMyField()
MY_field
myField
The resulting record will have its internal
"changed" flags set to true for all values. This means that
UpdatableRecord.store()
will perform an INSERT
statement. If you wish to store the record using an UPDATE
statement, use DSLContext.executeUpdate(UpdatableRecord)
instead.
from
in interface Record
source
- The source object to copy data fromRecord.into(Class)
public final void fromMap(Map<String,?> map)
Record
The argument map is expected to hold field-name / value pairs where
field-names correspond to actual field names as provided by
Record.field(String)
. Missing fields will be left untouched. Excess
fields will be ignored.
This is the inverse operation to Record.intoMap()
fromMap
in interface Record
Record.intoMap()
public final void fromArray(Object... array)
Record
The argument array is expected to hold values for this record's field indexes. Missing values will be left untouched. Excess values will be ignored.
This is the inverse operation to Record.intoArray()
protected final void from(Record source)
public int compareTo(Record that)
Record
Record
with another Record
according to their natural ordering.
jOOQ Records implement Comparable
to allow for naturally ordering
Records in a "SQL way", i.e. according to the following rules:
Two Records are comparable if and only if they have the same
ROW
type, i.e. if their fieldsRow()
methods return fields of the same type and degree.
Assume the following notations:
X[i]
means X.getValue(i)
X = Y
means X.compareTo(Y) == 0
X < Y
means X.compareTo(Y) < 0
X[i] = Y[i]
means
(X[i] == null && Y[i] == null) || X[i].compareTo(Y[i]) < 0
X[i] < Y[i]
means
Y[i] == null || X[i].compareTo(Y[i]) < 0
. This
corresponds to the SQL NULLS LAST
clause.r1
and r2
,
x = r1.compareTo(r2)
yields:
x = -1
: if
(r1[0] < r2[0])
OR (r1[0] = r2[0] AND r1[1] < r2[1])
OR ...
OR (r1[0] = r2[0] AND ... AND r1[N-1] = r2[N-1] AND r1[N] < r2[N])
x = 0
: if
OR (r1[0] = r2[0] AND ... AND r1[N-1] = r2[N-1] AND r1[N] = r2[N])
x = 1
: if
(r1[0] > r2[0])
OR (r1[0] = r2[0] AND r1[1] > r2[1])
OR ...
OR (r1[0] = r2[0] AND ... AND r1[N-1] = r2[N-1] AND r1[N] > r2[N])
Note, that the above rules correspond to the SQL ordering behaviour as
illustrated in the following examples:
-- A SQL ORDER BY clause, ordering all records by columns in their order
SELECT a, b, c
FROM my_table
ORDER BY 1, 2, 3
-- A row value expression comparison predicate
SELECT *
FROM my_table
WHERE (a, b, c) < (1, 2, 3)
See Row1.lessThan(Row1)
, Row2.lessThan(Row2)
, ...,
Row22.lessThan(Row22)
for more details about row value expression
comparison predicates
Alternative sorting behaviour can be achieved through
Result.sortAsc(java.util.Comparator)
and similar methods.
compareTo
in interface Comparable<Record>
compareTo
in interface Record
public final void attach(Configuration c)
Attachable
Configuration
attach
in interface Attachable
c
- A configuration or null
, if you wish to
detach this Attachable
from its previous
configuration.public final Configuration configuration()
AttachableInternal
configuration
in interface AttachableInternal
protected final DSLContext create()
Copyright © 2013. All Rights Reserved.