diff --git a/jOOQ-test/src/org/jooq/test/BaseTest.java b/jOOQ-test/src/org/jooq/test/BaseTest.java index 292d768f8b..562baea8cb 100644 --- a/jOOQ-test/src/org/jooq/test/BaseTest.java +++ b/jOOQ-test/src/org/jooq/test/BaseTest.java @@ -35,6 +35,8 @@ */ package org.jooq.test; +import static junit.framework.Assert.assertEquals; + import java.lang.reflect.Method; import java.math.BigDecimal; import java.math.BigInteger; @@ -781,6 +783,14 @@ public abstract class BaseTest< .fetchOne(); } + protected final void assertCountAuthors(int count) { + assertEquals(count, (int) create().selectCount().from(TAuthor()).fetchOne(0, Integer.class)); + } + + protected final void assertCountBooks(int count) { + assertEquals(count, (int) create().selectCount().from(TBook()).fetchOne(0, Integer.class)); + } + @SuppressWarnings("unchecked") protected Sequence SAuthorID() throws IllegalAccessException, NoSuchFieldException { return (Sequence) cSequences().getField("S_AUTHOR_ID").get(cSequences()); diff --git a/jOOQ-test/src/org/jooq/test/_/testcases/CRUDTests.java b/jOOQ-test/src/org/jooq/test/_/testcases/CRUDTests.java index 412df2be0d..7db60880ef 100644 --- a/jOOQ-test/src/org/jooq/test/_/testcases/CRUDTests.java +++ b/jOOQ-test/src/org/jooq/test/_/testcases/CRUDTests.java @@ -290,6 +290,60 @@ extends BaseTest> extends TableReco * Store this record back to the database. *

* Depending on the state of the primary key's or main unique key's value, - * an INSERT or an UPDATE statement is executed. + * an {@link #insert()} or an {@link #update()} statement is executed. *

*

Statement type

*

@@ -126,6 +126,9 @@ public interface UpdatableRecord> extends TableReco * INSERT will be executed. *

Automatic value generation

*

+ * Use {@link #insert()} or {@link #update()} to explicitly force either + * statement type. + *

*

- *

- * This is in fact the same as calling - * store(getTable().getMainKey().getFieldsArray()) * * @return 1 if the record was stored to the database. 0 * if storing was not necessary. * @throws DataAccessException if something went wrong executing the query * @throws DataChangedException If optimistic locking is enabled and the * record has already been changed/deleted in the database + * @see #insert() + * @see #update() */ int store() throws DataAccessException, DataChangedException; + /** + * Store this record back to the database using an INSERT + * statement. + *

+ * This is the same as {@link #store()}, except that an INSERT + * statement (or no statement) will always be executed. + * + * @return 1 if the record was stored to the database. 0 + * if storing was not necessary. + * @throws DataAccessException if something went wrong executing the query + * @see #store() + */ + int insert() throws DataAccessException; + + /** + * Store this record back to the database using an UPDATE + * statement. + *

+ * This is the same as {@link #store()}, except that an UPDATE + * statement (or no statement) will always be executed. + * + * @return 1 if the record was stored to the database. 0 + * if storing was not necessary. + * @throws DataAccessException if something went wrong executing the query + * @throws DataChangedException If optimistic locking is enabled and the + * record has already been changed/deleted in the database + * @see #store() + */ + int update() throws DataAccessException, DataChangedException; + /** * Deletes this record from the database, based on the value of the primary * key or main unique key. diff --git a/jOOQ/src/main/java/org/jooq/impl/UpdatableRecordImpl.java b/jOOQ/src/main/java/org/jooq/impl/UpdatableRecordImpl.java index 5f69ac012c..c8b1a5b5f3 100644 --- a/jOOQ/src/main/java/org/jooq/impl/UpdatableRecordImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/UpdatableRecordImpl.java @@ -144,10 +144,19 @@ public class UpdatableRecordImpl> extends TableReco result = storeInsert(); } - setAllChanged(false); return result; } + @Override + public final int insert() { + return storeInsert(); + } + + @Override + public final int update() { + return storeUpdate(getMainKey().getFieldsArray()); + } + private final int storeInsert() { Executor create = create(); InsertQuery insert = create.insertQuery(getTable()); @@ -184,6 +193,8 @@ public class UpdatableRecordImpl> extends TableReco } } } + + setAllChanged(false); } return result; @@ -218,6 +229,11 @@ public class UpdatableRecordImpl> extends TableReco // [#1596] Check if the record was really changed in the database int result = update.execute(); checkIfChanged(result, version, timestamp); + + if (result > 0) { + setAllChanged(false); + } + return result; }