org.jooq.Record Maven / Gradle / Ivy
/**
* Copyright (c) 2009-2015, Data Geekery GmbH (http://www.datageekery.com)
* All rights reserved.
*
* 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.
*
* Other licenses:
* -----------------------------------------------------------------------------
* Commercial licenses for this work are available. These replace the above
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
* database integrations.
*
* For more information, please visit: http://www.jooq.org/licenses
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
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.List;
import java.util.Map;
import javax.annotation.Generated;
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.
*
* If this record contains a field with the same {@link Field#getName()} as
* the argument field, that value is retrieved.
*
* @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.
*
* If this record contains a field with the same {@link Field#getName()} as
* the argument field, that value is retrieved.
*
* @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.
*
* If this record contains a field with the same {@link Field#getName()} as
* the argument field, that value is retrieved.
*
* @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();
/**
* Convert this record into a list.
*
* The resulting list 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.intoList().get(i)
*
*
* This is the same as calling Arrays.asList(intoArray())
*/
List