org.jooq.Record Maven / Gradle / Ivy
/**
* Copyright (c) 2009-2014, Data Geekery GmbH (http://www.datageekery.com)
* All rights reserved.
*
* This work is dual-licensed
* - under the Apache Software License 2.0 (the "ASL")
* - under the jOOQ License and Maintenance Agreement (the "jOOQ License")
* =============================================================================
* You may choose which license applies to you:
*
* - If you're using this work with Open Source databases, you may choose
* either ASL or jOOQ License.
* - If you're using this work with at least one commercial database, you must
* choose jOOQ License
*
* For more information, please visit http://www.jooq.org/licenses
*
* Apache Software License 2.0:
* -----------------------------------------------------------------------------
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* jOOQ License and Maintenance Agreement:
* -----------------------------------------------------------------------------
* Data Geekery grants the Customer the non-exclusive, timely limited and
* non-transferable license to install and use the Software under the terms of
* the jOOQ License and Maintenance Agreement.
*
* This library is distributed with a LIMITED WARRANTY. See the jOOQ License
* and Maintenance Agreement for more details: http://www.jooq.org/licensing
*/
package org.jooq;
import java.lang.reflect.Constructor;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLData;
import java.sql.Statement;
import java.util.Map;
import javax.persistence.Column;
import org.jooq.exception.DataTypeException;
import org.jooq.exception.MappingException;
import org.jooq.impl.DefaultRecordMapper;
import org.jooq.impl.DefaultRecordMapperProvider;
import org.jooq.tools.Convert;
/**
* A database result record.
*
* A record essentially combines a list of columns ({@link Field}) with a
* corresponding list of values, each value being of the respective field's
* type.
*
* While records can be seen as generic column / value mappings, their concrete
* implementations often specialise the above description in any of the
* following ways:
*
*
Table records
*
* Records originating from a concrete database table (or view) are modelled by
* jOOQ as {@link TableRecord} or {@link UpdatableRecord}, if they contain a
* primary key. If you're using jOOQ's code generator, you can generate even
* more concrete types of table records, i.e. one table record per table.
*
*
UDT records
*
* {@link SQLDialect#ORACLE} and {@link SQLDialect#POSTGRES} formally support
* user defined types (UDT), which are modelled by jOOQ as {@link UDTRecord}. In
* addition to being regular records (column / value mappings), they also
* implement the JDBC {@link SQLData} API in order to be streamed to a JDBC
* {@link PreparedStatement} or from a JDBC {@link ResultSet}
*
*
Records of well-defined degree
*
* When projecting custom record types in SQL, new ad-hoc types of a certain
* degree are formed on the fly. Records with degree <= 22 are reflected by
* jOOQ through the {@link Record1}, {@link Record2}, ... {@link Record22}
* classes, which cover the respective row value expressions {@link Row1},
* {@link Row2}, ... {@link Row22}
*
* Note that generated TableRecords and UDTRecords
* also implement a Record[N] interface, if N <= 22
*
*
Record implements Comparable
*
* jOOQ records have a natural ordering implemented in the same way as this is
* defined in the SQL standard. For more details, see the
* {@link #compareTo(Record)} method
*
* @author Lukas Eder
* @see Result
*/
public interface Record extends Attachable, Comparable {
/**
* Get this record's fields as a {@link Row}.
*/
Row fieldsRow();
/**
* Get a specific field from this Record.
*
* @see Row#field(Field)
*/
Field field(Field field);
/**
* Get a specific field from this Record.
*
* @see Row#field(String)
*/
Field> field(String name);
/**
* Get a specific field from this Record.
*
* @see Row#field(int)
*/
Field> field(int index);
/**
* Get all fields from this Record.
*
* @see Row#fields()
*/
Field>[] fields();
/**
* Get all fields from this Record, providing some fields.
*
* @return All available fields
* @see Row#fields(Field...)
*/
Field>[] fields(Field>... fields);
/**
* Get all fields from this Record, providing some field names.
*
* @return All available fields
* @see Row#fields(String...)
*/
Field>[] fields(String... fieldNames);
/**
* Get all fields from this Record, providing some field indexes.
*
* @return All available fields
* @see Row#fields(int...)
*/
Field>[] fields(int... fieldIndexes);
/**
* Get this record's values as a {@link Row}.
*/
Row valuesRow();
/**
* Get a value from this Record, providing a field.
*
* @param The generic field parameter
* @param field The field
* @return The value of a field contained in this record
* @throws IllegalArgumentException If the argument field is not contained
* in {@link #fieldsRow()}
*/
T getValue(Field field) throws IllegalArgumentException;
/**
* Get a value from this record, providing a field.
*
* @param The generic field parameter
* @param field The field
* @param defaultValue The default value instead of null
* @return The value of a field contained in this record, or defaultValue,
* if null
* @throws IllegalArgumentException If the argument field is not contained
* in {@link #fieldsRow()}
* @deprecated - 3.3.0 - [#2878] - This method will be removed in jOOQ 4.0
*/
@Deprecated
T getValue(Field field, T defaultValue) throws IllegalArgumentException;
/**
* Get a converted value from this Record, providing a field.
*
* @param The conversion type parameter
* @param field The field
* @param type The conversion type
* @return The value of a field contained in this record
* @throws IllegalArgumentException If the argument field is not contained
* in {@link #fieldsRow()}
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
* @see Convert#convert(Object, Class)
*/
T getValue(Field> field, Class extends T> type) throws IllegalArgumentException, DataTypeException;
/**
* Get a converted value from this record, providing a field.
*
* @param The conversion type parameter
* @param field The field
* @param type The conversion type
* @param defaultValue The default value instead of null
* @return The value of a field contained in this record, or defaultValue,
* if null
* @throws IllegalArgumentException If the argument field is not contained
* in {@link #fieldsRow()}
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
* @see Convert#convert(Object, Class)
* @deprecated - 3.3.0 - [#2878] - This method will be removed in jOOQ 4.0
*/
@Deprecated
T getValue(Field> field, Class extends T> type, T defaultValue) throws IllegalArgumentException,
DataTypeException;
/**
* Get a converted value from this Record, providing a field.
*
* @param The database type parameter
* @param The conversion type parameter
* @param field The field
* @param converter The data type converter
* @return The value of a field contained in this record
* @throws IllegalArgumentException If the argument field is not contained
* in {@link #fieldsRow()}
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
* @see Convert#convert(Object, Converter)
*/
U getValue(Field field, Converter super T, U> converter) throws IllegalArgumentException,
DataTypeException;
/**
* Get a converted value from this record, providing a field.
*
* @param The database type parameter
* @param The conversion type parameter
* @param field The field
* @param converter The data type converter
* @param defaultValue The default value instead of null
* @return The value of a field contained in this record, or defaultValue,
* if null
* @throws IllegalArgumentException If the argument field is not contained
* in {@link #fieldsRow()}
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
* @see Convert#convert(Object, Converter)
* @deprecated - 3.3.0 - [#2878] - This method will be removed in jOOQ 4.0
*/
@Deprecated
U getValue(Field field, Converter super T, U> converter, U defaultValue)
throws IllegalArgumentException, DataTypeException;
/**
* Get a value from this Record, providing a field name.
*
* @param fieldName The field's name
* @return The value of a field's name contained in this record
* @throws IllegalArgumentException If the argument fieldName is not
* contained in the record
*/
Object getValue(String fieldName) throws IllegalArgumentException;
/**
* Get a value from this record, providing a field name.
*
* @param fieldName The field's name
* @param defaultValue The default value instead of null
* @return The value of a field's name contained in this record, or
* defaultValue, if null
* @throws IllegalArgumentException If the argument fieldName is not
* contained in the record
* @deprecated - 3.3.0 - [#2878] - This method will be removed in jOOQ 4.0
*/
@Deprecated
Object getValue(String fieldName, Object defaultValue) throws IllegalArgumentException;
/**
* Get a converted value from this Record, providing a field name.
*
* @param The conversion type parameter
* @param fieldName The field's name
* @param type The conversion type
* @return The value of a field's name contained in this record
* @throws IllegalArgumentException If the argument fieldName is not
* contained in the record
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
* @see Convert#convert(Object, Class)
*/
T getValue(String fieldName, Class extends T> type) throws IllegalArgumentException, DataTypeException;
/**
* Get a converted value from this record, providing a field name.
*
* @param The conversion type parameter
* @param fieldName The field's name
* @param type The conversion type
* @param defaultValue The default value instead of null
* @return The value of a field's name contained in this record, or
* defaultValue, if null
* @throws IllegalArgumentException If the argument fieldName is not
* contained in the record
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
* @see Convert#convert(Object, Class)
* @deprecated - 3.3.0 - [#2878] - This method will be removed in jOOQ 4.0
*/
@Deprecated
T getValue(String fieldName, Class extends T> type, T defaultValue) throws IllegalArgumentException,
DataTypeException;
/**
* Get a converted value from this Record, providing a field name.
*
* @param The conversion type parameter
* @param fieldName The field's name
* @param converter The data type converter
* @return The value of a field's name contained in this record
* @throws IllegalArgumentException If the argument fieldName is not
* contained in the record
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
* @see Convert#convert(Object, Converter)
*/
U getValue(String fieldName, Converter, U> converter) throws IllegalArgumentException, DataTypeException;
/**
* Get a converted value from this record, providing a field name.
*
* @param The conversion type parameter
* @param fieldName The field's name
* @param converter The data type converter
* @param defaultValue The default value instead of null
* @return The value of a field's name contained in this record, or
* defaultValue, if null
* @throws IllegalArgumentException If the argument fieldName is not
* contained in the record
* @throws DataTypeException wrapping any data type conversion exception
* that might have occurred
* @see Convert#convert(Object, Converter)
* @deprecated - 3.3.0 - [#2878] - This method will be removed in jOOQ 4.0
*/
@Deprecated
U getValue(String fieldName, Converter, U> converter, U defaultValue) throws IllegalArgumentException,
DataTypeException;
/**
* Get a value from this record, providing a field index.
*
* @param index The field's index
* @return The value of a field's index contained in this record
* @throws IllegalArgumentException If the argument index is not contained
* in the record
*/
Object getValue(int index) throws IllegalArgumentException;
/**
* Get a value from this record, providing a field index.
*
* @param index The field's index
* @param defaultValue The default value instead of null
* @return The value of a field's index contained in this record, or
* defaultValue, if null
* @throws IllegalArgumentException If the argument index is not contained
* in the record
* @deprecated - 3.3.0 - [#2878] - This method will be removed in jOOQ 4.0
*/
@Deprecated
Object getValue(int index, Object defaultValue) throws IllegalArgumentException;
/**
* Get a converted value from this record, providing a field index.
*
* @param The conversion type parameter
* @param index The field's index
* @param type The conversion type
* @return The value of a field's index contained in this record
* @throws IllegalArgumentException If the argument index is not contained
* in the record
* @throws DataTypeException wrapping data type conversion exception that
* might have occurred
* @see Convert#convert(Object, Class)
*/
T getValue(int index, Class extends T> type) throws IllegalArgumentException, DataTypeException;
/**
* Get a converted value from this record, providing a field index.
*
* @param The conversion type parameter
* @param index The field's index
* @param type The conversion type
* @param defaultValue The default value instead of null
* @return The value of a field's index contained in this record, or
* defaultValue, if null
* @throws IllegalArgumentException If the argument index is not contained
* in the record
* @throws DataTypeException wrapping data type conversion exception that
* might have occurred
* @see Convert#convert(Object, Class)
* @deprecated - 3.3.0 - [#2878] - This method will be removed in jOOQ 4.0
*/
@Deprecated
T getValue(int index, Class extends T> type, T defaultValue) throws IllegalArgumentException,
DataTypeException;
/**
* Get a converted value from this record, providing a field index.
*
* @param The conversion type parameter
* @param index The field's index
* @param converter The data type converter
* @return The value of a field's index contained in this record
* @throws IllegalArgumentException If the argument index is not contained
* in the record
* @throws DataTypeException wrapping data type conversion exception that
* might have occurred
* @see Convert#convert(Object, Converter)
*/
U getValue(int index, Converter, U> converter) throws IllegalArgumentException, DataTypeException;
/**
* Get a converted value from this record, providing a field index.
*
* @param The conversion type parameter
* @param index The field's index
* @param converter The data type converter
* @param defaultValue The default value instead of null
* @return The value of a field's index contained in this record, or
* defaultValue, if null
* @throws IllegalArgumentException If the argument index is not contained
* in the record
* @throws DataTypeException wrapping data type conversion exception that
* might have occurred
* @see Convert#convert(Object, Converter)
* @deprecated - 3.3.0 - [#2878] - This method will be removed in jOOQ 4.0
*/
@Deprecated
U getValue(int index, Converter, U> converter, U defaultValue) throws IllegalArgumentException,
DataTypeException;
/**
* Set a value into this record.
*
* This will always set the {@link #changed(Field)} flag for the given
* field, no matter if setting the value actually changes the
* value.
*
* Changing {@link Table#getPrimaryKey()} values will set all
* {@link #changed()} flags to true, in order to produce complete
* INSERT statements on subsequent
* {@link UpdatableRecord#store()} operations.
*
* @param The generic field parameter
* @param field The field
* @param value The value
*/
void setValue(Field field, T value);
/**
* Set a value into this record.
*
* This will always set the {@link #changed(Field)} flag for the given
* field, no matter if setting the value actually changes the
* value.
*
* Changing {@link Table#getPrimaryKey()} values will set all
* {@link #changed()} flags to true, in order to produce complete
* INSERT statements on subsequent
* {@link UpdatableRecord#store()} operations.
*
* @param The generic field parameter
* @param The conversion type parameter
* @param field The field
* @param value The value
* @param converter The converter used to convert value into an
* appropriate type
*/
void setValue(Field field, U value, Converter converter);
/**
* Get the number of fields of this record.
*/
int size();
/**
* Get this record containing the original values as fetched from the
* database.
*
* 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.
*
* @see #original(Field)
* @see #original(int)
* @see #original(String)
*/
Record original();
/**
* Get an original value from this record as fetched from the database.
*
* 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.
*
* @see #original()
*/
T original(Field field);
/**
* Get an original value from this record as fetched from the database.
*
* 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.
*
* @see #original()
*/
Object original(int fieldIndex);
/**
* Get an original value from this record as fetched from the database.
*
* 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.
*
* @see #original()
*/
Object original(String fieldName);
/**
* Check if this record has been changed from its original as fetched from
* the database.
*
* If this returns false, then it can be said that
* record.equals(record.original()) is true.
*
* @see #original()
* @see #changed(Field)
* @see #changed(int)
* @see #changed(String)
*/
boolean changed();
/**
* Check if a field's value has been changed from its original as fetched
* from the database.
*
* @see #changed()
* @see #original(Field)
*/
boolean changed(Field> field);
/**
* Check if a field's value has been changed from its original as fetched
* from the database.
*
* @see #changed()
* @see #original(int)
*/
boolean changed(int fieldIndex);
/**
* Check if a field's value has been changed from its original as fetched
* from the database.
*
* @see #changed()
* @see #original(String)
*/
boolean changed(String fieldName);
/**
* Set all of this record's internal changed flags to the supplied value.
*
* If the changed argument is false, the
* {@link #original()} values will be reset to the corresponding "current"
* values as well
*
* @see #changed()
* @see #changed(Field, boolean)
* @see #changed(int, boolean)
* @see #changed(String, boolean)
*/
void changed(boolean changed);
/**
* Set this record's internal changed flag to the supplied value for a given
* field.
*
* If the changed argument is false, the
* {@link #original(Field)} value will be reset to the corresponding
* "current" value as well
*
* @see #changed()
* @see #changed(Field)
*/
void changed(Field> field, boolean changed);
/**
* Set this record's internal changed flag to the supplied value for a given
* field.
*
* If the changed argument is false, the
* {@link #original(int)} value will be reset to the corresponding "current"
* value as well
*
* @see #changed()
* @see #changed(int)
*/
void changed(int fieldIndex, boolean changed);
/**
* Set this record's internal changed flag to the supplied value for a given
* field.
*
* If the changed argument is false, the
* {@link #original(String)} value will be reset to the corresponding
* "current" value as well
*
* @see #changed()
* @see #changed(String)
*/
void changed(String fieldName, boolean changed);
/**
* Reset all values to their {@link #original()} values and all
* {@link #changed()} flags to false.
*/
void reset();
/**
* Reset a given value to its {@link #original(Field)} value and its
* {@link #changed(Field)} flag to false.
*/
void reset(Field> field);
/**
* Reset a given value to its {@link #original(int)} value and its
* {@link #changed(int)} flag to false.
*/
void reset(int fieldIndex);
/**
* Reset a given value to its {@link #original(String)} value and its
* {@link #changed(String)} flag to false.
*/
void reset(String fieldName);
/**
* Convert this record into an array.
*
* 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)
*
* @return This record as an array
* @see #fromArray(Object...)
*/
Object[] intoArray();
/**
* Return this record as a name/value map.
*
* This is the inverse operation to {@link #fromMap(Map)}
*
* @return This record as a map
* @see #fromMap(Map)
*/
Map intoMap();
/**
* Map resulting records onto a custom type.
*
* This will map this record onto your custom type using a
* {@link RecordMapper} as provided by
* {@link Configuration#recordMapperProvider()}. If no custom provider is
* specified, the {@link DefaultRecordMapperProvider} is used.
*
* @param The generic entity type.
* @param type The entity type.
* @throws MappingException wrapping any reflection exception that might
* have occurred while mapping records
* @see #from(Object)
* @see DefaultRecordMapper
*/
E into(Class extends E> type) throws MappingException;
/**
* Map resulting records onto a custom type.
*
* This is the same as {@link #into(Class)}, except that no new object is
* instanciated as a result. Instead, you can provide your own custom POJO
* instance.
*
* @param The generic entity type.
* @param object The receiving bean.
* @throws MappingException wrapping any reflection exception that might
* have occurred while mapping records
* @throws NullPointerException if object is null
* @see #from(Object)
*/
E into(E object) throws MappingException;
/**
* Map resulting records onto a custom record type.
*
* The mapping algorithm is this:
*
*
jOOQ will map Record values by equal field names:
*
*
* - For every field in the
table argument with
* {@link Field#getName()} "MY_field" (case-sensitive!), a
* corresponding field with the same name in this record will be searched.
* - If several fields in this record share the same
* {@link Field#getName()}, then the first one returning true on
* {@link Field#equals(Object)} will be returned. (e.g. qualified field
* names match)
*
*
*
Other restrictions
*
*
* - {@link Table#getRecordType()} must return a class of type
* {@link TableRecord}, which must provide a default constructor. Non-public
* default constructors are made accessible using
* {@link Constructor#setAccessible(boolean)}
*
*
* @param The generic table record type.
* @param table The table type.
*/
R into(Table table);
/**
* Generate an in-memory JDBC {@link ResultSet} containing the data of this
* Record.
*
* Use this as an adapter for JDBC-compliant code that expects a
* {@link ResultSet} to operate on, rather than a jOOQ {@link Result}. The
* returned ResultSet allows for the following behaviour
* according to the JDBC specification:
*
* - {@link ResultSet#CLOSE_CURSORS_AT_COMMIT}: The cursors (i.e.
* {@link Statement} object) are no longer available
* - {@link ResultSet#CONCUR_READ_ONLY}: You cannot update the database
* through this
ResultSet, as the underlying {@link Result}
* object does not hold any open database refences anymore
* - {@link ResultSet#FETCH_FORWARD}: The fetch direction is forward only,
* and cannot be changed
* - {@link ResultSet#TYPE_SCROLL_INSENSITIVE}: You can use any of the
*
ResultSet's scrolling methods, e.g. {@link ResultSet#next()}
* or {@link ResultSet#previous()}, etc.
*
*
* You may use {@link DSLContext#fetch(ResultSet)} to unwind this wrapper
* again.
*
* This is the same as creating a new {@link Result} with this
* Record only, and then calling {@link Result#intoResultSet()}
* on that Result
*
* @return A wrapper JDBC ResultSet
*/
ResultSet intoResultSet();
/**
* Map this record into a custom mapper callback.
*
* @param mapper The mapper callback
* @return The custom mapped record
*/
E map(RecordMapper mapper);
/**
* Load data into this record from a source.
*
* The mapping algorithm is this:
*
*
If source is an array
*
* Loading of data is delegated to {@link #fromArray(Object...)}
*
*
If source is a {@link Map}
*
*
* Loading of data is delegated to {@link #fromMap(Map)}
*
*
If any JPA {@link Column} annotations are found on the {@link Class}
* of the provided source, only those are used. Matching
* candidates are:
*
*
* - Public no-argument instance methods annotated with
*
Column
* - Public no-argument instance methods starting with
getXXX
* or isXXX, if there exists a matching public single-argument
* setXXX() instance method that is annotated with
* Column
* - Public instance member fields annotated with
Column
*
* Additional matching rules:
*
* - {@link Column#name()} must match {@link Field#getName()}. All other
* annotation attributes are ignored
* - Only the first match per field is used
* - Matching methods have a higher priority than matching member fields
* - Explicitly matching methods have a higher priority than implicitly
* matching methods (implicitly matching getter = setter is annotated)
* - Static methods / member fields are ignored
*
*
*
If there are no JPA Column annotations, or jOOQ can't
* find the javax.persistence API on the classpath, jOOQ will
* map members by naming convention:
*
* If {@link Field#getName()} is MY_field (case-sensitive!),
* then this field's value will be fetched from the first of these:
*
* - Public no-argument instance method
MY_field()
* - Public no-argument instance method
myField()
* - Public no-argument instance method
getMY_field()
* - Public no-argument instance method
getMyField()
* - Public instance member field
MY_field
* - Public instance member field
myField
*
*
*
Other restrictions
*
*
* - primitive types are supported.
*
*
*
General notes
*
* The resulting record will have its internal "changed" flags set to true
* for all values. This means that {@link UpdatableRecord#store()} will
* perform an INSERT statement. If you wish to store the record
* using an UPDATE statement, use
* {@link DSLContext#executeUpdate(UpdatableRecord)} instead.
*
* This is the same as calling
* record.from(source, record.fields())
*
* @param source The source object to copy data from
* @throws MappingException wrapping any reflection exception that might
* have occurred while mapping records
* @see #into(Class)
* @see #from(Object, Field...)
*/
void from(Object source) throws MappingException;
/**
* Load data into this record from a source, providing some fields.
*
* This is the same as {@link #from(Object)}, except that only fields
* contained in the fields argument will be mapped.
*
* @param source The source object to copy data from
* @param fields The record's fields to use for mapping
* @throws MappingException wrapping any reflection exception that might
* have occurred while mapping records
* @see #into(Class)
* @see #from(Object)
*/
void from(Object source, Field>... fields) throws MappingException;
/**
* Load data into this record from a source, providing some field names.
*
* This is the same as {@link #from(Object)}, except that only fields
* contained in the fieldNames argument will be mapped.
*
* @param source The source object to copy data from
* @param fieldNames The record's fields names to use for mapping
* @throws MappingException wrapping any reflection exception that might
* have occurred while mapping records
* @see #into(Class)
* @see #from(Object)
*/
void from(Object source, String... fieldNames) throws MappingException;
/**
* Load data into this record from a source, providing some field indexes.
*
* This is the same as {@link #from(Object)}, except that only fields
* contained in the fieldIndexes argument will be mapped.
*
* @param source The source object to copy data from
* @param fieldIndexes The record's fields indexes to use for mapping
* @throws MappingException wrapping any reflection exception that might
* have occurred while mapping records
* @see #into(Class)
* @see #from(Object)
*/
void from(Object source, int... fieldIndexes) throws MappingException;
/**
* 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
* {@link #field(String)}. Missing fields will be left untouched. Excess
* fields will be ignored.
*
* This is the inverse operation to {@link #intoMap()}. This is the same as
* calling record.fromMap(map, record.fields())
*
* @see #intoMap()
* @see #fromMap(Map, Field...)
*/
void fromMap(Map map);
/**
* Load data from a map into this record, providing some fields.
*
* The argument map is expected to hold field-name / value pairs where
* field-names correspond to actual field names as provided by
* {@link #field(String)}. Missing fields will be left untouched. Excess
* fields will be ignored.
*
* This is the same as {@link #fromMap(Map)}, except that only fields
* contained in the fields argument will be mapped.
*
* @see #intoMap()
* @see #fromMap(Map)
*/
void fromMap(Map map, Field>... fields);
/**
* Load data from a map into this record, providing some field names.
*
* The argument map is expected to hold field-name / value pairs where
* field-names correspond to actual field names as provided by
* {@link #field(String)}. Missing fields will be left untouched. Excess
* fields will be ignored.
*
* This is the same as {@link #fromMap(Map)}, except that only fields
* contained in the fieldNames argument will be mapped.
*
* @see #intoMap()
* @see #fromMap(Map)
*/
void fromMap(Map map, String... fieldNames);
/**
* Load data from a map into this record, providing some field indexes.
*
* The argument map is expected to hold field-name / value pairs where
* field-names correspond to actual field names as provided by
* {@link #field(String)}. Missing fields will be left untouched. Excess
* fields will be ignored.
*
* This is the same as {@link #fromMap(Map)}, except that only fields
* contained in the fieldIndexes argument will be mapped.
*
* @see #intoMap()
* @see #fromMap(Map)
*/
void fromMap(Map map, int... fieldIndexes);
/**
* Load data from an array into this 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 {@link #intoArray()}
*
* @see #intoArray()
* @see #fromArray(Object[], Field...)
*/
void fromArray(Object... array);
/**
* Load data from an array into this record, providing some fields.
*
* 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 same as {@link #fromArray(Object...)}, except that only
* fields contained in the fields argument will be mapped.
*
* @see #intoArray()
* @see #fromArray(Object...)
*/
void fromArray(Object[] array, Field>... fields);
/**
* Load data from an array into this record, providing some fields names.
*
* 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 same as {@link #fromArray(Object...)}, except that only
* fields contained in the fieldNames argument will be mapped.
*
* @see #intoArray()
* @see #fromArray(Object...)
*/
void fromArray(Object[] array, String... fieldNames);
/**
* Load data from an array into this record, providing some fields indexes.
*
* 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 same as {@link #fromArray(Object...)}, except that only
* fields contained in the fieldIndexes argument will be
* mapped.
*
* @see #intoArray()
* @see #fromArray(Object...)
*/
void fromArray(Object[] array, int... fieldIndexes);
// -------------------------------------------------------------------------
// Inherited methods
// -------------------------------------------------------------------------
/**
* Get a hash code of this Record, based on the underlying row
* value expression.
*
* In order to fulfill the general contract of {@link Object#hashCode()} and
* {@link Object#equals(Object)}, a Record's hash code value
* depends on all hash code values of this Record's underlying
* column values.
*
* @return A hash code value for this record
* @see #equals(Object)
*/
@Override
int hashCode();
/**
* Compare this Record with another Record for
* equality.
*
* Two records are considered equal if
*
* - They have the same degree
* - For every
i BETWEEN 0 AND degree, r1[i] = r2[i]
*
*
* Note, that the above rules correspond to the SQL comparison predicate
* behaviour as illustrated in the following example:
* -- A row value expression comparison predicate
* SELECT *
* FROM my_table
* WHERE (1, 'A') = (1, 'A')
*
*
* Unlike SQL, jOOQ allows to compare also incompatible records, e.g.
* records
*
* - ... whose degrees are not equal (results in
false)
* - ... whose column types are not equal (results in
false)
* - ... whose record types are not equal (irrelevant for the result)
*
*
* It can be said that for all R1, R2, if R1.equal(R2), then
* R1.compareTo(R2) == 0
*
* @param other The other record
* @return Whether the two records are equal
* @see #compareTo(Record)
* @see #hashCode()
*/
@Override
boolean equals(Object other);
/**
* Compares this Record with another Record
* according to their natural ordering.
*
* jOOQ Records implement {@link Comparable} to allow for naturally ordering
* Records in a "SQL way", i.e. according to the following rules:
*
*
Records being compared must have the same ROW type
*
* Two Records are comparable if and only if they have the same
* ROW type, i.e. if their {@link Record#fieldsRow()
* fieldsRow()} methods return fields of the same type and degree.
*
*
Comparison rules
*
* 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.
*
* Then, for two comparable Records 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 {@link Row1#lessThan(Row1)}, {@link Row2#lessThan(Row2)}, ...,
* {@link Row22#lessThan(Row22)} for more details about row value expression
* comparison predicates
*
* Alternative sorting behaviour can be achieved through
* {@link Result#sortAsc(java.util.Comparator)} and similar methods.
*
* @throws NullPointerException If the argument record is null
* @throws ClassCastException If the argument record is not comparable with
* this record according to the above rules.
*/
@Override
int compareTo(Record record);
}