Hi Robert,

Thanks for this feedback (and sorry for the delay). I can see how this
would be very useful, indeed. So, a simpler version of your code would do
the same via reflection, when calling

    private static UserRecord newRecord(UserBean bean) {
        UserRecord record = new UserRecord();
        record.from(bean);
        return record;
    }

But this semantics cannot be hard-wired into jOOQ because it's not the only
valid / useful use of Optional. For instance, your logic won't be able to
model the presence of a JSON "null" value. As always with the "null" /
Optional discussion, we'll wind up with several useful semantics for
"absent values":

- NULL (the actual SQL NULL / UNKNOWN value)
- DEFAULT (the actual SQL DEFAULT value)
- "IGNORE" (the semantics that you have implemented, or that jOOQ models
via Record.changed())

I suspect we better wait with adding new features around Optional in this
area...

Cheers,
Lukas

2015-09-16 16:28 GMT+02:00 Robert DiFalco <[email protected]>:

> For me, my beans are parsed from JSON and allow partial updates. So, for
> example, I can PUT /user/1 {"emailAddress": "[email protected]"} in order to
> only update the email_address. So I write my bean to record code like this:
>
>     private static UserRecord newRecord(UserBean bean) {
>         UserRecord record = new UserRecord();
>         bean.getFirstName().ifPresent(record::setFirstName);
>         bean.getLastName().ifPresent(record::setLastName);
>         bean.getEmailAddress().ifPresent(record::setEmailAddress);
>         bean.getPhoneNumberE164().ifPresent(record::setPhoneNumberE164);
>         return record;
>     }
>
> So if a getter uses Optional I suppose I would want it to work like this.
> Of course other people don't see it as good practice to have a getter
> return an Optional at all. But for my use case it works well to tell the
> difference between a specified value and an absent value that has been
> parsed from JSON.
>
> R.
>
>
>
> On Wed, Sep 16, 2015 at 5:31 AM, Lukas Eder <[email protected]> wrote:
>
>>
>>
>> 2015-09-15 17:52 GMT+02:00 Robert DiFalco <[email protected]>:
>>
>>> Thanks Lukas, unfortunately it does not handle Optional<T>.
>>>
>>
>> Hmm, good point. We should certainly add Optional support to
>> org.jooq.tools.Convert (https://github.com/jOOQ/jOOQ/issues/4565), and
>> perhaps to other data type conversion methods.
>>
>> Would you mind sharing a little more insight into your use-case? What is
>> your current usage of Optional and what are your expectations towards jOOQ
>> in this area?
>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "jOOQ User Group" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/jooq-user/_8KYcum-8H4/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> 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.
>

-- 
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