I'd like to update the changed fields in a JOOQ record using a POJO as the source. Record.from(Object) is nearly right, but according to the docs
The resulting record will have its internal "changed" flags set to true for all values.
I would like only the fields which have actually changed (as determined by say, Objects.equals(Object, Object)) to have their flags updated.
The two reasons for this are:
The reason for this implementation ...
The resulting record will have its internal "changed" flags set to true for all values.
... is simple: If things weren't implemented this way, there would be no way to enforce an update of a value that hasn't changed. There are some use-cases where this is desireable (e.g. batching, avoiding too many different SQL strings, etc.). The Record.from() method is just consistent with the other Record methods, e.g. Record.set(Field, Object).
You can patch the internal changed flags as such:
// Load all values and mark them all as "changed"
record.from(object);
// Undo the undesired flags
for (int i = 0; i < record.size(); i++)
if (Objects.equals(record.get(i), record.original(i)))
record.changed(i, false);
I've also created a feature request in jOOQ. Perhaps the API could be improved as a lot of people have this requirement: https://github.com/jOOQ/jOOQ/issues/5394
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With