[#1848] Add Record.changed() to indicate whether a Record contains

"dirty" values
This commit is contained in:
Lukas Eder 2012-09-28 17:41:09 +02:00
parent f23491be9e
commit d82d95ef78
4 changed files with 42 additions and 0 deletions

View File

@ -36,6 +36,8 @@
package org.jooq.test._.testcases;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import org.jooq.TableRecord;
import org.jooq.UpdatableRecord;
@ -80,13 +82,26 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, I, IPK, T658,
assertEquals(book.getValue(TBook_TITLE()), orig.getValue(TBook_TITLE()));
book.setValue(TBook_TITLE(), "abc");
assertFalse(book.equals(orig));
assertFalse(book.equals(book.original()));
assertEquals("abc", book.getValue(TBook_TITLE()));
assertEquals(BOOK_TITLES.get(0), orig.getValue(TBook_TITLE()));
book = orig;
orig = orig.original();
book.setValue(TBook_TITLE(), "abc");
assertFalse(book.equals(orig));
assertFalse(book.equals(book.original()));
assertEquals("abc", book.getValue(TBook_TITLE()));
assertEquals(BOOK_TITLES.get(0), orig.getValue(TBook_TITLE()));
}
@Test
public void testRecordChanged() throws Exception {
B book = create().selectFrom(TBook()).where(TBook_ID().eq(1)).fetchOne();
assertFalse(book.changed());
book.setValue(TBook_TITLE(), "abc");
assertTrue(book.changed());
}
}

View File

@ -1162,6 +1162,11 @@ public abstract class jOOQAbstractTest<
new RecordTests(this).testRecordOriginals();
}
@Test
public void testRecordChanged() throws Exception {
new RecordTests(this).testRecordChanged();
}
@Test
public void testConcurrentExecution() throws Exception {
new ThreadSafetyTests(this).testConcurrentExecution();

View File

@ -1118,6 +1118,17 @@ public interface Record extends FieldProvider, Store<Object> {
*/
Record original();
/**
* Check if this record has been changed from its original as fetched from
* the database.
* <p>
* If this returns <code>false</code>, then it can be said that
* <code>record.equals(record.original())</code> is true.
*
* @see #original()
*/
boolean changed();
/**
* Convert this record into an array.
* <p>

View File

@ -609,6 +609,17 @@ abstract class AbstractRecord extends AbstractStore<Object> implements Record {
return result;
}
@Override
public final boolean changed() {
for (Value<?> value : getValues()) {
if (value.isChanged()) {
return true;
}
}
return false;
}
@Override
public final Object[] intoArray() {
return into(Object[].class);