[jOOQ/jOOQ#10828] Record.get(Field) doesn't work for embeddable table fields when non field-replacing embeddables are projected explicitly
This commit is contained in:
parent
d474d3f69a
commit
ebf9b5e50c
@ -43,6 +43,7 @@ import static org.jooq.conf.SettingsTools.updatablePrimaryKeys;
|
||||
import static org.jooq.impl.Tools.EMPTY_FIELD;
|
||||
import static org.jooq.impl.Tools.converterOrFail;
|
||||
import static org.jooq.impl.Tools.embeddedFields;
|
||||
import static org.jooq.impl.Tools.indexFail;
|
||||
import static org.jooq.impl.Tools.indexOrFail;
|
||||
import static org.jooq.impl.Tools.resetChangedOnNotNull;
|
||||
import static org.jooq.impl.Tools.settings;
|
||||
@ -249,12 +250,16 @@ abstract class AbstractRecord extends AbstractStore implements Record {
|
||||
|
||||
@Override
|
||||
public final <T> T get(Field<T> field) {
|
||||
if (Tools.nonReplacingEmbeddable(field))
|
||||
int index = fieldsRow().indexOf(field);
|
||||
|
||||
if (index >= 0)
|
||||
return (T) get(index);
|
||||
else if (Tools.nonReplacingEmbeddable(field))
|
||||
return (T) Tools
|
||||
.newRecord(fetched, ((EmbeddableTableField<?, ?>) field).recordType)
|
||||
.operate(new TransferRecordState<Record>(embeddedFields(field)));
|
||||
else
|
||||
return (T) get(indexOrFail(fieldsRow(), field));
|
||||
throw Tools.indexFail(fieldsRow(), field);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -329,7 +334,11 @@ abstract class AbstractRecord extends AbstractStore implements Record {
|
||||
|
||||
@Override
|
||||
public final <T> void set(Field<T> field, T value) {
|
||||
if (Tools.nonReplacingEmbeddable(field)) {
|
||||
int index = fields.indexOf(field);
|
||||
|
||||
if (index >= 0)
|
||||
set(index, field, value);
|
||||
else if (Tools.nonReplacingEmbeddable(field)) {
|
||||
Field<?>[] f = embeddedFields(field);
|
||||
Object[] v = value instanceof EmbeddableRecord
|
||||
? ((EmbeddableRecord) value).intoArray()
|
||||
@ -339,7 +348,7 @@ abstract class AbstractRecord extends AbstractStore implements Record {
|
||||
set(indexOrFail(fields, f[i]), f[i], v[i]);
|
||||
}
|
||||
else
|
||||
set(indexOrFail(fields, field), field, value);
|
||||
throw indexFail(fields, field);
|
||||
}
|
||||
|
||||
final void set(int index, Field<?> field, Object value) {
|
||||
|
||||
@ -1996,41 +1996,41 @@ final class Tools {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* A utility method that fails with an exception if
|
||||
* {@link Row#indexOf(Field)} doesn't return any index.
|
||||
*/
|
||||
static final IllegalArgumentException indexFail(Row row, Field<?> field) {
|
||||
return new IllegalArgumentException("Field (" + field + ") is not contained in Row " + row);
|
||||
}
|
||||
|
||||
static final int indexOrFail(Row row, Field<?> field) {
|
||||
int result = row.indexOf(field);
|
||||
|
||||
if (result < 0)
|
||||
throw new IllegalArgumentException("Field (" + field + ") is not contained in Row " + row);
|
||||
throw indexFail(row, field);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* A utility method that fails with an exception if
|
||||
* {@link Row#indexOf(String)} doesn't return any index.
|
||||
*/
|
||||
static final IllegalArgumentException indexFail(Row row, String fieldName) {
|
||||
throw new IllegalArgumentException("Field (" + fieldName + ") is not contained in Row " + row);
|
||||
}
|
||||
|
||||
static final int indexOrFail(Row row, String fieldName) {
|
||||
int result = row.indexOf(fieldName);
|
||||
|
||||
if (result < 0)
|
||||
throw new IllegalArgumentException("Field (" + fieldName + ") is not contained in Row " + row);
|
||||
throw indexFail(row, fieldName);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* A utility method that fails with an exception if
|
||||
* {@link Row#indexOf(Name)} doesn't return any index.
|
||||
*/
|
||||
static final IllegalArgumentException indexFail(Row row, Name fieldName) {
|
||||
throw new IllegalArgumentException("Field (" + fieldName + ") is not contained in Row " + row);
|
||||
}
|
||||
|
||||
static final int indexOrFail(Row row, Name fieldName) {
|
||||
int result = row.indexOf(fieldName);
|
||||
|
||||
if (result < 0)
|
||||
throw new IllegalArgumentException("Field (" + fieldName + ") is not contained in Row " + row);
|
||||
throw indexFail(row, fieldName);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user