Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not update fields that haven't changed #227

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Do not update fields that haven't changed
Which at this point means the primary key fields. In the future, one may have a logic to detect actual changes and create records where the Pojo fields that haven't changed are not set.

This may be very useful to support MySQL/MariaDB `TIMESTAMP` fields with an `ON UPDATE CURRENT_TIMESTAMP()` feature, which are currently being overwritten by the old value in the POJO and there for are broken with vertx-jooq.
  • Loading branch information
guss77 authored Jan 11, 2024
commit 97517204ccb4584266a3356ebfe66ebf8973510c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public EXECUTE update(P object){
where = where.and(((TableField<R,Object>)tableField).eq(rec.get(tableField)));
}
Map<String, Object> valuesToUpdate =
Arrays.stream(rec.fields())
Arrays.stream(rec.fields()).filter(f -> rec.changed(f))
.collect(HashMap::new, (m, f) -> m.put(f.getName(), f.getValue(rec)), HashMap::putAll);
return dslContext
.update(getTable())
Expand Down