private final int store0(Field<?>[] storeFields) { TableField<R, ?>[] keys = getPrimaryKey().getFieldsArray(); boolean executeUpdate = false; // [#2764] If primary key values are allowed to be changed, // inserting is only possible without prior loading of pk values if (updatablePrimaryKeys(settings(this))) { executeUpdate = fetched; } else { for (TableField<R, ?> field : keys) { // If any primary key value is null or changed if (changed(field) || // [#3237] or if a NOT NULL primary key value is null, then execute an INSERT (field.getDataType().nullable() == false && get(field) == null)) { executeUpdate = false; break; } // Otherwise, updates are possible executeUpdate = true; } } int result = 0; if (executeUpdate) { result = storeUpdate(storeFields, keys); } else { result = storeInsert(storeFields); } return result; }
private final int delete0() { TableField<R, ?>[] keys = getPrimaryKey().getFieldsArray(); try { DeleteQuery<R> delete1 = create().deleteQuery(getTable()); Utils.addConditions(delete1, this, keys); if (isExecuteWithOptimisticLocking()) { // [#1596] Add additional conditions for version and/or timestamp columns if (isTimestampOrVersionAvailable()) { addConditionForVersionAndTimestamp(delete1); } // [#1547] Try fetching the Record again first, and compare this // Record's original values with the ones in the database else { checkIfChanged(keys); } } int result = delete1.execute(); checkIfChanged(result, null, null); return result; } // [#673] If store() is called after delete(), a new INSERT should // be executed and the record should be recreated finally { changed(true); } }
private final int delete0() { TableField<R, ?>[] keys = getPrimaryKey().getFieldsArray(); try { DeleteQuery<R> delete1 = create().deleteQuery(getTable()); Tools.addConditions(delete1, this, keys); if (isExecuteWithOptimisticLocking()) { // [#1596] Add additional conditions for version and/or timestamp columns if (isTimestampOrVersionAvailable()) { addConditionForVersionAndTimestamp(delete1); } // [#1547] Try fetching the Record again first, and compare this // Record's original values with the ones in the database // [#5384] Do this only if the exclusion flag for unversioned records is off else if (isExecuteWithOptimisticLockingIncludeUnversioned()) { checkIfChanged(keys); } } int result = delete1.execute(); checkIfChanged(result, null, null); return result; } // [#673] [#3363] If store() is called after delete(), a new INSERT should // be executed and the record should be recreated finally { changed(true); fetched = false; } }
private final int storeUpdate0(TableField<R, ?>[] keys) { UpdateQuery<R> update = create().updateQuery(getTable()); addChangedValues(update); Utils.addConditions(update, this, keys); // Don't store records if no value was set by client code if (!update.isExecutable()) return 0; // [#1596] Set timestamp and/or version columns to appropriate values BigInteger version = addRecordVersion(update); Timestamp timestamp = addRecordTimestamp(update); if (isExecuteWithOptimisticLocking()) { // [#1596] Add additional conditions for version and/or timestamp columns if (isTimestampOrVersionAvailable()) { addConditionForVersionAndTimestamp(update); } // [#1547] Try fetching the Record again first, and compare this // Record's original values with the ones in the database else { checkIfChanged(keys); } } // [#1596] Check if the record was really changed in the database int result = update.execute(); checkIfChanged(result, version, timestamp); if (result > 0) { changed(false); } return result; }
changed(storeField, false);