Hey Lukas,

On Sun, May 25, 2014 at 9:57 AM, Lukas Eder <[email protected]> wrote:
> You will find this discussion here inspiring:
> https://groups.google.com/d/msg/jooq-user/8MBETRVrLCM/xPeL-COW26QJ

Thanks for the pointer - that is an interesting discussion.

> Clearly, there is an additional use-case hidden in there somewhere that
> should be better supported by the jOOQ API, i.e. the distinction of the two
> possible NULL semantics:
>
> 1. Java null = not initialised = SQL "don't touch" = DEFAULT at INSERT,
> unchanged at UPDATE
> 2. Java null = explicit null = SQL NULL both at INSERT and at UPDATE
>
> The problem in differentiating such semantics mostly originates from
> transferring DTO / POJO content into an UpdatableRecord, prior to storage.
> jOOQ applies semantics 1) when a value was never explicitly set through
> UpdatableRecord.setValue(), but semantics 2) when it was explicitly set to
> NULL through UpdatableRecord.setValue(). Your workaround using the changed
> flag enforces semantics 1)
>
> Another idea was to check for nullability in Field metadata. If a Field is
> NOT NULL, then the semantics 2) never makes sense, so people have suggested
> to apply semantics 1), then. To me, that seems a bit too clever.
>
> So far, I think your workaround is really the best solution to this problem,
> right now...


I'd like to keep on using the regular fluent API - I'm not a great fan
of the DTO/POJO binding facilities. So because of this, I was
wondering if you could augment the the set(Field<T> field, T value)
methods on the InsertSetStep fluent API to do something like
setIfNotNull(Field<T> field, T value)? Or you could put the
ifNotNull() on the InsertSetMoreStep if that keeps the API cleaner. Or
you could stick a flag on the entire statement builder instance to get
it to ignore all null values.

My point is that JOOQ shouldn't need to be too clever about devising a
heuristic (at least in the case of the fluent API) - it just needs to
allow an app to say "on update, please ignore these specific fields if
the Java value is null".

Cheers,

Ben

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to