[jOOQ/jOOQ#17243] UpdatableRecord.delete() should reset all

Record.original() values
This commit is contained in:
Lukas Eder 2024-09-13 17:54:59 +02:00
parent 6294085110
commit c8c567348a
3 changed files with 66 additions and 6 deletions

View File

@ -255,6 +255,16 @@ public interface UpdatableRecord<R extends UpdatableRecord<R>> extends TableReco
* or inserted with default values (<code>INSERT</code>).
* <p>
* This is the same as calling <code>record.store(record.fields())</code>
* <h5>Effects on this record</h5>
* <p>
* After a successful {@link #store()} operation, this record will have:
* <ul>
* <li>Its {@link #valuesRow()} unchanged</li>
* <li>Its {@link #original()} values set to the same values as
* {@link #valuesRow()}.</li>
* <li>Its {@link #touched()} flags set to <code>false</code></li>
* <li>Its {@link #modified()} flags set to <code>false</code></li>
* </ul>
*
* @return <code>1</code> if the record was stored to the database. <code>0
* </code> if storing was not necessary.
@ -312,6 +322,15 @@ public interface UpdatableRecord<R extends UpdatableRecord<R>> extends TableReco
* {@link RecordDirtyTracking#TOUCHED}
* <p>
* This is the same as calling <code>record.insert(record.fields())</code>
* <h5>Effects on this record</h5>
* <p>
* After a successful {@link #insert()} operation, this record will have:
* <ul>
* <li>Its {@link #valuesRow()} unchanged</li>
* <li>Its {@link #original()} values set to the same values as {@link #valuesRow()}.</li>
* <li>Its {@link #touched()} flags set to <code>false</code></li>
* <li>Its {@link #modified()} flags set to <code>false</code></li>
* </ul>
*
* @return <code>1</code> if the record was stored to the database. <code>0
* </code> if storing was not necessary and
@ -365,6 +384,16 @@ public interface UpdatableRecord<R extends UpdatableRecord<R>> extends TableReco
* {@link Settings#getUpdateUnchangedRecords()}.
* <p>
* This is the same as calling <code>record.update(record.fields())</code>
* <h5>Effects on this record</h5>
* <p>
* After a successful {@link #update()} operation, this record will have:
* <ul>
* <li>Its {@link #valuesRow()} unchanged</li>
* <li>Its {@link #original()} values set to the same values as
* {@link #valuesRow()}.</li>
* <li>Its {@link #touched()} flags set to <code>false</code></li>
* <li>Its {@link #modified()} flags set to <code>false</code></li>
* </ul>
*
* @return <code>1</code> if the record was stored to the database. <code>0
* </code> if storing was not necessary.
@ -427,6 +456,16 @@ public interface UpdatableRecord<R extends UpdatableRecord<R>> extends TableReco
* {@link RecordDirtyTracking#TOUCHED}.
* <p>
* This is the same as calling <code>record.merge(record.fields())</code>
* <h5>Effects on this record</h5>
* <p>
* After a successful {@link #merge()} operation, this record will have:
* <ul>
* <li>Its {@link #valuesRow()} unchanged</li>
* <li>Its {@link #original()} values set to the same values as
* {@link #valuesRow()}.</li>
* <li>Its {@link #touched()} flags set to <code>false</code></li>
* <li>Its {@link #modified()} flags set to <code>false</code></li>
* </ul>
*
* @return <code>1</code> if the record was merged to the database. <code>0
* </code> if merging was not necessary.
@ -498,12 +537,25 @@ public interface UpdatableRecord<R extends UpdatableRecord<R>> extends TableReco
* <p>
* See {@link SelectQuery#setForUpdate(boolean)} for more details</li>
* </ul>
* <h5>Effects on this record</h5>
* <p>
* After a successful {@link #delete()} operation, this record will have:
* <ul>
* <li>Its {@link #valuesRow()} unchanged</li>
* <li>Its {@link #original()} values reset to <code>null</code></li>
* <li>Its {@link #touched()} flags set to <code>true</code></li>
* <li>Its {@link #modified()} flags set to <code>true</code></li>
* </ul>
* <h5>Statement examples</h5>
* <p>
* The executed statement is <pre><code>
* The executed statement is
*
* <pre>
* <code>
* DELETE FROM [table]
* WHERE [key fields = key values]
* AND [version/timestamp fields = version/timestamp values]</code></pre>
* AND [version/timestamp fields = version/timestamp values]</code>
* </pre>
* <p>
* This is in fact the same as calling
* <code>delete(getTable().getPrimaryKey().getFieldsArray())</code>
@ -608,6 +660,15 @@ public interface UpdatableRecord<R extends UpdatableRecord<R>> extends TableReco
* Duplicate this record (in memory) and reset all fields from the primary
* key or main unique key, such that a subsequent call to {@link #store()}
* will result in an <code>INSERT</code> statement.
* <h5>Effects on this record</h5>
* <p>
* After a {@link #copy()} operation, the resulting record will have:
* <ul>
* <li>Its {@link #valuesRow()} just like the source record</li>
* <li>Its {@link #original()} values set <code>null</code>.</li>
* <li>Its {@link #touched()} flags set to <code>true</code></li>
* <li>Its {@link #modified()} flags set to <code>false</code></li>
* </ul>
*
* @return A new record, distinct from <code>this</code> record.
*/

View File

@ -520,9 +520,8 @@ implements
// [#1995] If a value is meant to be "unchanged", the "original" should
// match the supposedly "unchanged" value.
if (!c) {
if (!c)
System.arraycopy(values, 0, originals, 0, values.length);
}
}
@Override

View File

@ -59,14 +59,13 @@ import static org.jooq.impl.RecordDelegate.RecordLifecycleType.REFRESH;
import static org.jooq.impl.RecordDelegate.RecordLifecycleType.STORE;
import static org.jooq.impl.RecordDelegate.RecordLifecycleType.UPDATE;
import static org.jooq.impl.Tools.EMPTY_FIELD;
import static org.jooq.impl.Tools.EMPTY_TABLE_FIELD;
import static org.jooq.impl.Tools.recordDirtyTrackingPredicate;
import static org.jooq.impl.Tools.settings;
import java.math.BigInteger;
import java.sql.Timestamp;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@ -423,6 +422,7 @@ public class UpdatableRecordImpl<R extends UpdatableRecord<R>> extends TableReco
// be executed and the record should be recreated
finally {
touched(true);
asList(originals).replaceAll(e -> null);
fetched = false;
}
}