[#2798] Inconsistent logic executed between Record.setValue(Field<T>, T) and BookRecord.setId(Integer) (generated)

This commit is contained in:
Lukas Eder 2013-12-07 12:38:04 +01:00
parent 8875940e9d
commit 5f7b344a8a
3 changed files with 46 additions and 9 deletions

View File

@ -55,6 +55,7 @@ import org.jooq.TableRecord;
import org.jooq.UpdatableRecord;
import org.jooq.test.BaseTest;
import org.jooq.test.jOOQAbstractTest;
import org.jooq.tools.reflect.Reflect;
import org.junit.Test;
@ -153,6 +154,33 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, UU, I, IPK, T7
assertEquals("abc", book.original(TBook_TITLE()));
}
@Test
public void testRecordChangedOnGeneratedMethods() throws Exception {
// [#2798] Generated methods might show a different behaviour with respect to changed flags,
// compared to regular API.
B b1 = create().selectFrom(TBook()).where(TBook_ID().eq(1)).fetchOne();
B b2 = create().selectFrom(TBook()).where(TBook_ID().eq(1)).fetchOne();
b1.setValue(TBook_ID(), 1);
Reflect.on(b2).call("setId", 1);
assertEquals(b1, b2);
assertFalse(b1.changed());
assertFalse(b2.changed());
assertFalse(b1.changed(TBook_ID()));
assertFalse(b2.changed(TBook_ID()));
b1.setValue(TBook_ID(), 2);
Reflect.on(b2).call("setId", 2);
assertEquals(b1, b2);
assertTrue(b1.changed());
assertTrue(b2.changed());
assertTrue(b1.changed(TBook_ID()));
assertTrue(b2.changed(TBook_ID()));
}
@Test
public void testRecordReset() throws Exception {
B book = create().selectFrom(TBook()).where(TBook_ID().eq(1)).fetchOne();

View File

@ -1551,6 +1551,11 @@ public abstract class jOOQAbstractTest<
new RecordTests(this).testRecordChanged();
}
@Test
public void testRecordChangedOnGeneratedMethods() throws Exception {
new RecordTests(this).testRecordChangedOnGeneratedMethods();
}
@Test
public void testRecordReset() throws Exception {
new RecordTests(this).testRecordReset();

View File

@ -286,9 +286,21 @@ abstract class AbstractRecord extends AbstractStore implements Record {
return values;
}
/**
* Subclasses may type-unsafely set a value to a record index. This method
* takes care of converting the value to the appropriate type.
*/
protected final void setValue(int index, Object value) {
setValue(index, (Field) field(index), value);
}
@Override
public final <T> void setValue(Field<T> field, T value) {
Value<T> val = getValue0(field);
setValue(fields.indexOf(field), field, value);
}
private final <T> void setValue(int index, Field<T> field, T value) {
Value<T> val = getValue0(index);
UniqueKey<?> key = getPrimaryKey();
// Normal fields' changed flag is always set to true
@ -337,14 +349,6 @@ abstract class AbstractRecord extends AbstractStore implements Record {
getValues()[index] = value;
}
/**
* Subclasses may type-unsafely set a value to a record index. This method
* takes care of converting the value to the appropriate type.
*/
protected final void setValue(int index, Object value) {
getValue0(index).setValue(Convert.convert(value, fields.type(index)));
}
/**
* Subclasses may override this
*/