[#2000] Add Record.reset(), reset(Field<?>), reset(int), reset(String)
to restore original values in a record
This commit is contained in:
parent
092700e0ec
commit
4fdf22e710
@ -145,4 +145,30 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, I, IPK, T725,
|
||||
assertEquals("abc", book.original().getValue(TBook_TITLE()));
|
||||
assertEquals("abc", book.original(TBook_TITLE()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRecordReset() throws Exception {
|
||||
B book = create().selectFrom(TBook()).where(TBook_ID().eq(1)).fetchOne();
|
||||
|
||||
book.setValue(TBook_TITLE(), "abc");
|
||||
book.reset();
|
||||
assertFalse(book.changed());
|
||||
assertFalse(book.changed(TBook_TITLE()));
|
||||
assertFalse(book.changed(TBook_TITLE().getName()));
|
||||
assertEquals("1984", book.getValue(TBook_TITLE()));
|
||||
|
||||
book.setValue(TBook_TITLE(), "abc");
|
||||
book.reset(TBook_TITLE());
|
||||
assertFalse(book.changed());
|
||||
assertFalse(book.changed(TBook_TITLE()));
|
||||
assertFalse(book.changed(TBook_TITLE().getName()));
|
||||
assertEquals("1984", book.getValue(TBook_TITLE()));
|
||||
|
||||
book.setValue(TBook_TITLE(), "abc");
|
||||
book.reset(TBook_TITLE().getName());
|
||||
assertFalse(book.changed());
|
||||
assertFalse(book.changed(TBook_TITLE()));
|
||||
assertFalse(book.changed(TBook_TITLE().getName()));
|
||||
assertEquals("1984", book.getValue(TBook_TITLE()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1203,6 +1203,11 @@ public abstract class jOOQAbstractTest<
|
||||
new RecordTests(this).testRecordChanged();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRecordReset() throws Exception {
|
||||
new RecordTests(this).testRecordReset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConcurrentExecution() throws Exception {
|
||||
new ThreadSafetyTests(this).testConcurrentExecution();
|
||||
|
||||
@ -499,6 +499,30 @@ public interface Record extends FieldProvider, Attachable {
|
||||
*/
|
||||
void changed(boolean changed, String fieldName);
|
||||
|
||||
/**
|
||||
* Reset all values to their {@link #original()} values and all
|
||||
* {@link #changed()} flags to <code>false</code>.
|
||||
*/
|
||||
void reset();
|
||||
|
||||
/**
|
||||
* Reset a given value to its {@link #original(Field)} value and its
|
||||
* {@link #changed(Field)} flag to <code>false</code>.
|
||||
*/
|
||||
void reset(Field<?> field);
|
||||
|
||||
/**
|
||||
* Reset a given value to its {@link #original(int)} value and its
|
||||
* {@link #changed(int)} flag to <code>false</code>.
|
||||
*/
|
||||
void reset(int fieldIndex);
|
||||
|
||||
/**
|
||||
* Reset a given value to its {@link #original(String)} value and its
|
||||
* {@link #changed(String)} flag to <code>false</code>.
|
||||
*/
|
||||
void reset(String fieldName);
|
||||
|
||||
/**
|
||||
* Convert this record into an array.
|
||||
* <p>
|
||||
|
||||
@ -422,6 +422,28 @@ abstract class AbstractRecord extends AbstractStore implements Record {
|
||||
changed(changed, getIndex(fieldName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void reset() {
|
||||
for (Value<?> value : getValues()) {
|
||||
value.reset();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void reset(Field<?> field) {
|
||||
reset(getIndex(field));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void reset(int fieldIndex) {
|
||||
getValue0(fieldIndex).reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void reset(String fieldName) {
|
||||
reset(getIndex(fieldName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Object[] intoArray() {
|
||||
return into(Object[].class);
|
||||
|
||||
@ -114,6 +114,11 @@ class Value<T> implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
final void reset() {
|
||||
isChanged = false;
|
||||
value = original;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// XXX: Object API
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
Loading…
Reference in New Issue
Block a user