From cbd9e9ef01c6b34f102aa24b3892fa883e7ee595 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Thu, 26 Nov 2020 15:31:06 +0100 Subject: [PATCH] [jOOQ/jOOQ#11031] Extract common API from Cursor | Record | RecordType | Result | Row | TableLike | UDT to new Fields type --- jOOQ/src/main/java/org/jooq/Cursor.java | 125 +------ jOOQ/src/main/java/org/jooq/Fields.java | 307 ++++++++++++++++++ jOOQ/src/main/java/org/jooq/Record.java | 149 +-------- jOOQ/src/main/java/org/jooq/RecordType.java | 259 +-------------- jOOQ/src/main/java/org/jooq/Result.java | 173 +--------- jOOQ/src/main/java/org/jooq/Row.java | 267 +-------------- jOOQ/src/main/java/org/jooq/TableLike.java | 200 +----------- jOOQ/src/main/java/org/jooq/UDT.java | 135 +------- .../java/org/jooq/impl/AbstractCursor.java | 82 ++++- .../java/org/jooq/impl/AbstractDMLQuery.java | 2 +- .../java/org/jooq/impl/AbstractRecord.java | 97 +++++- .../main/java/org/jooq/impl/AbstractRow.java | 19 +- .../java/org/jooq/impl/AbstractTable.java | 44 ++- .../java/org/jooq/impl/AliasedSelect.java | 4 +- jOOQ/src/main/java/org/jooq/impl/Array.java | 4 +- .../main/java/org/jooq/impl/ArrayTable.java | 18 +- .../org/jooq/impl/ArrayTableEmulation.java | 16 +- .../jooq/impl/CommonTableExpressionImpl.java | 8 +- .../main/java/org/jooq/impl/CursorImpl.java | 3 +- jOOQ/src/main/java/org/jooq/impl/DSL.java | 48 +-- .../org/jooq/impl/DefaultRecordContext.java | 8 +- .../org/jooq/impl/DefaultRecordMapper.java | 6 +- .../main/java/org/jooq/impl/DerivedTable.java | 4 +- jOOQ/src/main/java/org/jooq/impl/Dual.java | 4 +- .../impl/{Fields.java => FieldsImpl.java} | 30 +- .../java/org/jooq/impl/FunctionTable.java | 4 +- .../java/org/jooq/impl/GenerateSeries.java | 4 +- .../main/java/org/jooq/impl/HintedTable.java | 2 +- .../java/org/jooq/impl/InsertQueryImpl.java | 2 +- jOOQ/src/main/java/org/jooq/impl/Intern.java | 6 +- .../main/java/org/jooq/impl/JSONTable.java | 6 +- .../main/java/org/jooq/impl/JoinTable.java | 6 +- jOOQ/src/main/java/org/jooq/impl/Lateral.java | 4 +- .../main/java/org/jooq/impl/MergeImpl.java | 4 +- .../org/jooq/impl/MetaDataFieldProvider.java | 10 +- .../main/java/org/jooq/impl/ResultImpl.java | 6 +- .../src/main/java/org/jooq/impl/RowImplN.java | 2 +- .../src/main/java/org/jooq/impl/RowsFrom.java | 6 +- .../src/main/java/org/jooq/impl/SQLTable.java | 4 +- .../main/java/org/jooq/impl/SelectImpl.java | 42 +++ .../java/org/jooq/impl/SelectQueryImpl.java | 46 ++- .../main/java/org/jooq/impl/TableAlias.java | 8 +- .../main/java/org/jooq/impl/TableImpl.java | 6 +- .../java/org/jooq/impl/TableRecordImpl.java | 2 +- jOOQ/src/main/java/org/jooq/impl/Tools.java | 2 +- jOOQ/src/main/java/org/jooq/impl/UDTImpl.java | 78 ++++- jOOQ/src/main/java/org/jooq/impl/Values.java | 6 +- .../src/main/java/org/jooq/impl/XMLTable.java | 6 +- 48 files changed, 847 insertions(+), 1427 deletions(-) create mode 100644 jOOQ/src/main/java/org/jooq/Fields.java rename jOOQ/src/main/java/org/jooq/impl/{Fields.java => FieldsImpl.java} (95%) diff --git a/jOOQ/src/main/java/org/jooq/Cursor.java b/jOOQ/src/main/java/org/jooq/Cursor.java index ab13043643..0754eb92a9 100644 --- a/jOOQ/src/main/java/org/jooq/Cursor.java +++ b/jOOQ/src/main/java/org/jooq/Cursor.java @@ -77,7 +77,7 @@ import org.jetbrains.annotations.Nullable; * @param The cursor's record type * @author Lukas Eder */ -public interface Cursor extends Iterable, Formattable , AutoCloseable { +public interface Cursor extends Fields, Iterable, Formattable , AutoCloseable { /** * Get this cursor's row type. @@ -85,129 +85,6 @@ public interface Cursor extends Iterable, Formattable , Aut @NotNull RecordType recordType(); - /** - * Get this cursor's fields as a {@link Row}. - */ - @NotNull - Row fieldsRow(); - - /** - * Get a specific field from this Cursor. - *

- * This will return: - *

    - *
  • A field that is the same as the argument field (by identity - * comparison).
  • - *
  • A field that is equal to the argument field (exact matching fully - * qualified name).
  • - *
  • A field that is equal to the argument field (partially matching - * qualified name).
  • - *
  • A field whose name is equal to the name of the argument field.
  • - *
  • null otherwise. - *
- * If several fields have the same name, the first one is returned and a - * warning is logged. - * - * @see Row#field(Field) - */ - @Nullable - Field field(Field field); - - /** - * Get a specific field from this Cursor. - * - * @see Row#field(String) - */ - @Nullable - Field field(String name); - - /** - * Get a specific qualified field from this Cursor. - * - * @see Row#field(Name) - */ - @Nullable - Field field(Name name); - - /** - * Get a specific field from this Cursor. - * - * @see Row#field(int) - */ - @Nullable - Field field(int index); - - /** - * Get all fields from this Cursor. - * - * @see Row#fields() - */ - @NotNull - Field[] fields(); - - /** - * Get all fields from this Cursor, providing some fields. - * - * @return All available fields - * @see Row#fields(Field...) - */ - @NotNull - Field[] fields(Field... fields); - - /** - * Get all fields from this Cursor, providing some field names. - * - * @return All available fields - * @see Row#fields(String...) - */ - @NotNull - Field[] fields(String... fieldNames); - - /** - * Get all fields from this Cursor, providing some field names. - * - * @return All available fields - * @see Row#fields(Name...) - */ - @NotNull - Field[] fields(Name... fieldNames); - - /** - * Get all fields from this Cursor, providing some field indexes. - * - * @return All available fields - * @see Row#fields(int...) - */ - @NotNull - Field[] fields(int... fieldIndexes); - - /** - * Get a field's index from this cursor. - * - * @param field The field to look for - * @return The field's index or -1 if the field is not - * contained in this cursor. - */ - int indexOf(Field field); - - /** - * Get a field's index from this cursor. - * - * @param fieldName The field name to look for - * @return The field's index or -1 if the field is not - * contained in this cursor. - */ - int indexOf(String fieldName); - - /** - * Get a field's index from this cursor. - * - * @param fieldName The field name to look for - * @return The field's index or -1 if the field is not - * contained in this cursor - */ - int indexOf(Name fieldName); - /** * Check whether this cursor has a next record. *

diff --git a/jOOQ/src/main/java/org/jooq/Fields.java b/jOOQ/src/main/java/org/jooq/Fields.java new file mode 100644 index 0000000000..40ffec2317 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/Fields.java @@ -0,0 +1,307 @@ +/* + * 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.util.stream.Stream; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * A common super type for various types that can provide a set of fields, + * similar to a {@link Record}. + * + * @author Lukas Eder + */ +public interface Fields { + + /** + * Get all fields. + */ + @NotNull + Field[] fields(); + + /** + * Get all fields as a {@link Row}. + */ + @NotNull + Row fieldsRow(); + + + + /** + * Get this table's fields as a {@link Stream}, if this table knows its + * field references. + */ + @NotNull + Stream> fieldStream(); + + + + /** + * Get a field by field reference. + *

+ * This will return: + *

    + *
  • A field that is the same as the argument field (by identity + * comparison).
  • + *
  • A field that is equal to the argument field (exact matching fully + * qualified name).
  • + *
  • A field that is equal to the argument field (partially matching + * qualified name).
  • + *
  • A field whose name is equal to the name of the argument field.
  • + *
  • null otherwise. + *
+ * If several fields have the same name, the first one is returned and a + * warning is logged. + */ + @Nullable + Field field(Field field); + + /** + * Get a field by unqualified name. + * + * @param name The unqualified name of the field + */ + @Nullable + Field field(String name); + + /** + * Get a field by unqualified name coerced to type. + * + * @param name The unqualified name of the field + * @param type The type to coerce the resulting field to + */ + @Nullable + Field field(String name, Class type); + + /** + * Get a field by unqualified name coerced to dataType. + * + * @param name The unqualified name of the field + * @param dataType The data type to coerce the resulting field to + */ + @Nullable + Field field(String name, DataType dataType); + + /** + * Get a field by qualified name. + * + * @param name The qualified name of the field + */ + @Nullable + Field field(Name name); + + /** + * Get a field by qualified name coerced to type. + * + * @param name The qualified name of the field + * @param type The type to coerce the resulting field to + */ + @Nullable + Field field(Name name, Class type); + + /** + * Get a field by qualified name coerced to dataType. + * + * @param name The qualified name of the field + * @param dataType The data type to coerce the resulting field to + */ + @Nullable + Field field(Name name, DataType dataType); + + /** + * Get a field by index. + * + * @param index The 0-based index of the field + */ + @Nullable + Field field(int index); + + /** + * Get a field by index coerced to type. + * + * @param index The 0-based index of the field + * @param type The type to coerce the resulting field to + */ + @Nullable + Field field(int index, Class type); + + /** + * Get a field by index coerced to dataType. + * + * @param index The 0-based index of the field + * @param dataType The data type to coerce the resulting field to + */ + @Nullable + Field field(int index, DataType dataType); + + /** + * Get all fields, filtering by some fields. + * + * @param fields The fields to include after looking them up via + * {@link #field(Field)}. + * @see #field(Field) + */ + @NotNull + Field[] fields(Field... fields); + + /** + * Get all fields, filtering by some unqualified field names. + * + * @param names The unqualified field names to include after looking them up + * via {@link #field(String)}. + * @see #field(String) + */ + @NotNull + Field[] fields(String... names); + + /** + * Get all fields, filtering by some qualified field names. + * + * @param names The qualified field names to include after looking them up + * via {@link #field(Name)}. + * @see #field(Name) + */ + @NotNull + Field[] fields(Name... names); + + /** + * Get all fields, filtering by some field indexes. + * + * @param names The 0-based field indexes to include after looking them up + * via {@link #field(int)}. + * @see #field(int) + */ + @NotNull + Field[] fields(int... indexes); + + /** + * Get a field's index from this type. + * + * @param field The field to look for + * @return The field's 0-based index or -1 if the field is not + * available. + */ + int indexOf(Field field); + + /** + * Get a field's index from this type. + * + * @param name The unqualified field name to look for + * @return The field's 0-based index or -1 if the field is not + * available. + */ + int indexOf(String name); + + /** + * Get a field's index from this type. + * + * @param name The qualified field name to look for + * @return The field's 0-based index or -1 if the field is not + * available. + */ + int indexOf(Name name); + + /** + * Get an array of field types for this type. + *

+ * Entries in the resulting array correspond to {@link Field#getType()} for + * the corresponding Field in {@link #fields()} + */ + @NotNull + Class[] types(); + + /** + * Get the field type for a given field index. + * + * @param index The field's 0-based index + */ + @Nullable + Class type(int index); + + /** + * Get the field type for a given unqualified field name. + * + * @param name The unqualified field name + */ + @Nullable + Class type(String name); + + /** + * Get the field type for a given qualified field name. + * + * @param name The qualified field name + */ + @Nullable + Class type(Name name); + + /** + * Get an array of field data types for this type. + *

+ * Entries in the resulting array correspond to {@link Field#getDataType()} for + * the corresponding Field in {@link #fields()} + */ + @NotNull + DataType[] dataTypes(); + + /** + * Get the field data type for a given field index. + * + * @param index The field's 0-based index + */ + @Nullable + DataType dataType(int index); + + /** + * Get the field data type for a given qualified field name. + * + * @param name The qualified field name + */ + @Nullable + DataType dataType(String name); + + /** + * Get the field data type for a given qualified field name. + * + * @param name The qualified field name + */ + @Nullable + DataType dataType(Name name); + +} diff --git a/jOOQ/src/main/java/org/jooq/Record.java b/jOOQ/src/main/java/org/jooq/Record.java index 8a8b84e29b..168ca44826 100644 --- a/jOOQ/src/main/java/org/jooq/Record.java +++ b/jOOQ/src/main/java/org/jooq/Record.java @@ -125,130 +125,7 @@ import org.jetbrains.annotations.Nullable; * @author Lukas Eder * @see Result */ -public interface Record extends Attachable, Comparable, Formattable { - - /** - * Get this record's fields as a {@link Row}. - */ - @NotNull - Row fieldsRow(); - - /** - * Get a specific field from this Record. - *

- * This will return: - *

    - *
  • A field that is the same as the argument field (by identity - * comparison).
  • - *
  • A field that is equal to the argument field (exact matching fully - * qualified name).
  • - *
  • A field that is equal to the argument field (partially matching - * qualified name).
  • - *
  • A field whose name is equal to the name of the argument field.
  • - *
  • null otherwise. - *
- * If several fields have the same name, the first one is returned and a - * warning is logged. - * - * @see Row#field(Field) - */ - @Nullable - Field field(Field field); - - /** - * Get a specific field from this Record. - * - * @see Row#field(String) - */ - @Nullable - Field field(String name); - - /** - * Get a specific qualified field from this Record. - * - * @see Row#field(Name) - */ - @Nullable - Field field(Name name); - - /** - * Get a specific field from this Record. - * - * @see Row#field(int) - */ - @Nullable - Field field(int index); - - /** - * Get all fields from this Record. - * - * @see Row#fields() - */ - @NotNull - Field[] fields(); - - /** - * Get all fields from this Record, providing some fields. - * - * @return All available fields - * @see Row#fields(Field...) - */ - @NotNull - Field[] fields(Field... fields); - - /** - * Get all fields from this Record, providing some field names. - * - * @return All available fields - * @see Row#fields(String...) - */ - @NotNull - Field[] fields(String... fieldNames); - - /** - * Get all fields from this Record, providing some field names. - * - * @return All available fields - * @see Row#fields(Name...) - */ - @NotNull - Field[] fields(Name... fieldNames); - - /** - * Get all fields from this Record, providing some field indexes. - * - * @return All available fields - * @see Row#fields(int...) - */ - @NotNull - Field[] fields(int... fieldIndexes); - - /** - * Get a field's index from this record. - * - * @param field The field to look for - * @return The field's index or -1 if the field is not - * contained in this record. - */ - int indexOf(Field field); - - /** - * Get a field's index from this record. - * - * @param fieldName The field name to look for - * @return The field's index or -1 if the field is not - * contained in this record. - */ - int indexOf(String fieldName); - - /** - * Get a field's index from this record. - * - * @param fieldName The field name to look for - * @return The field's index or -1 if the field is not - * contained in this record - */ - int indexOf(Name fieldName); +public interface Record extends Fields, Attachable, Comparable, Formattable { /** * Get this record's values as a {@link Row}. @@ -398,7 +275,7 @@ public interface Record extends Attachable, Comparable, Formattable { /** * Get a value from this record, providing a field index. * - * @param index The field's index + * @param index The 0-based field index in this record. * @return The value of a field's index contained in this record * @throws IllegalArgumentException If the argument index is not contained * in the record @@ -414,7 +291,7 @@ public interface Record extends Attachable, Comparable, Formattable { * value to U * * @param The conversion type parameter - * @param index The field's index + * @param index The 0-based field index in this record. * @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 @@ -428,7 +305,7 @@ public interface Record extends Attachable, Comparable, Formattable { * Get a converted value from this record, providing a field index. * * @param The conversion type parameter - * @param index The field's index + * @param index The 0-based field index in this record. * @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 @@ -533,6 +410,7 @@ public interface Record extends Attachable, Comparable, Formattable { * the database. Every record also references the originally fetched values. * This method returns such an original value for a field. * + * @param fieldIndex The 0-based field index in this record. * @see #original() */ @Nullable @@ -589,6 +467,7 @@ public interface Record extends Attachable, Comparable, Formattable { * Check if a field's value has been changed from its original as fetched * from the database. * + * @param fieldIndex The 0-based field index in this record. * @see #changed() * @see #original(int) */ @@ -647,6 +526,7 @@ public interface Record extends Attachable, Comparable, Formattable { * {@link #original(int)} value will be reset to the corresponding "current" * value as well * + * @param fieldIndex The 0-based field index in this record. * @see #changed() * @see #changed(int) */ @@ -693,6 +573,8 @@ public interface Record extends Attachable, Comparable, Formattable { /** * Reset a given value to its {@link #original(int)} value and its * {@link #changed(int)} flag to false. + * + * @param fieldIndex The 0-based field index in this record. */ void reset(int fieldIndex); @@ -1249,7 +1131,7 @@ public interface Record extends Attachable, Comparable, Formattable { * 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 + * @param fieldIndexes The record's 0-based field indexes to use for mapping * @throws MappingException wrapping any reflection exception that might * have occurred while mapping records * @see #into(Class) @@ -1332,6 +1214,7 @@ public interface Record extends Attachable, Comparable, Formattable { * This is the same as {@link #fromMap(Map)}, except that only fields * contained in the fieldIndexes argument will be mapped. * + * @param fieldIndexes The 0-based field indexes in this record. * @see #intoMap() * @see #fromMap(Map) */ @@ -1407,6 +1290,7 @@ public interface Record extends Attachable, Comparable, Formattable { * fields contained in the fieldIndexes argument will be * mapped. * + * @param fieldIndexes The 0-based field indexes in this record. * @see #intoArray() * @see #fromArray(Object...) */ @@ -1752,6 +1636,7 @@ public interface Record extends Attachable, Comparable, Formattable { * [#2211] Future versions of jOOQ might remove this method. It is * recommended to use {@link #get(int)} instead. * + * @param index The 0-based field index in this record. * @see #get(int) */ Object getValue(int index) throws IllegalArgumentException; @@ -1759,7 +1644,7 @@ public interface Record extends Attachable, Comparable, Formattable { /** * Get a value from this record, providing a field index. * - * @param index The field's index + * @param index The 0-based field index in this record. * @param defaultValue The default value instead of null * @return The value of a field's index contained in this record, or * defaultValue, if null @@ -1776,6 +1661,7 @@ public interface Record extends Attachable, Comparable, Formattable { * [#2211] Future versions of jOOQ might remove this method. It is * recommended to use {@link #get(int, Class)} instead. * + * @param index The 0-based field index in this record. * @see #get(int, Class) */ T getValue(int index, Class type) throws IllegalArgumentException, DataTypeException; @@ -1788,7 +1674,7 @@ public interface Record extends Attachable, Comparable, Formattable { * value to U * * @param The conversion type parameter - * @param index The field's index + * @param index The 0-based field index in this record. * @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 @@ -1808,6 +1694,7 @@ public interface Record extends Attachable, Comparable, Formattable { * [#2211] Future versions of jOOQ might remove this method. It is * recommended to use {@link #get(int, Converter)} instead. * + * @param index The 0-based field index in this record. * @see #get(int, Converter) */ U getValue(int index, Converter converter) throws IllegalArgumentException, DataTypeException; @@ -1816,7 +1703,7 @@ public interface Record extends Attachable, Comparable, Formattable { * Get a converted value from this record, providing a field index. * * @param The conversion type parameter - * @param index The field's index + * @param index The 0-based field index in this record. * @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 diff --git a/jOOQ/src/main/java/org/jooq/RecordType.java b/jOOQ/src/main/java/org/jooq/RecordType.java index c1233af837..554ba10272 100644 --- a/jOOQ/src/main/java/org/jooq/RecordType.java +++ b/jOOQ/src/main/java/org/jooq/RecordType.java @@ -37,9 +37,6 @@ */ package org.jooq; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - /** * A record type for {@link Table}, {@link Cursor}, {@link Result} and other * objects. @@ -54,265 +51,11 @@ import org.jetbrains.annotations.Nullable; * * @author Lukas Eder */ -public interface RecordType { +public interface RecordType extends Fields { /** * Get the degree of this record type. */ int size(); - /** - * Get a specific field from this record type. - *

- * This will return: - *

    - *
  • A field that is the same as the argument field (by identity - * comparison).
  • - *
  • A field that is equal to the argument field (exact matching fully - * qualified name).
  • - *
  • A field that is equal to the argument field (partially matching - * qualified name).
  • - *
  • A field whose name is equal to the name of the argument field.
  • - *
  • null otherwise. - *
- * If several fields have the same name, the first one is returned and a - * warning is logged. - * - * @param The generic field type - * @param field The field to fetch - * @return The field itself or an aliased field - */ - @Nullable - Field field(Field field); - - /** - * Get a specific field from this record type. - * - * @param fieldName The field to fetch - * @return The field with the given name - */ - @Nullable - Field field(String fieldName); - - /** - * Get a specific field from this record type coerced to type. - * - * @param fieldName The field to fetch - * @param type The type to coerce the resulting field to - * @return The field with the given name - */ - @Nullable - Field field(String fieldName, Class type); - - /** - * Get a specific field from this record type coerced to dataType. - * - * @param fieldName The field to fetch - * @param dataType The data type to coerce the resulting field to - * @return The field with the given name - */ - @Nullable - Field field(String fieldName, DataType dataType); - - /** - * Get a specific qualified field from this record type. - * - * @param fieldName The field to fetch - * @return The field with the given name - */ - @Nullable - Field field(Name fieldName); - - /** - * Get a specific field from this record type coerced to type. - * - * @param fieldName The field to fetch - * @param type The type to coerce the resulting field to - * @return The field with the given name - */ - @Nullable - Field field(Name fieldName, Class type); - - /** - * Get a specific field from this record type coerced to dataType. - * - * @param fieldName The field to fetch - * @param dataType The data type to coerce the resulting field to - * @return The field with the given name - */ - @Nullable - Field field(Name fieldName, DataType dataType); - - /** - * Get a specific field from this record type. - * - * @param fieldIndex The field's index of the field to fetch - * @return The field with the given name - */ - @Nullable - Field field(int fieldIndex); - - /** - * Get a specific field from this record type coerced to type. - * - * @param fieldIndex The field's index of the field to fetch - * @param type The type to coerce the resulting field to - * @return The field with the given name - */ - @Nullable - Field field(int fieldIndex, Class type); - - /** - * Get a specific field from this record type coerced to dataType. - * - * @param fieldIndex The field's index of the field to fetch - * @param dataType The data type to coerce the resulting field to - * @return The field with the given name - */ - @Nullable - Field field(int fieldIndex, DataType dataType); - - /** - * Get all fields from this record type. - * - * @return All available fields - */ - @NotNull - Field[] fields(); - - /** - * Get all fields from this record type, providing some fields. - * - * @return All available fields - * @see #field(Field) - */ - @NotNull - Field[] fields(Field... fields); - - /** - * Get all fields from this record type, providing some field names. - * - * @return All available fields - * @see #field(String) - */ - @NotNull - Field[] fields(String... fieldNames); - - /** - * Get all fields from this record type, providing some field names. - * - * @return All available fields - * @see #field(Name) - */ - @NotNull - Field[] fields(Name... fieldNames); - - /** - * Get all fields from this record type, providing some field indexes. - * - * @return All available fields - * @see #field(int) - */ - @NotNull - Field[] fields(int... fieldIndexes); - - /** - * Get a field's index from this record type. - * - * @param field The field to look for - * @return The field's index or -1 if the field is not - * contained in this Row - */ - int indexOf(Field field); - - /** - * Get a field's index from this record type. - * - * @param fieldName The field name to look for - * @return The field's index or -1 if the field is not - * contained in this Row - */ - int indexOf(String fieldName); - - /** - * Get a field's index from this record type. - * - * @param fieldName The field name to look for - * @return The field's index or -1 if the field is not - * contained in this Row - */ - int indexOf(Name fieldName); - - /** - * Get an array of types for this record type. - *

- * Entries in the resulting array correspond to {@link Field#getType()} for - * the corresponding Field in {@link #fields()} - */ - @NotNull - Class[] types(); - - /** - * Get the type for a given field index. - * - * @param fieldIndex The field's index of the field's type to fetch - * @return The field's type - */ - @Nullable - Class type(int fieldIndex); - - /** - * Get the type for a given field name. - * - * @param fieldName The field's name of the field's type to fetch - * @return The field's type - */ - @Nullable - Class type(String fieldName); - - /** - * Get the type for a given field name. - * - * @param fieldName The field's name of the field's type to fetch - * @return The field's type - */ - @Nullable - Class type(Name fieldName); - - /** - * Get an array of data types for this record type. - *

- * Entries in the resulting array correspond to {@link Field#getDataType()} - * for the corresponding Field in {@link #fields()} - */ - @NotNull - DataType[] dataTypes(); - - /** - * Get the data type for a given field index. - * - * @param fieldIndex The field's index of the field's data type to fetch - * @return The field's data type - */ - @Nullable - DataType dataType(int fieldIndex); - - /** - * Get the data type for a given field name. - * - * @param fieldName The field's name of the field's data type to fetch - * @return The field's data type - */ - @Nullable - DataType dataType(String fieldName); - - /** - * Get the data type for a given field name. - * - * @param fieldName The field's name of the field's data type to fetch - * @return The field's data type - */ - @Nullable - DataType dataType(Name fieldName); - } diff --git a/jOOQ/src/main/java/org/jooq/Result.java b/jOOQ/src/main/java/org/jooq/Result.java index 1e65c1fb67..710d19d7f9 100644 --- a/jOOQ/src/main/java/org/jooq/Result.java +++ b/jOOQ/src/main/java/org/jooq/Result.java @@ -60,7 +60,7 @@ import org.jetbrains.annotations.Nullable; * @author Lukas Eder * @see SelectQuery#getResult() */ -public interface Result extends List, Attachable, Formattable { +public interface Result extends Fields, List, Attachable, Formattable { /** * Get this result's record type. @@ -68,177 +68,6 @@ public interface Result extends List, Attachable, Formattab @NotNull RecordType recordType(); - /** - * Get this result's fields as a {@link Row}. - */ - @NotNull - Row fieldsRow(); - - /** - * Get a specific field from this Result. - *

- * This will return: - *

    - *
  • A field that is the same as the argument field (by identity - * comparison).
  • - *
  • A field that is equal to the argument field (exact matching fully - * qualified name).
  • - *
  • A field that is equal to the argument field (partially matching - * qualified name).
  • - *
  • A field whose name is equal to the name of the argument field.
  • - *
  • null otherwise. - *
- * If several fields have the same name, the first one is returned and a - * warning is logged. - * - * @see Row#field(Field) - */ - @Nullable - Field field(Field field); - - /** - * Get a specific field from this Result. - * - * @see Row#field(String) - */ - @Nullable - Field field(String name); - - /** - * Get a specific field from this Result, coerced to type. - * - * @see Row#field(String, Class) - */ - @Nullable - Field field(String name, Class type); - - /** - * Get a specific field from this Result, coerced to dataType. - * - * @see Row#field(String, DataType) - */ - @Nullable - Field field(String name, DataType dataType); - - /** - * Get a specific field from this Result. - * - * @see Row#field(Name) - */ - @Nullable - Field field(Name name); - - /** - * Get a specific field from this Result, coerced to type. - * - * @see Row#field(Name, Class) - */ - @Nullable - Field field(Name name, Class type); - - /** - * Get a specific field from this Result, coerced to dataType. - * - * @see Row#field(Name, DataType) - */ - @Nullable - Field field(Name name, DataType dataType); - - /** - * Get a specific field from this Result. - * - * @see Row#field(int) - */ - @Nullable - Field field(int index); - - /** - * Get a specific field from this Result, coerced to type. - * - * @see Row#field(int, Class) - */ - @Nullable - Field field(int index, Class type); - - /** - * Get a specific field from this Result, coerced to dataType. - * - * @see Row#field(int, DataType) - */ - @Nullable - Field field(int index, DataType dataType); - - /** - * Get all fields from this Result. - * - * @see Row#fields() - */ - @NotNull - Field[] fields(); - - /** - * Get all fields from this Result, providing some fields. - * - * @return All available fields - * @see Row#fields(Field...) - */ - @NotNull - Field[] fields(Field... fields); - - /** - * Get all fields from this Result, providing some field names. - * - * @return All available fields - * @see Row#fields(String...) - */ - @NotNull - Field[] fields(String... fieldNames); - - /** - * Get all fields from this Result, providing some field names. - * - * @return All available fields - * @see Row#fields(Name...) - */ - @NotNull - Field[] fields(Name... fieldNames); - - /** - * Get all fields from this Result, providing some field indexes. - * - * @return All available fields - * @see Row#fields(int...) - */ - @NotNull - Field[] fields(int... fieldIndexes); - - /** - * Get a field's index from this result. - * - * @param field The field to look for - * @return The field's index or -1 if the field is not - * contained in this result. - */ - int indexOf(Field field); - - /** - * Get a field's index from this result. - * - * @param fieldName The field name to look for - * @return The field's index or -1 if the field is not - * contained in this result. - */ - int indexOf(String fieldName); - - /** - * Get a field's index from this result. - * - * @param fieldName The field name to look for - * @return The field's index or -1 if the field is not - * contained in this result - */ - int indexOf(Name fieldName); - /** * Convenience method to fetch a value at a given position in the result. * diff --git a/jOOQ/src/main/java/org/jooq/Row.java b/jOOQ/src/main/java/org/jooq/Row.java index 2a396bc07d..7850641dbb 100644 --- a/jOOQ/src/main/java/org/jooq/Row.java +++ b/jOOQ/src/main/java/org/jooq/Row.java @@ -37,12 +37,9 @@ */ package org.jooq; -import java.util.stream.Stream; - import org.jooq.impl.DSL; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; /** * A row value expression. @@ -80,275 +77,13 @@ import org.jetbrains.annotations.Nullable; * * @author Lukas Eder */ -public interface Row extends FieldOrRow { +public interface Row extends Fields, FieldOrRow { /** * Get the degree of this row value expression. */ int size(); - - /** - * Get the fields from this row as a {@link Stream}. - */ - @NotNull - Stream> fieldStream(); - - - /** - * Get a specific field from this row. - *

- * This will return: - *

    - *
  • A field that is the same as the argument field (by identity - * comparison).
  • - *
  • A field that is equal to the argument field (exact matching fully - * qualified name).
  • - *
  • A field that is equal to the argument field (partially matching - * qualified name).
  • - *
  • A field whose name is equal to the name of the argument field.
  • - *
  • null otherwise. - *
- * If several fields have the same name, the first one is returned and a - * warning is logged. - * - * @param The generic field type - * @param field The field to fetch - * @return The field itself or an aliased field - */ - @Nullable - Field field(Field field); - - /** - * Get a specific field from this row. - * - * @param fieldName The field to fetch - * @return The field with the given name - */ - @Nullable - Field field(String fieldName); - - /** - * Get a specific field from this row and coerce it to type. - * - * @param fieldName The field to fetch - * @param type The type to coerce the resulting field to - * @return The field with the given name - */ - @Nullable - Field field(String fieldName, Class type); - - /** - * Get a specific field from this row and coerce it to dataType. - * - * @param fieldName The field to fetch - * @param dataType The type to coerce the resulting field to - * @return The field with the given name - */ - @Nullable - Field field(String fieldName, DataType dataType); - - /** - * Get a specific field from this row. - * - * @param fieldName The field to fetch - * @return The field with the given name - */ - @Nullable - Field field(Name fieldName); - - /** - * Get a specific field from this row and coerce it to type. - * - * @param fieldName The field to fetch - * @param type The type to coerce the resulting field to - * @return The field with the given name - */ - @Nullable - Field field(Name fieldName, Class type); - - /** - * Get a specific field from this row and coerce it to dataType. - * - * @param fieldName The field to fetch - * @param dataType The type to coerce the resulting field to - * @return The field with the given name - */ - @Nullable - Field field(Name fieldName, DataType dataType); - - /** - * Get a specific field from this row. - * - * @param fieldIndex The field's index of the field to fetch - * @return The field with the given name - */ - @Nullable - Field field(int fieldIndex); - - /** - * Get a specific field from this row and coerce it to type. - * - * @param fieldIndex The field's index of the field to fetch - * @param type The type to coerce the resulting field to - * @return The field with the given name - */ - @Nullable - Field field(int fieldIndex, Class type); - - /** - * Get a specific field from this row and coerce it to dataType. - * - * @param fieldIndex The field's index of the field to fetch - * @param dataType The type to coerce the resulting field to - * @return The field with the given name - */ - @Nullable - Field field(int fieldIndex, DataType dataType); - - /** - * Get all fields from this row. - * - * @return All available fields - */ - @NotNull - Field[] fields(); - - /** - * Get all fields from this row, providing some fields. - * - * @return All available fields - * @see #field(Field) - */ - @NotNull - Field[] fields(Field... fields); - - /** - * Get all fields from this row, providing some field names. - * - * @return All available fields - * @see #field(String) - */ - @NotNull - Field[] fields(String... fieldNames); - - /** - * Get all fields from this row, providing some field names. - * - * @return All available fields - * @see #field(Name) - */ - @NotNull - Field[] fields(Name... fieldNames); - - /** - * Get all fields from this row, providing some field indexes. - * - * @return All available fields - * @see #field(int) - */ - @NotNull - Field[] fields(int... fieldIndexes); - - /** - * Get a field's index from this row. - * - * @param field The field to look for - * @return The field's index or -1 if the field is not - * contained in this Row - */ - int indexOf(Field field); - - /** - * Get a field's index from this row. - * - * @param fieldName The field name to look for - * @return The field's index or -1 if the field is not - * contained in this Row - */ - int indexOf(String fieldName); - - /** - * Get a field's index from this row. - * - * @param fieldName The field name to look for - * @return The field's index or -1 if the field is not - * contained in this Row - */ - int indexOf(Name fieldName); - - /** - * Get an array of types for this row. - *

- * Entries in the resulting array correspond to {@link Field#getType()} for - * the corresponding Field in {@link #fields()} - */ - @NotNull - Class[] types(); - - /** - * Get the type for a given field index. - * - * @param fieldIndex The field's index of the field's type to fetch - * @return The field's type - */ - @Nullable - Class type(int fieldIndex); - - /** - * Get the type for a given field name. - * - * @param fieldName The field's name of the field's type to fetch - * @return The field's type - */ - @Nullable - Class type(String fieldName); - - /** - * Get the type for a given field name. - * - * @param fieldName The field's name of the field's type to fetch - * @return The field's type - */ - @Nullable - Class type(Name fieldName); - - /** - * Get an array of data types for this row. - *

- * Entries in the resulting array correspond to {@link Field#getDataType()} - * for the corresponding Field in {@link #fields()} - */ - @NotNull - DataType[] dataTypes(); - - /** - * Get the data type for a given field index. - * - * @param fieldIndex The field's index of the field's data type to fetch - * @return The field's data type - */ - @Nullable - DataType dataType(int fieldIndex); - - /** - * Get the data type for a given field name. - * - * @param fieldName The field's name of the field's data type to fetch - * @return The field's data type - */ - @Nullable - DataType dataType(String fieldName); - - /** - * Get the data type for a given field name. - * - * @param fieldName The field's name of the field's data type to fetch - * @return The field's data type - */ - @Nullable - DataType dataType(Name fieldName); - // ------------------------------------------------------------------------ // [NOT] NULL predicates // ------------------------------------------------------------------------ diff --git a/jOOQ/src/main/java/org/jooq/TableLike.java b/jOOQ/src/main/java/org/jooq/TableLike.java index 17cce58866..86712f4191 100644 --- a/jOOQ/src/main/java/org/jooq/TableLike.java +++ b/jOOQ/src/main/java/org/jooq/TableLike.java @@ -39,10 +39,8 @@ package org.jooq; import java.util.function.BiFunction; import java.util.function.Function; -import java.util.stream.Stream; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; /** * An object that can behave like a table (a table-like object). @@ -52,203 +50,7 @@ import org.jetbrains.annotations.Nullable; * @param The record type * @author Lukas Eder */ -public interface TableLike extends QueryPart { - - /** - * Get this table's fields as a {@link Row}, if this table knows its field - * references. - */ - @NotNull - Row fieldsRow(); - - - /** - * Get this table's fields as a {@link Stream}, if this table knows its - * field references. - */ - @NotNull - Stream> fieldStream(); - - - /** - * Get a specific field from this table, if this table knows its field - * references. - *

- * This will return: - *

    - *
  • A field that is the same as the argument field (by identity - * comparison).
  • - *
  • A field that is equal to the argument field (exact matching fully - * qualified name).
  • - *
  • A field that is equal to the argument field (partially matching - * qualified name).
  • - *
  • A field whose name is equal to the name of the argument field.
  • - *
  • null otherwise. - *
- * If several fields have the same name, the first one is returned and a - * warning is logged. - * - * @see Row#field(Field) - */ - @Nullable - Field field(Field field); - - /** - * Get a specific field from this table, if this table knows its field - * references. - * - * @see Row#field(String) - */ - @Nullable - Field field(String name); - - /** - * Get a specific field from this table and coerce it to type, - * if this table knows its field references. - * - * @see Row#field(String, Class) - */ - @Nullable - Field field(String name, Class type); - - /** - * Get a specific field from this table and coerce it to - * dataType, if this table knows its field references. - * - * @see Row#field(String, DataType) - */ - @Nullable - Field field(String name, DataType dataType); - - /** - * Get a specific field from this table, if this table knows its field - * references. - * - * @see Row#field(Name) - */ - @Nullable - Field field(Name name); - - /** - * Get a specific field from this table and coerce it to type, - * if this table knows its field references. - * - * @see Row#field(Name, Class) - */ - @Nullable - Field field(Name name, Class type); - - /** - * Get a specific field from this table and coerce it to - * dataType, if this table knows its field references. - * - * @see Row#field(Name, DataType) - */ - @Nullable - Field field(Name name, DataType dataType); - - /** - * Get a specific field from this table, if this table knows its field - * references. - * - * @see Row#field(int) - */ - @Nullable - Field field(int index); - - /** - * Get a specific field from this table and coerce it to type, - * if this table knows its field references. - * - * @see Row#field(int, Class) - */ - @Nullable - Field field(int index, Class type); - - /** - * Get a specific field from this table and coerce it to - * dataType, if this table knows its field references. - * - * @see Row#field(int, DataType) - */ - @Nullable - Field field(int index, DataType dataType); - - /** - * Get all fields from this table, if this table knows its field references, - * or an empty array otherwise. - * - * @see Row#fields() - */ - @NotNull - Field[] fields(); - - /** - * Get all fields from this table, providing some fields, if this table - * knows its field references. - * - * @return All available fields - * @see Row#fields(Field...) - */ - @NotNull - Field[] fields(Field... fields); - - /** - * Get all fields from this table, providing some field names, if this table - * knows its field references. - * - * @return All available fields - * @see Row#fields(String...) - */ - @NotNull - Field[] fields(String... fieldNames); - - /** - * Get all fields from this table, providing some field names, if this table - * knows its field references. - * - * @return All available fields - * @see Row#fields(Name...) - */ - @NotNull - Field[] fields(Name... fieldNames); - - /** - * Get all fields from this table, providing some field indexes, if this - * table knows its field references. - * - * @return All available fields - * @see Row#fields(int...) - */ - @NotNull - Field [] fields(int... fieldIndexes); - - /** - * Get a field's index from this table. - * - * @param field The field to look for - * @return The field's index or -1 if the field is not - * contained in this table. - */ - int indexOf(Field field); - - /** - * Get a field's index from this table. - * - * @param fieldName The field name to look for - * @return The field's index or -1 if the field is not - * contained in this table. - */ - int indexOf(String fieldName); - - /** - * Get a field's index from this table. - * - * @param fieldName The field name to look for - * @return The field's index or -1 if the field is not - * contained in this table - */ - int indexOf(Name fieldName); +public interface TableLike extends Fields, QueryPart { /** * The underlying table representation of this object. diff --git a/jOOQ/src/main/java/org/jooq/UDT.java b/jOOQ/src/main/java/org/jooq/UDT.java index 704112084f..8f6e172984 100644 --- a/jOOQ/src/main/java/org/jooq/UDT.java +++ b/jOOQ/src/main/java/org/jooq/UDT.java @@ -37,8 +37,6 @@ */ package org.jooq; -import java.util.stream.Stream; - import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -51,138 +49,7 @@ import org.jetbrains.annotations.Nullable; * @param The record type * @author Lukas Eder */ -public interface UDT> extends Qualified { - - /** - * Get this UDT's fields as a {@link Row}. - */ - @NotNull - Row fieldsRow(); - - - /** - * Get this table's fields as a {@link Stream}. - */ - @NotNull - Stream> fieldStream(); - - - /** - * Get a specific field from this UDT. - *

- * This will return: - *

    - *
  • A field that is the same as the argument field (by identity - * comparison).
  • - *
  • A field that is equal to the argument field (exact matching fully - * qualified name).
  • - *
  • A field that is equal to the argument field (partially matching - * qualified name).
  • - *
  • A field whose name is equal to the name of the argument field.
  • - *
  • null otherwise. - *
- * If several fields have the same name, the first one is returned and a - * warning is logged. - * - * @see Row#field(Field) - */ - @Nullable - Field field(Field field); - - /** - * Get a specific field from this UDT. - * - * @see Row#field(String) - */ - @Nullable - Field field(String name); - - /** - * Get a specific field from this UDT. - * - * @see Row#field(Name) - */ - @Nullable - Field field(Name name); - - /** - * Get a specific field from this UDT. - * - * @see Row#field(int) - */ - @Nullable - Field field(int index); - - /** - * Get all fields from this UDT. - * - * @see Row#fields() - */ - @Nullable - Field[] fields(); - - /** - * Get all fields from this UDT, providing some fields. - * - * @return All available fields - * @see Row#fields(Field...) - */ - @Nullable - Field[] fields(Field... fields); - - /** - * Get all fields from this UDT, providing some field names. - * - * @return All available fields - * @see Row#fields(String...) - */ - @Nullable - Field[] fields(String... fieldNames); - - /** - * Get all fields from this UDT, providing some field names. - * - * @return All available fields - * @see Row#fields(Name...) - */ - @Nullable - Field[] fields(Name... fieldNames); - - /** - * Get all fields from this UDT, providing some field indexes. - * - * @return All available fields - * @see Row#fields(int...) - */ - @Nullable - Field[] fields(int... fieldIndexes); - - /** - * Get a field's index from this udt. - * - * @param field The field to look for - * @return The field's index or -1 if the field is not - * contained in this udt. - */ - int indexOf(Field field); - - /** - * Get a field's index from this udt. - * - * @param fieldName The field name to look for - * @return The field's index or -1 if the field is not - * contained in this udt. - */ - int indexOf(String fieldName); - - /** - * Get a field's index from this udt. - * - * @param fieldName The field name to look for - * @return The field's index or -1 if the field is not - * contained in this udt - */ - int indexOf(Name fieldName); +public interface UDT> extends Fields, Qualified { /** * Get the UDT package. diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractCursor.java b/jOOQ/src/main/java/org/jooq/impl/AbstractCursor.java index 3beef9f4ca..d08212d9c7 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AbstractCursor.java +++ b/jOOQ/src/main/java/org/jooq/impl/AbstractCursor.java @@ -60,6 +60,7 @@ import java.util.Deque; import java.util.Iterator; import java.util.List; import java.util.TreeMap; +import java.util.stream.Stream; import javax.xml.bind.DatatypeConverter; import javax.xml.parsers.DocumentBuilder; @@ -76,6 +77,7 @@ import org.jooq.DSLContext; import org.jooq.DataType; import org.jooq.EnumType; import org.jooq.Field; +import org.jooq.Fields; import org.jooq.Formattable; import org.jooq.JSON; import org.jooq.JSONB; @@ -106,17 +108,17 @@ import org.xml.sax.helpers.AttributesImpl; /** * @author Lukas Eder */ -abstract class AbstractCursor extends AbstractFormattable implements Iterable { +abstract class AbstractCursor extends AbstractFormattable implements Fields, Iterable { /** * Generated UID */ private static final long serialVersionUID = -3412555195899758746L; - final Fields fields; + final FieldsImpl fields; Configuration configuration; - AbstractCursor(Configuration configuration, Fields fields) { + AbstractCursor(Configuration configuration, FieldsImpl fields) { this.configuration = configuration; this.fields = fields; } @@ -129,10 +131,21 @@ abstract class AbstractCursor extends AbstractFormattable impl return fields; } + @Override public final Row fieldsRow() { return Tools.row0(fields); } + + + @Override + public final Stream> fieldStream() { + return fields.fieldStream(); + } + + + + @Override public final Field field(Field field) { return fields.field(field); } @@ -140,6 +153,7 @@ abstract class AbstractCursor extends AbstractFormattable impl /** * @deprecated This method hides static import {@link DSL#field(String)}. */ + @Override @Deprecated public final Field field(String name) { return fields.field(name); @@ -148,6 +162,7 @@ abstract class AbstractCursor extends AbstractFormattable impl /** * @deprecated This method hides static import {@link DSL#field(String, Class)}. */ + @Override @Deprecated public final Field field(String name, Class type) { return fields.field(name, type); @@ -156,6 +171,7 @@ abstract class AbstractCursor extends AbstractFormattable impl /** * @deprecated This method hides static import {@link DSL#field(String, DataType)}. */ + @Override @Deprecated public final Field field(String name, DataType dataType) { return fields.field(name, dataType); @@ -164,6 +180,7 @@ abstract class AbstractCursor extends AbstractFormattable impl /** * @deprecated This method hides static import {@link DSL#field(Name)}. */ + @Override @Deprecated public final Field field(Name name) { return fields.field(name); @@ -172,6 +189,7 @@ abstract class AbstractCursor extends AbstractFormattable impl /** * @deprecated This method hides static import {@link DSL#field(Name, Class)}. */ + @Override @Deprecated public final Field field(Name name, Class type) { return fields.field(name, type); @@ -180,55 +198,107 @@ abstract class AbstractCursor extends AbstractFormattable impl /** * @deprecated This method hides static import {@link DSL#field(Name, DataType)}. */ + @Override @Deprecated public final Field field(Name name, DataType dataType) { return fields.field(name, dataType); } + @Override public final Field field(int index) { return fields.field(index); } + @Override public final Field field(int index, Class type) { return fields.field(index, type); } + @Override public final Field field(int index, DataType dataType) { return fields.field(index, dataType); } + @Override public final Field[] fields() { return fields.fields().clone(); } + @Override public final Field[] fields(Field... f) { return fields.fields(f); } + @Override public final Field[] fields(int... indexes) { return fields.fields(indexes); } + @Override public final Field[] fields(String... names) { return fields.fields(names); } + @Override public final Field[] fields(Name... names) { return fields.fields(names); } + @Override public final int indexOf(Field field) { return fields.indexOf(field); } + @Override public final int indexOf(String fieldName) { return fields.indexOf(fieldName); } + @Override public final int indexOf(Name fieldName) { return fields.indexOf(fieldName); } + @Override + public final Class[] types() { + return fields.types(); + } + + @Override + public final Class type(int index) { + return fields.type(index); + } + + @Override + public final Class type(String name) { + return fields.type(name); + } + + @Override + public final Class type(Name name) { + return fields.type(name); + } + + @Override + public final DataType[] dataTypes() { + return fields.dataTypes(); + } + + @Override + public final DataType dataType(int index) { + return fields.dataType(index); + } + + @Override + public final DataType dataType(String name) { + return fields.dataType(name); + } + + @Override + public final DataType dataType(Name name) { + return fields.dataType(name); + } + // ------------------------------------------------------------------------- // XXX: Formattable API // ------------------------------------------------------------------------- @@ -723,7 +793,7 @@ abstract class AbstractCursor extends AbstractFormattable impl } } - static final void formatJSONMap0(Record record, Fields fields, JSONFormat format, int recordLevel, Writer writer) throws java.io.IOException { + static final void formatJSONMap0(Record record, FieldsImpl fields, JSONFormat format, int recordLevel, Writer writer) throws java.io.IOException { String separator = ""; boolean wrapRecords = format.wrapSingleColumnRecords() || fields.fields.length > 1; @@ -758,7 +828,7 @@ abstract class AbstractCursor extends AbstractFormattable impl writer.append('}'); } - static final void formatJSONArray0(Record record, Fields fields, JSONFormat format, int recordLevel, Writer writer) throws java.io.IOException { + static final void formatJSONArray0(Record record, FieldsImpl fields, JSONFormat format, int recordLevel, Writer writer) throws java.io.IOException { String separator = ""; if (format.wrapSingleColumnRecords() || fields.fields.length > 1) @@ -855,7 +925,7 @@ abstract class AbstractCursor extends AbstractFormattable impl XMLFormat format, int recordLevel, Record record, - Fields fields + FieldsImpl fields ) throws java.io.IOException { String newline = format.newline(); diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractDMLQuery.java b/jOOQ/src/main/java/org/jooq/impl/AbstractDMLQuery.java index b8ef357e57..888e3d0df3 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AbstractDMLQuery.java +++ b/jOOQ/src/main/java/org/jooq/impl/AbstractDMLQuery.java @@ -1254,7 +1254,7 @@ abstract class AbstractDMLQuery extends AbstractRowCountQuery // Only the IDENTITY value was requested. No need for an // additional query - if (returningResolvedAsterisks.size() == 1 && new Fields<>(returningResolvedAsterisks).field(returnIdentity) != null) { + if (returningResolvedAsterisks.size() == 1 && new FieldsImpl<>(returningResolvedAsterisks).field(returnIdentity) != null) { for (final Object id : ids) { ((Result) getResult()).add( Tools.newRecord( diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractRecord.java b/jOOQ/src/main/java/org/jooq/impl/AbstractRecord.java index 634a1daf77..3ed50eb1cc 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AbstractRecord.java +++ b/jOOQ/src/main/java/org/jooq/impl/AbstractRecord.java @@ -179,6 +179,20 @@ abstract class AbstractRecord extends AbstractStore implements Record { // XXX: FieldProvider API // ------------------------------------------------------------------------ + @Override + public final Field[] fields() { + return fields.fields(); + } + + + + @Override + public final Stream> fieldStream() { + return fields.fieldStream(); + } + + + @Override public final Field field(Field field) { return fieldsRow().field(field); @@ -189,19 +203,44 @@ abstract class AbstractRecord extends AbstractStore implements Record { return fieldsRow().field(name); } + @Override + public final Field field(String name, Class type) { + return fields.field(name, type); + } + + @Override + public final Field field(String name, DataType dataType) { + return fields.field(name, dataType); + } + @Override public final Field field(Name name) { return fieldsRow().field(name); } + @Override + public final Field field(Name name, Class type) { + return fields.field(name, type); + } + + @Override + public final Field field(Name name, DataType dataType) { + return fields.field(name, dataType); + } + @Override public final Field field(int index) { return index >= 0 && index < fields.size() ? fields.field(index) : null; } @Override - public final Field[] fields() { - return fields.fields(); + public final Field field(int index, Class type) { + return fields.field(index, type); + } + + @Override + public final Field field(int index, DataType dataType) { + return fields.field(index, dataType); } @Override @@ -239,6 +278,46 @@ abstract class AbstractRecord extends AbstractStore implements Record { return fields.indexOf(fieldName); } + @Override + public final Class[] types() { + return fields.types(); + } + + @Override + public final Class type(int fieldIndex) { + return fields.type(fieldIndex); + } + + @Override + public final Class type(String fieldName) { + return fields.type(fieldName); + } + + @Override + public final Class type(Name fieldName) { + return fields.type(fieldName); + } + + @Override + public final DataType[] dataTypes() { + return fields.dataTypes(); + } + + @Override + public final DataType dataType(int fieldIndex) { + return fields.dataType(fieldIndex); + } + + @Override + public final DataType dataType(String fieldName) { + return fields.dataType(fieldName); + } + + @Override + public final DataType dataType(Name fieldName) { + return fields.dataType(fieldName); + } + // ------------------------------------------------------------------------ // XXX: Record API // ------------------------------------------------------------------------ @@ -740,7 +819,7 @@ abstract class AbstractRecord extends AbstractStore implements Record { @Override public final E into(Class type) { - return (E) Tools.configuration(this).recordMapperProvider().provide((Fields) fields.fields, type).map(this); + return (E) Tools.configuration(this).recordMapperProvider().provide((FieldsImpl) fields.fields, type).map(this); } // [#10191] Java and Kotlin can produce overloads for this method despite @@ -754,7 +833,7 @@ abstract class AbstractRecord extends AbstractStore implements Record { Class type = (Class) object.getClass(); try { - return new DefaultRecordMapper((Fields) fields.fields, type, object, configuration()).map(this); + return new DefaultRecordMapper((FieldsImpl) fields.fields, type, object, configuration()).map(this); } // Pass MappingExceptions on to client code @@ -844,7 +923,7 @@ abstract class AbstractRecord extends AbstractStore implements Record { return mapper.map(this); } - private final void from0(Object source, Fields f) { + private final void from0(Object source, FieldsImpl f) { if (source == null) return; // [#2520] TODO: Benchmark this from() method. There's probably a better implementation @@ -855,7 +934,7 @@ abstract class AbstractRecord extends AbstractStore implements Record { resetChangedOnNotNull(this); } - private final Object prepareArrayForUnmap(Object source, Fields f) { + private final Object prepareArrayForUnmap(Object source, FieldsImpl f) { if (source instanceof Object[]) { Object[] array = (Object[]) source; @@ -883,7 +962,7 @@ abstract class AbstractRecord extends AbstractStore implements Record { @Override public final void from(Object source, Field... f) { - from0(source, new Fields(f)); + from0(source, new FieldsImpl(f)); } @Override @@ -908,7 +987,7 @@ abstract class AbstractRecord extends AbstractStore implements Record { @Override public final void fromMap(Map map, Field... f) { - from0(map, new Fields(f)); + from0(map, new FieldsImpl(f)); } @Override @@ -933,7 +1012,7 @@ abstract class AbstractRecord extends AbstractStore implements Record { @Override public final void fromArray(Object[] array, Field... f) { - from0(array, new Fields(f)); + from0(array, new FieldsImpl(f)); } @Override diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractRow.java b/jOOQ/src/main/java/org/jooq/impl/AbstractRow.java index ea63344276..761da1237e 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AbstractRow.java +++ b/jOOQ/src/main/java/org/jooq/impl/AbstractRow.java @@ -55,6 +55,8 @@ import org.jooq.Row; import org.jooq.Row1; import org.jooq.Row2; +import org.jetbrains.annotations.NotNull; + /** * A common base class for the various degrees of {@link Row1}, {@link Row2}, * etc. @@ -64,20 +66,20 @@ abstract class AbstractRow extends AbstractQueryPart implements Row { /** * Generated UID */ - private static final long serialVersionUID = 2175082265665049629L; + private static final long serialVersionUID = 2175082265665049629L; private static final Clause[] CLAUSES = { FIELD_ROW }; - final Fields fields; + final FieldsImpl fields; AbstractRow(Field... fields) { - this(new Fields<>(fields)); + this(new FieldsImpl<>(fields)); } AbstractRow(Collection> fields) { - this(new Fields<>(fields)); + this(new FieldsImpl<>(fields)); } - AbstractRow(Fields fields) { + AbstractRow(FieldsImpl fields) { super(); this.fields = fields; @@ -114,6 +116,12 @@ abstract class AbstractRow extends AbstractQueryPart implements Row { return fields.size(); } + @Override + public final Row fieldsRow() { + return this; + } + + @Override public final Stream> fieldStream() { @@ -121,6 +129,7 @@ abstract class AbstractRow extends AbstractQueryPart implements Row { } + @Override public final Field field(Field field) { return fields.field(field); diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractTable.java b/jOOQ/src/main/java/org/jooq/impl/AbstractTable.java index 28863f6969..cfad891e4a 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AbstractTable.java +++ b/jOOQ/src/main/java/org/jooq/impl/AbstractTable.java @@ -189,7 +189,7 @@ abstract class AbstractTable extends AbstractNamed implements * TableAlias contains aliased fields of its * AliasProvider table. */ - abstract Fields fields0(); + abstract FieldsImpl fields0(); @Override public final DataType getDataType() { @@ -218,12 +218,14 @@ abstract class AbstractTable extends AbstractNamed implements } + @Override public final Stream> fieldStream() { return Stream.of(fields()); } + @Override public final Field field(Field field) { return fieldsRow().field(field); @@ -314,6 +316,46 @@ abstract class AbstractTable extends AbstractNamed implements return fieldsRow().indexOf(fieldName); } + @Override + public final Class[] types() { + return fieldsRow().types(); + } + + @Override + public final Class type(int index) { + return fieldsRow().type(index); + } + + @Override + public final Class type(String name) { + return fieldsRow().type(name); + } + + @Override + public final Class type(Name name) { + return fieldsRow().type(name); + } + + @Override + public final DataType[] dataTypes() { + return fieldsRow().dataTypes(); + } + + @Override + public final DataType dataType(int index) { + return fieldsRow().dataType(index); + } + + @Override + public final DataType dataType(String name) { + return fieldsRow().dataType(name); + } + + @Override + public final DataType dataType(Name name) { + return fieldsRow().dataType(name); + } + @Override public final Table asTable() { return this; diff --git a/jOOQ/src/main/java/org/jooq/impl/AliasedSelect.java b/jOOQ/src/main/java/org/jooq/impl/AliasedSelect.java index 95e3148e47..1b564f24c2 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AliasedSelect.java +++ b/jOOQ/src/main/java/org/jooq/impl/AliasedSelect.java @@ -97,8 +97,8 @@ final class AliasedSelect extends AbstractTable { } @Override - final Fields fields0() { - return new Fields<>(query.asTable(DSL.name("t"), aliases).fields()); + final FieldsImpl fields0() { + return new FieldsImpl<>(query.asTable(DSL.name("t"), aliases).fields()); } @Override diff --git a/jOOQ/src/main/java/org/jooq/impl/Array.java b/jOOQ/src/main/java/org/jooq/impl/Array.java index 204a51e206..46069e70b6 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Array.java +++ b/jOOQ/src/main/java/org/jooq/impl/Array.java @@ -65,12 +65,12 @@ final class Array extends AbstractField { private static final long serialVersionUID = -6629785423729163857L; private static final Set REQUIRES_CAST = SQLDialect.supportedBy(POSTGRES); - private final Fields fields; + private final FieldsImpl fields; Array(Collection> fields) { super(N_ARRAY, type(fields)); - this.fields = new Fields<>(fields); + this.fields = new FieldsImpl<>(fields); } @SuppressWarnings({ "rawtypes", "unchecked" }) diff --git a/jOOQ/src/main/java/org/jooq/impl/ArrayTable.java b/jOOQ/src/main/java/org/jooq/impl/ArrayTable.java index 7d9866f2bf..e712cad1f3 100644 --- a/jOOQ/src/main/java/org/jooq/impl/ArrayTable.java +++ b/jOOQ/src/main/java/org/jooq/impl/ArrayTable.java @@ -70,12 +70,12 @@ final class ArrayTable extends AbstractTable { /** * Generated UID */ - private static final long serialVersionUID = 2380426377794577041L; + private static final long serialVersionUID = 2380426377794577041L; - private final Field array; - private final Fields field; - private final Name alias; - private final Name[] fieldAliases; + private final Field array; + private final FieldsImpl field; + private final Name alias; + private final Name[] fieldAliases; ArrayTable(Field array) { this(array, N_ARRAY_TABLE); @@ -122,7 +122,7 @@ final class ArrayTable extends AbstractTable { this.field = init(arrayType, alias); } - private static final Fields init(Class arrayType, Name alias) { + private static final FieldsImpl init(Class arrayType, Name alias) { List> result = new ArrayList<>(); // [#1114] VARRAY/TABLE of OBJECT have more than one field @@ -143,7 +143,7 @@ final class ArrayTable extends AbstractTable { result.add(DSL.field(name(alias.last(), "COLUMN_VALUE"), DSL.getDataType(arrayType))); } - return new Fields<>(result); + return new FieldsImpl<>(result); } @Override @@ -284,7 +284,7 @@ final class ArrayTable extends AbstractTable { } @Override - final Fields fields0() { + final FieldsImpl fields0() { return ArrayTable.this.fields0(); } } @@ -295,7 +295,7 @@ final class ArrayTable extends AbstractTable { } @Override - final Fields fields0() { + final FieldsImpl fields0() { return field; } } diff --git a/jOOQ/src/main/java/org/jooq/impl/ArrayTableEmulation.java b/jOOQ/src/main/java/org/jooq/impl/ArrayTableEmulation.java index 67ba043f9d..d08427d46e 100644 --- a/jOOQ/src/main/java/org/jooq/impl/ArrayTableEmulation.java +++ b/jOOQ/src/main/java/org/jooq/impl/ArrayTableEmulation.java @@ -64,14 +64,14 @@ final class ArrayTableEmulation extends AbstractTable { /** * Generated UID */ - private static final long serialVersionUID = 2392515064450536343L; + private static final long serialVersionUID = 2392515064450536343L; - private final Object[] array; - private final Fields field; - private final Name alias; - private final Name fieldAlias; + private final Object[] array; + private final FieldsImpl field; + private final Name alias; + private final Name fieldAlias; - private transient Table table; + private transient Table table; ArrayTableEmulation(Object[] array) { this(array, N_ARRAY_TABLE, null); @@ -87,7 +87,7 @@ final class ArrayTableEmulation extends AbstractTable { this.array = array; this.alias = alias; this.fieldAlias = fieldAlias == null ? N_COLUMN_VALUE : fieldAlias; - this.field = new Fields<>(DSL.field(name(alias.last(), this.fieldAlias.last()), DSL.getDataType(array.getClass().getComponentType()))); + this.field = new FieldsImpl<>(DSL.field(name(alias.last(), this.fieldAlias.last()), DSL.getDataType(array.getClass().getComponentType()))); } @Override @@ -124,7 +124,7 @@ final class ArrayTableEmulation extends AbstractTable { } @Override - final Fields fields0() { + final FieldsImpl fields0() { return field; } diff --git a/jOOQ/src/main/java/org/jooq/impl/CommonTableExpressionImpl.java b/jOOQ/src/main/java/org/jooq/impl/CommonTableExpressionImpl.java index 64a1269d8b..02d84ce18e 100644 --- a/jOOQ/src/main/java/org/jooq/impl/CommonTableExpressionImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/CommonTableExpressionImpl.java @@ -76,7 +76,7 @@ final class CommonTableExpressionImpl extends AbstractTable private final DerivedColumnListImpl name; private final Select select; - private final Fields fields; + private final FieldsImpl fields; private final Boolean materialized; CommonTableExpressionImpl(DerivedColumnListImpl name, Select select, Boolean materialized) { @@ -131,11 +131,11 @@ final class CommonTableExpressionImpl extends AbstractTable } @Override - final Fields fields0() { + final FieldsImpl fields0() { return fields; } - final Fields fields1() { + final FieldsImpl fields1() { List> s = select.getSelect(); Field[] f = new Field[Tools.degree(select)]; @@ -152,6 +152,6 @@ final class CommonTableExpressionImpl extends AbstractTable ); } - return new Fields<>(f); + return new FieldsImpl<>(f); } } diff --git a/jOOQ/src/main/java/org/jooq/impl/CursorImpl.java b/jOOQ/src/main/java/org/jooq/impl/CursorImpl.java index 5ca6c0631e..d61ced60b8 100644 --- a/jOOQ/src/main/java/org/jooq/impl/CursorImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/CursorImpl.java @@ -119,14 +119,13 @@ final class CursorImpl extends AbstractCursor implements Cu private transient Iterator iterator; private transient int rows; - @SuppressWarnings("unchecked") CursorImpl(ExecuteContext ctx, ExecuteListener listener, Field[] fields, int[] internIndexes, boolean keepStatement, boolean keepResultSet) { this(ctx, listener, fields, internIndexes, keepStatement, keepResultSet, (Class) RecordImplN.class, 0, true); } CursorImpl(ExecuteContext ctx, ExecuteListener listener, Field[] fields, int[] internIndexes, boolean keepStatement, boolean keepResultSet, Class type, int maxRows, boolean autoclosing) { - super(ctx.configuration(), new Fields<>(fields)); + super(ctx.configuration(), new FieldsImpl<>(fields)); this.ctx = ctx; this.listener = (listener != null ? listener : ExecuteListeners.getAndStart(ctx)); diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java index 351e406ae6..297d890190 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DSL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java @@ -24471,7 +24471,7 @@ public class DSL { */ @NotNull public static RecordType recordType(Field[] fields) { - return new Fields(fields); + return new FieldsImpl(fields); } /** @@ -24479,7 +24479,7 @@ public class DSL { */ @NotNull public static RecordType recordType(Collection> fields) { - return new Fields(fields); + return new FieldsImpl(fields); } @@ -24489,7 +24489,7 @@ public class DSL { */ @NotNull public static RecordType> recordType(Field field1) { - return new Fields(field1); + return new FieldsImpl(field1); } /** @@ -24497,7 +24497,7 @@ public class DSL { */ @NotNull public static RecordType> recordType(Field field1, Field field2) { - return new Fields(field1, field2); + return new FieldsImpl(field1, field2); } /** @@ -24505,7 +24505,7 @@ public class DSL { */ @NotNull public static RecordType> recordType(Field field1, Field field2, Field field3) { - return new Fields(field1, field2, field3); + return new FieldsImpl(field1, field2, field3); } /** @@ -24513,7 +24513,7 @@ public class DSL { */ @NotNull public static RecordType> recordType(Field field1, Field field2, Field field3, Field field4) { - return new Fields(field1, field2, field3, field4); + return new FieldsImpl(field1, field2, field3, field4); } /** @@ -24521,7 +24521,7 @@ public class DSL { */ @NotNull public static RecordType> recordType(Field field1, Field field2, Field field3, Field field4, Field field5) { - return new Fields(field1, field2, field3, field4, field5); + return new FieldsImpl(field1, field2, field3, field4, field5); } /** @@ -24529,7 +24529,7 @@ public class DSL { */ @NotNull public static RecordType> recordType(Field field1, Field field2, Field field3, Field field4, Field field5, Field field6) { - return new Fields(field1, field2, field3, field4, field5, field6); + return new FieldsImpl(field1, field2, field3, field4, field5, field6); } /** @@ -24537,7 +24537,7 @@ public class DSL { */ @NotNull public static RecordType> recordType(Field field1, Field field2, Field field3, Field field4, Field field5, Field field6, Field field7) { - return new Fields(field1, field2, field3, field4, field5, field6, field7); + return new FieldsImpl(field1, field2, field3, field4, field5, field6, field7); } /** @@ -24545,7 +24545,7 @@ public class DSL { */ @NotNull public static RecordType> recordType(Field field1, Field field2, Field field3, Field field4, Field field5, Field field6, Field field7, Field field8) { - return new Fields(field1, field2, field3, field4, field5, field6, field7, field8); + return new FieldsImpl(field1, field2, field3, field4, field5, field6, field7, field8); } /** @@ -24553,7 +24553,7 @@ public class DSL { */ @NotNull public static RecordType> recordType(Field field1, Field field2, Field field3, Field field4, Field field5, Field field6, Field field7, Field field8, Field field9) { - return new Fields(field1, field2, field3, field4, field5, field6, field7, field8, field9); + return new FieldsImpl(field1, field2, field3, field4, field5, field6, field7, field8, field9); } /** @@ -24561,7 +24561,7 @@ public class DSL { */ @NotNull public static RecordType> recordType(Field field1, Field field2, Field field3, Field field4, Field field5, Field field6, Field field7, Field field8, Field field9, Field field10) { - return new Fields(field1, field2, field3, field4, field5, field6, field7, field8, field9, field10); + return new FieldsImpl(field1, field2, field3, field4, field5, field6, field7, field8, field9, field10); } /** @@ -24569,7 +24569,7 @@ public class DSL { */ @NotNull public static RecordType> recordType(Field field1, Field field2, Field field3, Field field4, Field field5, Field field6, Field field7, Field field8, Field field9, Field field10, Field field11) { - return new Fields(field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11); + return new FieldsImpl(field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11); } /** @@ -24577,7 +24577,7 @@ public class DSL { */ @NotNull public static RecordType> recordType(Field field1, Field field2, Field field3, Field field4, Field field5, Field field6, Field field7, Field field8, Field field9, Field field10, Field field11, Field field12) { - return new Fields(field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12); + return new FieldsImpl(field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12); } /** @@ -24585,7 +24585,7 @@ public class DSL { */ @NotNull public static RecordType> recordType(Field field1, Field field2, Field field3, Field field4, Field field5, Field field6, Field field7, Field field8, Field field9, Field field10, Field field11, Field field12, Field field13) { - return new Fields(field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13); + return new FieldsImpl(field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13); } /** @@ -24593,7 +24593,7 @@ public class DSL { */ @NotNull public static RecordType> recordType(Field field1, Field field2, Field field3, Field field4, Field field5, Field field6, Field field7, Field field8, Field field9, Field field10, Field field11, Field field12, Field field13, Field field14) { - return new Fields(field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13, field14); + return new FieldsImpl(field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13, field14); } /** @@ -24601,7 +24601,7 @@ public class DSL { */ @NotNull public static RecordType> recordType(Field field1, Field field2, Field field3, Field field4, Field field5, Field field6, Field field7, Field field8, Field field9, Field field10, Field field11, Field field12, Field field13, Field field14, Field field15) { - return new Fields(field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13, field14, field15); + return new FieldsImpl(field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13, field14, field15); } /** @@ -24609,7 +24609,7 @@ public class DSL { */ @NotNull public static RecordType> recordType(Field field1, Field field2, Field field3, Field field4, Field field5, Field field6, Field field7, Field field8, Field field9, Field field10, Field field11, Field field12, Field field13, Field field14, Field field15, Field field16) { - return new Fields(field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13, field14, field15, field16); + return new FieldsImpl(field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13, field14, field15, field16); } /** @@ -24617,7 +24617,7 @@ public class DSL { */ @NotNull public static RecordType> recordType(Field field1, Field field2, Field field3, Field field4, Field field5, Field field6, Field field7, Field field8, Field field9, Field field10, Field field11, Field field12, Field field13, Field field14, Field field15, Field field16, Field field17) { - return new Fields(field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13, field14, field15, field16, field17); + return new FieldsImpl(field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13, field14, field15, field16, field17); } /** @@ -24625,7 +24625,7 @@ public class DSL { */ @NotNull public static RecordType> recordType(Field field1, Field field2, Field field3, Field field4, Field field5, Field field6, Field field7, Field field8, Field field9, Field field10, Field field11, Field field12, Field field13, Field field14, Field field15, Field field16, Field field17, Field field18) { - return new Fields(field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13, field14, field15, field16, field17, field18); + return new FieldsImpl(field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13, field14, field15, field16, field17, field18); } /** @@ -24633,7 +24633,7 @@ public class DSL { */ @NotNull public static RecordType> recordType(Field field1, Field field2, Field field3, Field field4, Field field5, Field field6, Field field7, Field field8, Field field9, Field field10, Field field11, Field field12, Field field13, Field field14, Field field15, Field field16, Field field17, Field field18, Field field19) { - return new Fields(field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13, field14, field15, field16, field17, field18, field19); + return new FieldsImpl(field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13, field14, field15, field16, field17, field18, field19); } /** @@ -24641,7 +24641,7 @@ public class DSL { */ @NotNull public static RecordType> recordType(Field field1, Field field2, Field field3, Field field4, Field field5, Field field6, Field field7, Field field8, Field field9, Field field10, Field field11, Field field12, Field field13, Field field14, Field field15, Field field16, Field field17, Field field18, Field field19, Field field20) { - return new Fields(field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13, field14, field15, field16, field17, field18, field19, field20); + return new FieldsImpl(field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13, field14, field15, field16, field17, field18, field19, field20); } /** @@ -24649,7 +24649,7 @@ public class DSL { */ @NotNull public static RecordType> recordType(Field field1, Field field2, Field field3, Field field4, Field field5, Field field6, Field field7, Field field8, Field field9, Field field10, Field field11, Field field12, Field field13, Field field14, Field field15, Field field16, Field field17, Field field18, Field field19, Field field20, Field field21) { - return new Fields(field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13, field14, field15, field16, field17, field18, field19, field20, field21); + return new FieldsImpl(field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13, field14, field15, field16, field17, field18, field19, field20, field21); } /** @@ -24657,7 +24657,7 @@ public class DSL { */ @NotNull public static RecordType> recordType(Field field1, Field field2, Field field3, Field field4, Field field5, Field field6, Field field7, Field field8, Field field9, Field field10, Field field11, Field field12, Field field13, Field field14, Field field15, Field field16, Field field17, Field field18, Field field19, Field field20, Field field21, Field field22) { - return new Fields(field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13, field14, field15, field16, field17, field18, field19, field20, field21, field22); + return new FieldsImpl(field1, field2, field3, field4, field5, field6, field7, field8, field9, field10, field11, field12, field13, field14, field15, field16, field17, field18, field19, field20, field21, field22); } diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultRecordContext.java b/jOOQ/src/main/java/org/jooq/impl/DefaultRecordContext.java index bdb6a7d6e5..0ba640fc29 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultRecordContext.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultRecordContext.java @@ -53,9 +53,9 @@ import org.jooq.Result; */ class DefaultRecordContext extends AbstractScope implements RecordContext { - private final ExecuteType type; - private final Record[] records; - Exception exception; + private final ExecuteType type; + private final Record[] records; + Exception exception; DefaultRecordContext(Configuration configuration, ExecuteType type, Record... records) { super(configuration); @@ -82,7 +82,7 @@ class DefaultRecordContext extends AbstractScope implements RecordContext { @Override public final RecordType recordType() { Record record = record(); - return record != null ? new Fields<>(record.fields()) : null; + return record != null ? new FieldsImpl<>(record.fields()) : null; } @Override diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultRecordMapper.java b/jOOQ/src/main/java/org/jooq/impl/DefaultRecordMapper.java index 28f9274c57..be7425765e 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultRecordMapper.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultRecordMapper.java @@ -787,14 +787,14 @@ public class DefaultRecordMapper implements RecordMapper(entry.getValue()), member.getType()) + .provide(new FieldsImpl<>(entry.getValue()), member.getType()) ); } for (Method method : getMatchingSetters(configuration, type, prefix, true)) { list.add(configuration .recordMapperProvider() - .provide(new Fields<>(entry.getValue()), method.getParameterTypes()[0]) + .provide(new FieldsImpl<>(entry.getValue()), method.getParameterTypes()[0]) ); } @@ -1002,7 +1002,7 @@ public class DefaultRecordMapper implements RecordMapper(nestedMappedFields[i]), parameterTypes[i]); + .provide((RecordType) new FieldsImpl<>(nestedMappedFields[i]), parameterTypes[i]); } } } diff --git a/jOOQ/src/main/java/org/jooq/impl/DerivedTable.java b/jOOQ/src/main/java/org/jooq/impl/DerivedTable.java index c7d06eb9e0..2fc4e868cf 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DerivedTable.java +++ b/jOOQ/src/main/java/org/jooq/impl/DerivedTable.java @@ -79,8 +79,8 @@ class DerivedTable extends AbstractTable { } @Override - final Fields fields0() { - return new Fields<>(query.getSelect()); + final FieldsImpl fields0() { + return new FieldsImpl<>(query.getSelect()); } @Override diff --git a/jOOQ/src/main/java/org/jooq/impl/Dual.java b/jOOQ/src/main/java/org/jooq/impl/Dual.java index cd7fea7e84..46bdd44e1a 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Dual.java +++ b/jOOQ/src/main/java/org/jooq/impl/Dual.java @@ -214,7 +214,7 @@ final class Dual extends AbstractTable { } @Override - final Fields fields0() { - return new Fields<>(); + final FieldsImpl fields0() { + return new FieldsImpl<>(); } } diff --git a/jOOQ/src/main/java/org/jooq/impl/Fields.java b/jOOQ/src/main/java/org/jooq/impl/FieldsImpl.java similarity index 95% rename from jOOQ/src/main/java/org/jooq/impl/Fields.java rename to jOOQ/src/main/java/org/jooq/impl/FieldsImpl.java index 4a3a6131f2..e06e950d09 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Fields.java +++ b/jOOQ/src/main/java/org/jooq/impl/FieldsImpl.java @@ -47,6 +47,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; +import java.util.stream.Stream; import org.jooq.Context; import org.jooq.DataType; @@ -54,27 +55,30 @@ import org.jooq.Field; import org.jooq.Name; import org.jooq.Record; import org.jooq.RecordType; +import org.jooq.Row; import org.jooq.Table; import org.jooq.TableField; import org.jooq.tools.JooqLogger; +import org.jetbrains.annotations.NotNull; + /** * A simple wrapper for Field[], providing some useful lookup * methods * * @author Lukas Eder */ -final class Fields extends AbstractQueryPart implements RecordType { +final class FieldsImpl extends AbstractQueryPart implements RecordType { private static final long serialVersionUID = -6911012275707591576L; - private static final JooqLogger log = JooqLogger.getLogger(Fields.class); + private static final JooqLogger log = JooqLogger.getLogger(FieldsImpl.class); Field[] fields; - Fields(Field... fields) { + FieldsImpl(Field... fields) { this.fields = fields; } - Fields(Collection> fields) { + FieldsImpl(Collection> fields) { this.fields = fields.toArray(EMPTY_FIELD); } @@ -256,6 +260,20 @@ final class Fields extends AbstractQueryPart implements Record return fields; } + @Override + public final Row fieldsRow() { + return new RowImplN(fields); + } + + + + @Override + public final Stream> fieldStream() { + return Stream.of(fields); + } + + + @Override public final Field[] fields(Field... f) { Field[] result = new Field[f.length]; @@ -478,8 +496,8 @@ final class Fields extends AbstractQueryPart implements Record if (this == that) return true; - if (that instanceof Fields) - return Arrays.equals(fields, ((Fields) that).fields); + if (that instanceof FieldsImpl) + return Arrays.equals(fields, ((FieldsImpl) that).fields); return false; } diff --git a/jOOQ/src/main/java/org/jooq/impl/FunctionTable.java b/jOOQ/src/main/java/org/jooq/impl/FunctionTable.java index e8c6959ce8..4e732f4d07 100644 --- a/jOOQ/src/main/java/org/jooq/impl/FunctionTable.java +++ b/jOOQ/src/main/java/org/jooq/impl/FunctionTable.java @@ -108,7 +108,7 @@ final class FunctionTable extends AbstractTable { } @Override - final Fields fields0() { - return new Fields<>(); + final FieldsImpl fields0() { + return new FieldsImpl<>(); } } diff --git a/jOOQ/src/main/java/org/jooq/impl/GenerateSeries.java b/jOOQ/src/main/java/org/jooq/impl/GenerateSeries.java index 1fa13d58f3..3cc417359c 100644 --- a/jOOQ/src/main/java/org/jooq/impl/GenerateSeries.java +++ b/jOOQ/src/main/java/org/jooq/impl/GenerateSeries.java @@ -162,8 +162,8 @@ final class GenerateSeries extends AbstractTable> { } @Override - final Fields> fields0() { - return new Fields<>(DSL.field(N_GENERATE_SERIES, Integer.class)); + final FieldsImpl> fields0() { + return new FieldsImpl<>(DSL.field(N_GENERATE_SERIES, Integer.class)); } @Override // Avoid AbstractTable implementation diff --git a/jOOQ/src/main/java/org/jooq/impl/HintedTable.java b/jOOQ/src/main/java/org/jooq/impl/HintedTable.java index 6b0cb002db..217db0b8b2 100644 --- a/jOOQ/src/main/java/org/jooq/impl/HintedTable.java +++ b/jOOQ/src/main/java/org/jooq/impl/HintedTable.java @@ -106,7 +106,7 @@ final class HintedTable extends AbstractTable { } @Override - final Fields fields0() { + final FieldsImpl fields0() { return delegate.fields0(); } } diff --git a/jOOQ/src/main/java/org/jooq/impl/InsertQueryImpl.java b/jOOQ/src/main/java/org/jooq/impl/InsertQueryImpl.java index 1eaf72ef1c..d1ac9e00b7 100644 --- a/jOOQ/src/main/java/org/jooq/impl/InsertQueryImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/InsertQueryImpl.java @@ -355,7 +355,7 @@ final class InsertQueryImpl extends AbstractStoreQuery impl ctx.sql("[unknown primary key]"); else ctx.qualify(false) - .visit(new Fields<>(table().getPrimaryKey().getFields())) + .visit(new FieldsImpl<>(table().getPrimaryKey().getFields())) .qualify(qualify); ctx.sql(')'); diff --git a/jOOQ/src/main/java/org/jooq/impl/Intern.java b/jOOQ/src/main/java/org/jooq/impl/Intern.java index 0d085a2a35..74b02614fa 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Intern.java +++ b/jOOQ/src/main/java/org/jooq/impl/Intern.java @@ -62,11 +62,11 @@ final class Intern implements Serializable { if (internIndexes != null) return internIndexes; else if (internFields != null) - return new Fields<>(fields).indexesOf(internFields); + return new FieldsImpl<>(fields).indexesOf(internFields); else if (internNameStrings != null) - return new Fields<>(fields).indexesOf(internNameStrings); + return new FieldsImpl<>(fields).indexesOf(internNameStrings); else if (internNames != null) - return new Fields<>(fields).indexesOf(internNames); + return new FieldsImpl<>(fields).indexesOf(internNames); return null; } diff --git a/jOOQ/src/main/java/org/jooq/impl/JSONTable.java b/jOOQ/src/main/java/org/jooq/impl/JSONTable.java index 7fbc1802be..ab045cd216 100644 --- a/jOOQ/src/main/java/org/jooq/impl/JSONTable.java +++ b/jOOQ/src/main/java/org/jooq/impl/JSONTable.java @@ -100,7 +100,7 @@ implements private final Field json; private final QueryPartList columns; private final boolean hasOrdinality; - private transient Fields fields; + private transient FieldsImpl fields; JSONTable(Field json, Field path) { this(json, path, null, false); @@ -184,14 +184,14 @@ implements } @Override - final Fields fields0() { + final FieldsImpl fields0() { if (fields == null) { List> f = new ArrayList<>(); for (JSONTableColumn c : columns) f.add(c.field.getDataType() == c.type ? c.field : DSL.field(c.field.getQualifiedName(), c.type)); - fields = new Fields<>(f); + fields = new FieldsImpl<>(f); } return fields; diff --git a/jOOQ/src/main/java/org/jooq/impl/JoinTable.java b/jOOQ/src/main/java/org/jooq/impl/JoinTable.java index 699b5daf38..2ebab438b6 100755 --- a/jOOQ/src/main/java/org/jooq/impl/JoinTable.java +++ b/jOOQ/src/main/java/org/jooq/impl/JoinTable.java @@ -564,9 +564,9 @@ implements } @Override - final Fields fields0() { + final FieldsImpl fields0() { if (type == LEFT_SEMI_JOIN || type == LEFT_ANTI_JOIN) { - return new Fields<>(lhs.asTable().fields()); + return new FieldsImpl<>(lhs.asTable().fields()); } else { Field[] l = lhs.asTable().fields(); @@ -576,7 +576,7 @@ implements System.arraycopy(l, 0, all, 0, l.length); System.arraycopy(r, 0, all, l.length, r.length); - return new Fields<>(all); + return new FieldsImpl<>(all); } } diff --git a/jOOQ/src/main/java/org/jooq/impl/Lateral.java b/jOOQ/src/main/java/org/jooq/impl/Lateral.java index 8a7f5cb873..f3bcb0cc31 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Lateral.java +++ b/jOOQ/src/main/java/org/jooq/impl/Lateral.java @@ -88,7 +88,7 @@ final class Lateral extends AbstractTable { } @Override - final Fields fields0() { - return new Fields<>(table.fields()); + final FieldsImpl fields0() { + return new FieldsImpl<>(table.fields()); } } diff --git a/jOOQ/src/main/java/org/jooq/impl/MergeImpl.java b/jOOQ/src/main/java/org/jooq/impl/MergeImpl.java index 9ec0ae7d4e..7c81eaae64 100644 --- a/jOOQ/src/main/java/org/jooq/impl/MergeImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/MergeImpl.java @@ -1396,7 +1396,7 @@ implements } private final void toSQLMySQLOnDuplicateKeyUpdate(Context ctx) { - Fields fields = new Fields<>(getUpsertFields()); + FieldsImpl fields = new FieldsImpl<>(getUpsertFields()); Map, Field> map = new LinkedHashMap<>(); for (Field field : fields.fields) map.put(field, getUpsertValues().get(fields.indexOf(field))); @@ -1417,7 +1417,7 @@ implements ctx.sql("[ merge with select is not supported in PostgreSQL ]"); } else { - Fields fields = new Fields<>(getUpsertFields()); + FieldsImpl fields = new FieldsImpl<>(getUpsertFields()); Map, Field> map = new LinkedHashMap<>(); for (Field field : fields.fields) { diff --git a/jOOQ/src/main/java/org/jooq/impl/MetaDataFieldProvider.java b/jOOQ/src/main/java/org/jooq/impl/MetaDataFieldProvider.java index 8ceb9abe9e..f322e56255 100644 --- a/jOOQ/src/main/java/org/jooq/impl/MetaDataFieldProvider.java +++ b/jOOQ/src/main/java/org/jooq/impl/MetaDataFieldProvider.java @@ -72,16 +72,16 @@ final class MetaDataFieldProvider implements Serializable { /** * Generated UID */ - private static final long serialVersionUID = -8482521025536063609L; - private static final JooqLogger log = JooqLogger.getLogger(MetaDataFieldProvider.class); + private static final long serialVersionUID = -8482521025536063609L; + private static final JooqLogger log = JooqLogger.getLogger(MetaDataFieldProvider.class); - private final Fields fields; + private final FieldsImpl fields; MetaDataFieldProvider(Configuration configuration, ResultSetMetaData meta) { this.fields = init(configuration, meta); } - private static Fields init(Configuration configuration, ResultSetMetaData meta) { + private static FieldsImpl init(Configuration configuration, ResultSetMetaData meta) { Field[] fields; int columnCount = 0; @@ -160,7 +160,7 @@ final class MetaDataFieldProvider implements Serializable { throw Tools.translate(null, e); } - return new Fields<>(fields); + return new FieldsImpl<>(fields); } final Field[] getFields() { diff --git a/jOOQ/src/main/java/org/jooq/impl/ResultImpl.java b/jOOQ/src/main/java/org/jooq/impl/ResultImpl.java index bf26dbc78c..c2f115183c 100644 --- a/jOOQ/src/main/java/org/jooq/impl/ResultImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/ResultImpl.java @@ -110,14 +110,14 @@ final class ResultImpl extends AbstractCursor implements Re private final List records; ResultImpl(Configuration configuration, Collection> fields) { - this(configuration, new Fields<>(fields)); + this(configuration, new FieldsImpl<>(fields)); } ResultImpl(Configuration configuration, Field... fields) { - this(configuration, new Fields<>(fields)); + this(configuration, new FieldsImpl<>(fields)); } - ResultImpl(Configuration configuration, Fields fields) { + ResultImpl(Configuration configuration, FieldsImpl fields) { super(configuration, fields); this.records = new ArrayList<>(); diff --git a/jOOQ/src/main/java/org/jooq/impl/RowImplN.java b/jOOQ/src/main/java/org/jooq/impl/RowImplN.java index aa210f4f9d..e5685f0be3 100644 --- a/jOOQ/src/main/java/org/jooq/impl/RowImplN.java +++ b/jOOQ/src/main/java/org/jooq/impl/RowImplN.java @@ -71,7 +71,7 @@ final class RowImplN extends AbstractRow implements RowN { super(fields); } - RowImplN(Fields fields) { + RowImplN(FieldsImpl fields) { super(fields); } diff --git a/jOOQ/src/main/java/org/jooq/impl/RowsFrom.java b/jOOQ/src/main/java/org/jooq/impl/RowsFrom.java index 1e0ece22a6..af6a4cd0fb 100644 --- a/jOOQ/src/main/java/org/jooq/impl/RowsFrom.java +++ b/jOOQ/src/main/java/org/jooq/impl/RowsFrom.java @@ -60,7 +60,7 @@ final class RowsFrom extends AbstractTable { */ private static final long serialVersionUID = 693765524746506586L; - private final TableList tables; + private final TableList tables; RowsFrom(Table... tables) { super(TableOptions.expression(), N_ROWSFROM); @@ -75,14 +75,14 @@ final class RowsFrom extends AbstractTable { } @Override - final Fields fields0() { + final FieldsImpl fields0() { List> fields = new ArrayList<>(); for (Table table : tables) for (Field field : table.fields()) fields.add(DSL.field(DSL.name(field.getName()), field.getDataType())); - return new Fields<>(fields); + return new FieldsImpl<>(fields); } @Override diff --git a/jOOQ/src/main/java/org/jooq/impl/SQLTable.java b/jOOQ/src/main/java/org/jooq/impl/SQLTable.java index e9e08acf15..42910be40f 100644 --- a/jOOQ/src/main/java/org/jooq/impl/SQLTable.java +++ b/jOOQ/src/main/java/org/jooq/impl/SQLTable.java @@ -72,7 +72,7 @@ final class SQLTable extends AbstractTable { } @Override - final Fields fields0() { - return new Fields<>(); + final FieldsImpl fields0() { + return new FieldsImpl<>(); } } diff --git a/jOOQ/src/main/java/org/jooq/impl/SelectImpl.java b/jOOQ/src/main/java/org/jooq/impl/SelectImpl.java index 973f494b65..fb07f4c206 100644 --- a/jOOQ/src/main/java/org/jooq/impl/SelectImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/SelectImpl.java @@ -4045,12 +4045,14 @@ final class SelectImpl> fieldStream() { return Stream.of(fields()); } + @Override public final Field field(Field field) { return getDelegate().field(field); @@ -4141,6 +4143,46 @@ final class SelectImpl[] types() { + return getDelegate().types(); + } + + @Override + public final Class type(int fieldIndex) { + return getDelegate().type(fieldIndex); + } + + @Override + public final Class type(String fieldName) { + return getDelegate().type(fieldName); + } + + @Override + public final Class type(Name fieldName) { + return getDelegate().type(fieldName); + } + + @Override + public final DataType[] dataTypes() { + return getDelegate().dataTypes(); + } + + @Override + public final DataType dataType(int fieldIndex) { + return getDelegate().dataType(fieldIndex); + } + + @Override + public final DataType dataType(String fieldName) { + return getDelegate().dataType(fieldName); + } + + @Override + public final DataType dataType(Name fieldName) { + return getDelegate().dataType(fieldName); + } + @Override public final ResultQuery coerce(Table table) { return getDelegate().coerce(table); diff --git a/jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java b/jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java index bc39e21dc6..3bffb43017 100644 --- a/jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java @@ -474,12 +474,14 @@ final class SelectQueryImpl extends AbstractResultQuery imp } + @Override public final Stream> fieldStream() { return Stream.of(fields()); } + @Override public final Field field(Field field) { return asTable().field(field); @@ -594,6 +596,46 @@ final class SelectQueryImpl extends AbstractResultQuery imp return asTable().indexOf(fieldName); } + @Override + public final Class[] types() { + return asTable().types(); + } + + @Override + public final Class type(int fieldIndex) { + return asTable().type(fieldIndex); + } + + @Override + public final Class type(String fieldName) { + return asTable().type(fieldName); + } + + @Override + public final Class type(Name fieldName) { + return asTable().type(fieldName); + } + + @Override + public final DataType[] dataTypes() { + return asTable().dataTypes(); + } + + @Override + public final DataType dataType(int fieldIndex) { + return asTable().dataType(fieldIndex); + } + + @Override + public final DataType dataType(String fieldName) { + return asTable().dataType(fieldName); + } + + @Override + public final DataType dataType(Name fieldName) { + return asTable().dataType(fieldName); + } + @Override public final Table asTable() { // Its usually better to alias nested selects that are used in @@ -3308,7 +3350,7 @@ final class SelectQueryImpl extends AbstractResultQuery imp private final Collection> subtract(List> left, List> right) { // [#7921] TODO Make this functionality more generally reusable - Fields e = new Fields<>(right); + FieldsImpl e = new FieldsImpl<>(right); List> result = new ArrayList<>(); for (Field f : left) @@ -3413,7 +3455,7 @@ final class SelectQueryImpl extends AbstractResultQuery imp } private final >> Q resolveAsterisk(Q result, QueryPartList> except) { - Fields e = except == null ? null : new Fields<>(except); + FieldsImpl e = except == null ? null : new FieldsImpl<>(except); // [#109] [#489] [#7231]: SELECT * is only applied when at least one // table from the table source is "unknown", i.e. not generated from a diff --git a/jOOQ/src/main/java/org/jooq/impl/TableAlias.java b/jOOQ/src/main/java/org/jooq/impl/TableAlias.java index a7ec8f6d3a..d742d7ad0f 100644 --- a/jOOQ/src/main/java/org/jooq/impl/TableAlias.java +++ b/jOOQ/src/main/java/org/jooq/impl/TableAlias.java @@ -60,7 +60,7 @@ final class TableAlias extends AbstractTable { private static final long serialVersionUID = -8417114874567698325L; final Alias> alias; - final Fields aliasedFields; + final FieldsImpl aliasedFields; TableAlias(Table table, Name alias) { this(table, alias, null, false); @@ -85,7 +85,7 @@ final class TableAlias extends AbstractTable { * Register fields for this table alias */ @SuppressWarnings({ "rawtypes", "unchecked" }) - private final Fields init(Name[] fieldAliases) { + private final FieldsImpl init(Name[] fieldAliases) { Row row = this.alias.wrapped().fieldsRow(); int size = row.size(); List> result = new ArrayList<>(size); @@ -99,7 +99,7 @@ final class TableAlias extends AbstractTable { result.add(new TableFieldImpl(name, field.getDataType(), this, field.getCommentPart(), field.getBinding())); } - return new Fields<>(result); + return new FieldsImpl<>(result); } /** @@ -163,7 +163,7 @@ final class TableAlias extends AbstractTable { } @Override - final Fields fields0() { + final FieldsImpl fields0() { return aliasedFields; } diff --git a/jOOQ/src/main/java/org/jooq/impl/TableImpl.java b/jOOQ/src/main/java/org/jooq/impl/TableImpl.java index 91be9f4708..b5bda33b1e 100644 --- a/jOOQ/src/main/java/org/jooq/impl/TableImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/TableImpl.java @@ -87,7 +87,7 @@ public class TableImpl extends AbstractTable { private static final Set NO_SUPPORT_QUALIFIED_TVF_CALLS = SQLDialect.supportedBy(HSQLDB, POSTGRES); private static final Set REQUIRES_TVF_TABLE_CONSTRUCTOR = SQLDialect.supportedBy(HSQLDB); - final Fields fields; + final FieldsImpl fields; final Alias> alias; protected final Field[] parameters; @@ -183,7 +183,7 @@ public class TableImpl extends AbstractTable { public TableImpl(Name name, Schema schema, Table child, ForeignKey path, Table aliased, Field[] parameters, Comment comment, TableOptions options) { super(options, name, schema, comment); - this.fields = new Fields<>(); + this.fields = new FieldsImpl<>(); this.child = child; this.childPath = path == null ? null : Tools.aliasedKey((ForeignKey) path, child, this); @@ -226,7 +226,7 @@ public class TableImpl extends AbstractTable { } @Override - final Fields fields0() { + final FieldsImpl fields0() { return fields; } diff --git a/jOOQ/src/main/java/org/jooq/impl/TableRecordImpl.java b/jOOQ/src/main/java/org/jooq/impl/TableRecordImpl.java index 3ac88bfded..96027ef663 100644 --- a/jOOQ/src/main/java/org/jooq/impl/TableRecordImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/TableRecordImpl.java @@ -309,7 +309,7 @@ public class TableRecordImpl> extends AbstractRecord im * Set all changed values of this record to a store query. */ final void addChangedValues(Field[] storeFields, StoreQuery query, boolean forUpdate) { - Fields f = new Fields<>(storeFields); + FieldsImpl f = new FieldsImpl<>(storeFields); for (Field field : fields.fields.fields) if (changed(field) && f.field(field) != null) diff --git a/jOOQ/src/main/java/org/jooq/impl/Tools.java b/jOOQ/src/main/java/org/jooq/impl/Tools.java index f9f7ac13d0..5e2619fbf0 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Tools.java +++ b/jOOQ/src/main/java/org/jooq/impl/Tools.java @@ -936,7 +936,7 @@ final class Tools { } } - static final AbstractRow row0(Fields fields) { + static final AbstractRow row0(FieldsImpl fields) { return row0(fields.fields); } diff --git a/jOOQ/src/main/java/org/jooq/impl/UDTImpl.java b/jOOQ/src/main/java/org/jooq/impl/UDTImpl.java index 46bb881553..3358896d7b 100644 --- a/jOOQ/src/main/java/org/jooq/impl/UDTImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/UDTImpl.java @@ -67,7 +67,7 @@ public class UDTImpl> extends AbstractNamed implements UD private static final long serialVersionUID = -2208672099190913126L; private final Schema schema; - private final Fields fields; + private final FieldsImpl fields; private final Package pkg; private final boolean synthetic; private transient DataType type; @@ -83,7 +83,7 @@ public class UDTImpl> extends AbstractNamed implements UD public UDTImpl(String name, Schema schema, Package pkg, boolean synthetic) { super(qualify(pkg != null ? pkg : schema, DSL.name(name)), CommentImpl.NO_COMMENT); - this.fields = new Fields<>(); + this.fields = new FieldsImpl<>(); this.schema = schema; this.pkg = pkg; this.synthetic = synthetic; @@ -116,12 +116,14 @@ public class UDTImpl> extends AbstractNamed implements UD } + @Override public final Stream> fieldStream() { return Stream.of(fields()); } + @Override public final Field field(Field field) { return fieldsRow().field(field); @@ -132,16 +134,46 @@ public class UDTImpl> extends AbstractNamed implements UD return fieldsRow().field(string); } + @Override + public final Field field(String name, Class t) { + return fieldsRow().field(name, t); + } + + @Override + public final Field field(String name, DataType t) { + return fieldsRow().field(name, t); + } + @Override public final Field field(Name fieldName) { return fieldsRow().field(fieldName); } + @Override + public final Field field(Name name, Class t) { + return fieldsRow().field(name, t); + } + + @Override + public final Field field(Name name, DataType t) { + return fieldsRow().field(name, t); + } + @Override public final Field field(int index) { return fieldsRow().field(index); } + @Override + public final Field field(int index, Class t) { + return fieldsRow().field(index, t); + } + + @Override + public final Field field(int index, DataType t) { + return fieldsRow().field(index, t); + } + @Override public final Field[] fields() { return fieldsRow().fields(); @@ -182,7 +214,47 @@ public class UDTImpl> extends AbstractNamed implements UD return fieldsRow().indexOf(fieldName); } - final Fields fields0() { + @Override + public final Class[] types() { + return fieldsRow().types(); + } + + @Override + public final Class type(int fieldIndex) { + return fieldsRow().type(fieldIndex); + } + + @Override + public final Class type(String fieldName) { + return fieldsRow().type(fieldName); + } + + @Override + public final Class type(Name fieldName) { + return fieldsRow().type(fieldName); + } + + @Override + public final DataType[] dataTypes() { + return fieldsRow().dataTypes(); + } + + @Override + public final DataType dataType(int fieldIndex) { + return fieldsRow().dataType(fieldIndex); + } + + @Override + public final DataType dataType(String fieldName) { + return fieldsRow().dataType(fieldName); + } + + @Override + public final DataType dataType(Name fieldName) { + return fieldsRow().dataType(fieldName); + } + + final FieldsImpl fields0() { return fields; } diff --git a/jOOQ/src/main/java/org/jooq/impl/Values.java b/jOOQ/src/main/java/org/jooq/impl/Values.java index 994b37b4e5..ec54881d2d 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Values.java +++ b/jOOQ/src/main/java/org/jooq/impl/Values.java @@ -86,7 +86,7 @@ final class Values extends AbstractTable { private static final long serialVersionUID = -637982217747670311L; static final Set NO_SUPPORT_VALUES = SQLDialect.supportedUntil(FIREBIRD, MARIADB); - private final Row[] rows; + private final Row[] rows; Values(Row[] rows) { super(TableOptions.expression(), N_VALUES); @@ -178,7 +178,7 @@ final class Values extends AbstractTable { } @Override - final Fields fields0() { - return new Fields<>(rows[0].fields()); + final FieldsImpl fields0() { + return new FieldsImpl<>(rows[0].fields()); } } diff --git a/jOOQ/src/main/java/org/jooq/impl/XMLTable.java b/jOOQ/src/main/java/org/jooq/impl/XMLTable.java index c41e8a1663..f5cc7f8ec4 100644 --- a/jOOQ/src/main/java/org/jooq/impl/XMLTable.java +++ b/jOOQ/src/main/java/org/jooq/impl/XMLTable.java @@ -94,7 +94,7 @@ implements private final XMLPassingMechanism passingMechanism; private final QueryPartList columns; private final boolean hasOrdinality; - private transient Fields fields; + private transient FieldsImpl fields; XMLTable(Field xpath) { this(xpath, null, null, null, false); @@ -210,14 +210,14 @@ implements } @Override - final Fields fields0() { + final FieldsImpl fields0() { if (fields == null) { List> f = new ArrayList<>(); for (XMLTableColumn c : columns) f.add(c.field.getDataType() == c.type ? c.field : DSL.field(c.field.getQualifiedName(), c.type)); - fields = new Fields<>(f); + fields = new FieldsImpl<>(f); } return fields;