[#1002] TableRecord.storeUsing() doesn't update IDENTITY column values, if the column is not part of the main unique key
This commit is contained in:
parent
ef8c6cd43a
commit
2936124b63
@ -765,9 +765,8 @@ public abstract class jOOQAbstractTest<
|
||||
}
|
||||
|
||||
// TODO [#1002] Fix this
|
||||
// R r5 = create().fetchOne(table, id.equal(5));
|
||||
// assertEquals(r5, r4);
|
||||
|
||||
R r5 = create().fetchOne(table, id.equal(5));
|
||||
assertEquals(r5, r4);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -35,12 +35,13 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
|
||||
import org.jooq.ConditionProvider;
|
||||
import org.jooq.DeleteQuery;
|
||||
import org.jooq.Field;
|
||||
import org.jooq.Identity;
|
||||
import org.jooq.InsertQuery;
|
||||
import org.jooq.SimpleSelectQuery;
|
||||
import org.jooq.StoreQuery;
|
||||
@ -121,7 +122,8 @@ public class TableRecordImpl<R extends TableRecord<R>> extends TypeRecord<Table<
|
||||
}
|
||||
|
||||
// [#814] Refresh identity and/or main unique key values
|
||||
List<Field<?>> key = getKey();
|
||||
// [#1002] Consider also identity columns of non-updatable records
|
||||
Collection<Field<?>> key = getReturning();
|
||||
insert.setReturning(key);
|
||||
int result = insert.execute();
|
||||
|
||||
@ -140,8 +142,15 @@ public class TableRecordImpl<R extends TableRecord<R>> extends TypeRecord<Table<
|
||||
/**
|
||||
* Subclasses may override this method to provide an identity
|
||||
*/
|
||||
List<Field<?>> getKey() {
|
||||
return Collections.emptyList();
|
||||
Collection<Field<?>> getReturning() {
|
||||
Collection<Field<?>> result = new LinkedHashSet<Field<?>>();
|
||||
|
||||
Identity<R, ?> identity = getTable().getIdentity();
|
||||
if (identity != null) {
|
||||
result.add(identity.getField());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@ -35,13 +35,9 @@
|
||||
*/
|
||||
package org.jooq.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.jooq.Field;
|
||||
import org.jooq.Identity;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.UniqueKey;
|
||||
import org.jooq.UpdatableRecord;
|
||||
@ -91,16 +87,10 @@ public class UpdatableRecordImpl<R extends UpdatableRecord<R>> extends TableReco
|
||||
}
|
||||
|
||||
@Override
|
||||
List<Field<?>> getKey() {
|
||||
Set<Field<?>> result = new LinkedHashSet<Field<?>>();
|
||||
|
||||
Identity<R, ?> identity = getTable().getIdentity();
|
||||
if (identity != null) {
|
||||
result.add(identity.getField());
|
||||
}
|
||||
|
||||
Collection<Field<?>> getReturning() {
|
||||
Collection<Field<?>> result = super.getReturning();
|
||||
result.addAll(getMainKey().getFields());
|
||||
return new ArrayList<Field<?>>(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
Reference in New Issue
Block a user