From 1ab673fa9a1f8fb38877883f3d44b8e08ff0d7d0 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Wed, 21 Apr 2021 14:04:06 +0200 Subject: [PATCH] [jOOQ/jOOQ#11788] Add QualifiedRecord and RecordQualifier to unify the Table|UDT and TableRecord|UDTRecord type hierarchy This helps better implement Oracle %ROWTYPE support see [jOOQ/jOOQ#7863] --- .../main/java/org/jooq/QualifiedRecord.java | 65 ++++++++ .../main/java/org/jooq/RecordQualifier.java | 79 +++++++++ jOOQ/src/main/java/org/jooq/Table.java | 23 +-- jOOQ/src/main/java/org/jooq/TableRecord.java | 10 +- jOOQ/src/main/java/org/jooq/UDT.java | 31 +--- jOOQ/src/main/java/org/jooq/UDTRecord.java | 12 +- .../jooq/impl/AbstractQualifiedRecord.java | 154 ++++++++++++++++++ .../java/org/jooq/impl/AbstractTable.java | 6 + .../java/org/jooq/impl/DefaultBinding.java | 9 +- .../java/org/jooq/impl/TableRecordImpl.java | 42 +---- jOOQ/src/main/java/org/jooq/impl/Tools.java | 50 +++--- .../main/java/org/jooq/impl/UDTDataType.java | 4 +- .../java/org/jooq/impl/UDTRecordImpl.java | 88 +--------- .../org/jooq/impl/UpdatableRecordImpl.java | 4 +- 14 files changed, 347 insertions(+), 230 deletions(-) create mode 100644 jOOQ/src/main/java/org/jooq/QualifiedRecord.java create mode 100644 jOOQ/src/main/java/org/jooq/RecordQualifier.java create mode 100644 jOOQ/src/main/java/org/jooq/impl/AbstractQualifiedRecord.java diff --git a/jOOQ/src/main/java/org/jooq/QualifiedRecord.java b/jOOQ/src/main/java/org/jooq/QualifiedRecord.java new file mode 100644 index 0000000000..5b1372ab85 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/QualifiedRecord.java @@ -0,0 +1,65 @@ +/* + * 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.sql.SQLData; + +import org.jetbrains.annotations.NotNull; + +/** + * A record that has a {@link RecordQualifier} (a {@link UDTRecord} or a + * {@link TableRecord}). + * + * @author Lukas Eder + */ +public interface QualifiedRecord> extends Record, SQLData { + + /** + * Get the {@link UDT} or {@link Table} reference. + */ + @NotNull + RecordQualifier getQualifier(); + + @NotNull + @Override + R with(Field field, T value); + + @NotNull + @Override + R with(Field field, U value, Converter converter); +} diff --git a/jOOQ/src/main/java/org/jooq/RecordQualifier.java b/jOOQ/src/main/java/org/jooq/RecordQualifier.java new file mode 100644 index 0000000000..0c29af6cfa --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/RecordQualifier.java @@ -0,0 +1,79 @@ +/* + * 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 org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + + +/** + * A {@link UDT} or {@link Table}. + * + * @author Lukas Eder + */ +public interface RecordQualifier extends Qualified, Fields { + + /** + * Get the UDT package if this is a {@link UDT}, or null if it + * is not a UDT, or if it is a schema level UDT defined outside of a + * package. + */ + @Nullable + Package getPackage(); + + /** + * The record type produced by this {@link UDT} or {@link Table}. + */ + @NotNull + Class getRecordType(); + + /** + * The {@link UDT}'s or {@link Table}'s data type as known to the database. + */ + @NotNull + DataType getDataType(); + + /** + * Create a new {@link Record} of this {@link UDT}'s or {@link Table}'s type. + * + * @see DSLContext#newRecord(Table) + */ + @NotNull + R newRecord(); + +} diff --git a/jOOQ/src/main/java/org/jooq/Table.java b/jOOQ/src/main/java/org/jooq/Table.java index 037e28e895..5dc60fc592 100644 --- a/jOOQ/src/main/java/org/jooq/Table.java +++ b/jOOQ/src/main/java/org/jooq/Table.java @@ -123,7 +123,7 @@ import org.jetbrains.annotations.Nullable; * @param The record type associated with this table * @author Lukas Eder */ -public interface Table extends TableLike, Qualified { +public interface Table extends TableLike, RecordQualifier { /** * Get the table type. @@ -143,27 +143,6 @@ public interface Table extends TableLike, Qualified { @NotNull RecordType recordType(); - /** - * The record type produced by this table. - */ - @NotNull - Class getRecordType(); - - /** - * The table's record type as a UDT data type, in case the underlying - * database supports table records as UDT records. - */ - @NotNull - DataType getDataType(); - - /** - * Create a new {@link Record} of this table's type. - * - * @see DSLContext#newRecord(Table) - */ - @NotNull - R newRecord(); - /** * Retrieve the table's IDENTITY information, if available. *

diff --git a/jOOQ/src/main/java/org/jooq/TableRecord.java b/jOOQ/src/main/java/org/jooq/TableRecord.java index 4a2efe6a80..19dd1944d9 100644 --- a/jOOQ/src/main/java/org/jooq/TableRecord.java +++ b/jOOQ/src/main/java/org/jooq/TableRecord.java @@ -51,7 +51,7 @@ import org.jetbrains.annotations.Nullable; * @param The record type * @author Lukas Eder */ -public interface TableRecord> extends Record { +public interface TableRecord> extends QualifiedRecord { /** * The table from which this record was read. @@ -126,12 +126,4 @@ public interface TableRecord> extends Record { @NotNull @Support > Table parent(ForeignKey key); - - @NotNull - @Override - R with(Field field, T value); - - @NotNull - @Override - R with(Field field, U value, Converter converter); } diff --git a/jOOQ/src/main/java/org/jooq/UDT.java b/jOOQ/src/main/java/org/jooq/UDT.java index 8f6e172984..aaed0d365c 100644 --- a/jOOQ/src/main/java/org/jooq/UDT.java +++ b/jOOQ/src/main/java/org/jooq/UDT.java @@ -37,9 +37,6 @@ */ package org.jooq; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - /** * UDT definition. *

@@ -49,33 +46,7 @@ import org.jetbrains.annotations.Nullable; * @param The record type * @author Lukas Eder */ -public interface UDT> extends Fields, Qualified { - - /** - * Get the UDT package. - */ - @Nullable - Package getPackage(); - - /** - * @return The record type produced by this table. - */ - @NotNull - Class getRecordType(); - - /** - * Create a new {@link Record} of this UDT's type. - * - * @see DSLContext#newRecord(UDT) - */ - @NotNull - R newRecord(); - - /** - * The UDT's data type as known to the database. - */ - @NotNull - DataType getDataType(); +public interface UDT> extends RecordQualifier { /** * Whether this data type can be used from SQL statements. diff --git a/jOOQ/src/main/java/org/jooq/UDTRecord.java b/jOOQ/src/main/java/org/jooq/UDTRecord.java index bef21aa7ca..431df6dd0e 100644 --- a/jOOQ/src/main/java/org/jooq/UDTRecord.java +++ b/jOOQ/src/main/java/org/jooq/UDTRecord.java @@ -37,8 +37,6 @@ */ package org.jooq; -import java.sql.SQLData; - import org.jetbrains.annotations.NotNull; /** @@ -47,7 +45,7 @@ import org.jetbrains.annotations.NotNull; * @param The record type * @author Lukas Eder */ -public interface UDTRecord> extends Record, SQLData { +public interface UDTRecord> extends QualifiedRecord { /** * The UDT from which this record was read @@ -55,12 +53,4 @@ public interface UDTRecord> extends Record, SQLData { @NotNull UDT getUDT(); - @NotNull - @Override - R with(Field field, T value); - - @NotNull - @Override - R with(Field field, U value, Converter converter); - } diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractQualifiedRecord.java b/jOOQ/src/main/java/org/jooq/impl/AbstractQualifiedRecord.java new file mode 100644 index 0000000000..54b21b3219 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/AbstractQualifiedRecord.java @@ -0,0 +1,154 @@ +/* + * 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.impl; + +import static org.jooq.impl.DefaultExecuteContext.localConfiguration; +import static org.jooq.impl.DefaultExecuteContext.localData; +import static org.jooq.impl.Tools.fieldsArray; +import static org.jooq.impl.Tools.row0; + +import java.sql.SQLException; +import java.sql.SQLInput; +import java.sql.SQLOutput; +import java.util.Map; + +import org.jooq.Configuration; +import org.jooq.Converter; +import org.jooq.Field; +import org.jooq.QualifiedRecord; +import org.jooq.Record; +import org.jooq.RecordQualifier; +import org.jooq.Row; +import org.jooq.UDT; + +/** + * @author Lukas Eder + */ +abstract class AbstractQualifiedRecord> extends AbstractRecord implements QualifiedRecord { + + /** + * Generated UID + */ + + private static final long serialVersionUID = 6031695690614716816L; + private final RecordQualifier qualifier; + + public AbstractQualifiedRecord(RecordQualifier qualifier) { + super((AbstractRow) qualifier.fieldsRow()); + + this.qualifier = qualifier; + } + + // ------------------------------------------------------------------------- + // XXX: QualifiedRecord API + // ------------------------------------------------------------------------- + + @Override + public final RecordQualifier getQualifier() { + return qualifier; + } + + @SuppressWarnings("unchecked") + @Override + public final R with(Field field, T value) { + return (R) super.with(field, value); + } + + @SuppressWarnings("unchecked") + @Override + public final R with(Field field, U value, Converter converter) { + return (R) super.with(field, value, converter); + } + + /* + * Subclasses may override this method + */ + @Override + public Row fieldsRow() { + return fields; + } + + /* + * Subclasses may override this method + */ + @Override + public Row valuesRow() { + return row0(fieldsArray(intoArray(), fields.fields.fields())); + } + + // ------------------------------------------------------------------------- + // XXX: SQLData API + // ------------------------------------------------------------------------- + + @Override + public final String getSQLTypeName() throws SQLException { + + // [#1693] This needs to return the fully qualified SQL type name, in + // case the connected user is not the owner of the UDT + Configuration configuration = localConfiguration(); + return Tools.getMappedUDTName(configuration, this); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + public final void readSQL(SQLInput stream, String typeName) throws SQLException { + Configuration configuration = localConfiguration(); + Map data = localData(); + Field[] f = getQualifier().fields(); + + for (int i = 0; i < f.length; i++) { + Field field = f[i]; + DefaultBindingGetSQLInputContext out = new DefaultBindingGetSQLInputContext(configuration, data, stream); + field.getBinding().get(out); + set(i, field, out.value()); + } + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + public final void writeSQL(SQLOutput stream) throws SQLException { + Configuration configuration = localConfiguration(); + Map data = localData(); + Field[] f = getQualifier().fields(); + + for (int i = 0; i < f.length; i++) { + Field field = f[i]; + field.getBinding().set(new DefaultBindingSetSQLOutputContext(configuration, data, stream, get(i))); + } + } +} diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractTable.java b/jOOQ/src/main/java/org/jooq/impl/AbstractTable.java index 81d77f85f4..b5955b07d6 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AbstractTable.java +++ b/jOOQ/src/main/java/org/jooq/impl/AbstractTable.java @@ -90,6 +90,7 @@ import org.jooq.Index; import org.jooq.JoinType; // ... import org.jooq.Name; +import org.jooq.Package; // ... // ... // ... @@ -469,6 +470,11 @@ abstract class AbstractTable extends AbstractNamed implements return getSchema() == null ? null : getSchema().getCatalog(); } + @Override + public final Package getPackage() { + return null; + } + @Override public /* non-final */ Schema getSchema() { if (tableschema == null) diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultBinding.java b/jOOQ/src/main/java/org/jooq/impl/DefaultBinding.java index 97d14ea9df..1cbf8b2199 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultBinding.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultBinding.java @@ -194,6 +194,7 @@ import org.jooq.JSON; import org.jooq.JSONB; import org.jooq.Param; // ... +import org.jooq.QualifiedRecord; import org.jooq.Record; import org.jooq.RenderContext; import org.jooq.Result; @@ -505,11 +506,11 @@ public class DefaultBinding implements Binding { @SuppressWarnings("unchecked") static final Map> typeMap(Class type, Configuration configuration, Map> result) { try { - if (UDTRecord.class.isAssignableFrom(type)) { - Class> t = (Class>) type; + if (QualifiedRecord.class.isAssignableFrom(type)) { + Class> t = (Class>) type; result.put(getMappedUDTName(configuration, t), t); - UDTRecord r = t.newInstance(); - for (Field field : r.getUDT().fields()) + QualifiedRecord r = t.getConstructor().newInstance(); + for (Field field : r.getQualifier().fields()) typeMap(field.getType(), configuration, result); } diff --git a/jOOQ/src/main/java/org/jooq/impl/TableRecordImpl.java b/jOOQ/src/main/java/org/jooq/impl/TableRecordImpl.java index 0b2107272b..6ae3eb6fad 100644 --- a/jOOQ/src/main/java/org/jooq/impl/TableRecordImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/TableRecordImpl.java @@ -51,9 +51,7 @@ import static org.jooq.conf.SettingsTools.updatablePrimaryKeys; import static org.jooq.impl.RecordDelegate.delegate; import static org.jooq.impl.RecordDelegate.RecordLifecycleType.INSERT; import static org.jooq.impl.Tools.EMPTY_FIELD; -import static org.jooq.impl.Tools.fieldsArray; import static org.jooq.impl.Tools.indexOrFail; -import static org.jooq.impl.Tools.row0; import static org.jooq.impl.Tools.settings; import static org.jooq.impl.Tools.BooleanDataKey.DATA_OMIT_RETURNING_CLAUSE; @@ -65,7 +63,6 @@ import java.util.LinkedHashSet; import java.util.Set; import org.jooq.Configuration; -import org.jooq.Converter; import org.jooq.DSLContext; import org.jooq.DataType; import org.jooq.Field; @@ -73,7 +70,6 @@ import org.jooq.ForeignKey; import org.jooq.Identity; import org.jooq.InsertQuery; import org.jooq.Record; -import org.jooq.Row; import org.jooq.SQLDialect; import org.jooq.StoreQuery; import org.jooq.Table; @@ -91,7 +87,7 @@ import org.jooq.tools.JooqLogger; * @author Lukas Eder */ @org.jooq.Internal -public class TableRecordImpl> extends AbstractRecord implements TableRecord { +public class TableRecordImpl> extends AbstractQualifiedRecord implements TableRecord { /** * Generated UID @@ -100,45 +96,13 @@ public class TableRecordImpl> extends AbstractRecord im private static final JooqLogger log = JooqLogger.getLogger(TableRecordImpl.class); private static final Set REFRESH_GENERATED_KEYS = SQLDialect.supportedBy(DERBY, H2, MARIADB, MYSQL); - private final Table table; - public TableRecordImpl(Table table) { - super((AbstractRow) table.fieldsRow()); - - this.table = table; - } - - @SuppressWarnings("unchecked") - @Override - public final R with(Field field, T value) { - return (R) super.with(field, value); - } - - @SuppressWarnings("unchecked") - @Override - public final R with(Field field, U value, Converter converter) { - return (R) super.with(field, value, converter); + super(table); } @Override public final Table getTable() { - return table; - } - - /* - * Subclasses may override this method - */ - @Override - public Row fieldsRow() { - return fields; - } - - /* - * Subclasses may override this method - */ - @Override - public Row valuesRow() { - return row0(fieldsArray(intoArray(), fields.fields.fields())); + return (Table) getQualifier(); } @SuppressWarnings("unchecked") diff --git a/jOOQ/src/main/java/org/jooq/impl/Tools.java b/jOOQ/src/main/java/org/jooq/impl/Tools.java index e769d272c7..8bde29fa66 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Tools.java +++ b/jOOQ/src/main/java/org/jooq/impl/Tools.java @@ -257,10 +257,12 @@ import org.jooq.OrderField; import org.jooq.Param; // ... import org.jooq.QualifiedAsterisk; +import org.jooq.QualifiedRecord; import org.jooq.Query; import org.jooq.QueryPart; import org.jooq.Record; import org.jooq.Record1; +import org.jooq.RecordQualifier; import org.jooq.RecordType; import org.jooq.RenderContext; import org.jooq.RenderContext.CastMode; @@ -911,38 +913,30 @@ final class Tools { } /** - * Create a new record + * Create a new record. */ static final RecordDelegate newRecord(boolean fetched, Class type, AbstractRow fields) { return newRecord(fetched, type, fields, null); } /** - * Create a new record + * Create a new {@link Table} or {@link UDT} record. */ - @SuppressWarnings("unchecked") - static final RecordDelegate newRecord(boolean fetched, Table type, Configuration configuration) { - return (RecordDelegate) newRecord(fetched, type.getRecordType(), (AbstractRow) type.fieldsRow(), configuration); - } - - /** - * Create a new UDT record - */ - static final > RecordDelegate newRecord(boolean fetched, UDT type) { + static final RecordDelegate newRecord(boolean fetched, RecordQualifier type) { return newRecord(fetched, type, null); } /** - * Create a new UDT record + * Create a new {@link Table} or {@link UDT} record. */ - static final > RecordDelegate newRecord(boolean fetched, UDT type, Configuration configuration) { + static final RecordDelegate newRecord(boolean fetched, RecordQualifier type, Configuration configuration) { return newRecord(fetched, type.getRecordType(), (AbstractRow) type.fieldsRow(), configuration); } /** * Create a new record. */ - static final RecordDelegate newRecord(boolean fetched, Class type, AbstractRow fields, Configuration configuration) { + static final RecordDelegate newRecord(boolean fetched, Class type, AbstractRow fields, Configuration configuration) { return newRecord(fetched, recordFactory(type, fields), configuration); } @@ -1031,7 +1025,7 @@ final class Tools { * Create a new record factory. */ @SuppressWarnings({ "unchecked" }) - static final Supplier recordFactory(final Class type, final AbstractRow row) { + static final Supplier recordFactory(Class type, AbstractRow row) { // An ad-hoc type resulting from a JOIN or arbitrary SELECT if (type == AbstractRecord.class || type == Record.class || InternalRecord.class.isAssignableFrom(type)) { @@ -1072,7 +1066,7 @@ final class Tools { try { // [#919] Allow for accessing non-public constructors - final Constructor constructor = Reflect.accessible(type.getDeclaredConstructor()); + final Constructor constructor = Reflect.accessible(type.getDeclaredConstructor()); return () -> { try { @@ -2947,7 +2941,6 @@ final class Tools { /** * Map a {@link Catalog} according to the configured {@link org.jooq.SchemaMapping} */ - @SuppressWarnings("deprecation") static final Catalog getMappedCatalog(Configuration configuration, Catalog catalog) { if (configuration != null) { org.jooq.SchemaMapping mapping = configuration.schemaMapping(); @@ -2962,7 +2955,6 @@ final class Tools { /** * Map a {@link Schema} according to the configured {@link org.jooq.SchemaMapping} */ - @SuppressWarnings("deprecation") static final Schema getMappedSchema(Configuration configuration, Schema schema) { if (configuration != null) { org.jooq.SchemaMapping mapping = configuration.schemaMapping(); @@ -2977,7 +2969,6 @@ final class Tools { /** * Map a {@link Table} according to the configured {@link org.jooq.SchemaMapping} */ - @SuppressWarnings("deprecation") static final Table getMappedTable(Configuration configuration, Table table) { if (configuration != null) { org.jooq.SchemaMapping mapping = configuration.schemaMapping(); @@ -2990,18 +2981,20 @@ final class Tools { } /** - * Map an {@link ArrayRecord} according to the configured {@link org.jooq.SchemaMapping} + * Map an {@link UDTRecord} according to the configured + * {@link org.jooq.SchemaMapping} */ @SuppressWarnings("unchecked") - static final String getMappedUDTName(Configuration configuration, Class> type) { - return getMappedUDTName(configuration, Tools.newRecord(false, (Class>) type).operate(null)); + static final String getMappedUDTName(Configuration configuration, Class> type) { + return getMappedUDTName(configuration, Tools.newRecord(false, (Class>) type).operate(null)); } /** - * Map an {@link ArrayRecord} according to the configured {@link org.jooq.SchemaMapping} + * Map an {@link UDTRecord} according to the configured + * {@link org.jooq.SchemaMapping} */ - static final String getMappedUDTName(Configuration configuration, UDTRecord record) { - UDT udt = record.getUDT(); + static final String getMappedUDTName(Configuration configuration, QualifiedRecord record) { + RecordQualifier udt = record.getQualifier(); Schema mapped = getMappedSchema(configuration, udt.getSchema()); StringBuilder sb = new StringBuilder(); @@ -3013,7 +3006,12 @@ final class Tools { - sb.append(record.getUDT().getName()); + sb.append(record.getQualifier().getName()); + + + + + return sb.toString(); } diff --git a/jOOQ/src/main/java/org/jooq/impl/UDTDataType.java b/jOOQ/src/main/java/org/jooq/impl/UDTDataType.java index 276111fa01..5f6c645ce2 100644 --- a/jOOQ/src/main/java/org/jooq/impl/UDTDataType.java +++ b/jOOQ/src/main/java/org/jooq/impl/UDTDataType.java @@ -51,8 +51,8 @@ final class UDTDataType> extends DefaultDataType { */ private static final long serialVersionUID = 3262508265391094581L; + @SuppressWarnings("unchecked") UDTDataType(UDT udt) { - super(SQLDialect.DEFAULT, udt.getRecordType(), Tools.asString(udt.getQualifiedName())); + super(SQLDialect.DEFAULT, (Class) udt.getRecordType(), Tools.asString(udt.getQualifiedName())); } - } diff --git a/jOOQ/src/main/java/org/jooq/impl/UDTRecordImpl.java b/jOOQ/src/main/java/org/jooq/impl/UDTRecordImpl.java index f5c552cc20..f7981023d3 100644 --- a/jOOQ/src/main/java/org/jooq/impl/UDTRecordImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/UDTRecordImpl.java @@ -37,20 +37,6 @@ */ package org.jooq.impl; -import static org.jooq.impl.DefaultExecuteContext.localConfiguration; -import static org.jooq.impl.DefaultExecuteContext.localData; -import static org.jooq.impl.Tools.fieldsArray; -import static org.jooq.impl.Tools.row0; - -import java.sql.SQLException; -import java.sql.SQLInput; -import java.sql.SQLOutput; -import java.util.Map; - -import org.jooq.Configuration; -import org.jooq.Converter; -import org.jooq.Field; -import org.jooq.Row; import org.jooq.UDT; import org.jooq.UDTRecord; @@ -62,88 +48,20 @@ import org.jooq.UDTRecord; * @author Lukas Eder */ @org.jooq.Internal -public class UDTRecordImpl> extends AbstractRecord implements UDTRecord { +public class UDTRecordImpl> extends AbstractQualifiedRecord implements UDTRecord { /** * Generated UID */ private static final long serialVersionUID = 5671315498175872799L; - private final UDT udt; public UDTRecordImpl(UDT udt) { - super((AbstractRow) udt.fieldsRow()); - - this.udt = udt; + super(udt); } @Override public final UDT getUDT() { - return udt; - } - - /* - * Subclasses may override this method - */ - @Override - public Row fieldsRow() { - return fields; - } - - /* - * Subclasses may override this method - */ - @Override - public Row valuesRow() { - return row0(fieldsArray(intoArray(), fields.fields.fields())); - } - - @Override - public final String getSQLTypeName() throws SQLException { - - // [#1693] This needs to return the fully qualified SQL type name, in - // case the connected user is not the owner of the UDT - Configuration configuration = localConfiguration(); - return Tools.getMappedUDTName(configuration, this); - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Override - public final void readSQL(SQLInput stream, String typeName) throws SQLException { - Configuration configuration = localConfiguration(); - Map data = localData(); - Field[] f = getUDT().fields(); - - for (int i = 0; i < f.length; i++) { - Field field = f[i]; - DefaultBindingGetSQLInputContext out = new DefaultBindingGetSQLInputContext(configuration, data, stream); - field.getBinding().get(out); - set(i, field, out.value()); - } - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Override - public final void writeSQL(SQLOutput stream) throws SQLException { - Configuration configuration = localConfiguration(); - Map data = localData(); - Field[] f = getUDT().fields(); - - for (int i = 0; i < f.length; i++) { - Field field = f[i]; - field.getBinding().set(new DefaultBindingSetSQLOutputContext(configuration, data, stream, get(i))); - } - } - - @SuppressWarnings("unchecked") - @Override - public final R with(Field field, T value) { - return (R) super.with(field, value); - } - - @SuppressWarnings("unchecked") - @Override - public final R with(Field field, U value, Converter converter) { - return (R) super.with(field, value, converter); + return (UDT) getQualifier(); } @Override diff --git a/jOOQ/src/main/java/org/jooq/impl/UpdatableRecordImpl.java b/jOOQ/src/main/java/org/jooq/impl/UpdatableRecordImpl.java index d01e709bc7..85fe64f86a 100644 --- a/jOOQ/src/main/java/org/jooq/impl/UpdatableRecordImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/UpdatableRecordImpl.java @@ -429,7 +429,7 @@ public class UpdatableRecordImpl> extends TableReco // [#3359] The "fetched" flag must be set to false to enforce INSERT statements on // subsequent store() calls - when Settings.updatablePrimaryKeys is set. - return (R) Tools.newRecord(false, getTable(), configuration()) + return Tools.newRecord(false, getTable(), configuration()) .operate(copy -> { // Copy all fields. This marks them all as isChanged, which is important @@ -440,7 +440,7 @@ public class UpdatableRecordImpl> extends TableReco if (!key.contains(field)) copy.set((Field) field, get(field)); - return (R) copy; + return copy; }); }