2013/10/17 Marko Topolnik <[email protected]>

> On Thursday, October 17, 2013 11:12:01 AM UTC+2, Lukas Eder wrote:
>>
>>
>>
>> 2013/10/17 Marko Topolnik <[email protected]>
>>
>>
>>>
>>> On Thursday, October 17, 2013 10:59:03 AM UTC+2, Lukas Eder wrote:
>>>>
>>>> Hello,
>>>>
>>>> A similar problem has been reported before:
>>>> https://groups.google.com/**foru**m/#!topic/jooq-user/_cp2-**mrtZ7**
>>>> k/discussion<https://groups.google.com/forum/#!topic/jooq-user/_cp2-mrtZ7k/discussion>
>>>> .
>>>>
>>>> It has lead to this feature requests (among others):
>>>> - 
>>>> https://github.com/jOOQ/jOOQ/**i**ssues/2700<https://github.com/jOOQ/jOOQ/issues/2700>
>>>> - 
>>>> https://github.com/jOOQ/**jOOQ**/issues/2702<https://github.com/jOOQ/jOOQ/issues/2702>
>>>>
>>>
>>> I was quite convinced that I'm not the first one with this issue, but I
>>> unfortunately failed to pinpoint the earlier posts, sorry :)
>>>
>>
>> No worries! I just tend to link to these things to create more cohesion
>> between threads. This helps me find stuff, later on.
>>
>>
>>>
>>>
>>>> In the mean time, your workaround is one way to do this, another would
>>>> be this:
>>>>
>>>>       final Record inputRec = sql.newRecord(USER);
>>>>       inputRec.from(user);
>>>>       for (Field<?> f : inputRec.fields()) {
>>>>           if (inputRec.getValue(f) == null)
>>>>               inputRec.changed(false);
>>>>       }
>>>>       inputRec.store();
>>>>
>>>
>>> Great, I was experimenting with this approach involving changed.
>>> However, I overlooked the store method and used creat.insertInto(...),
>>> which always inserted nulls regardless of their *changed* status.
>>>
>>
>> Yes, if you're into CRUD, jOOQ's UpdatableRecord has a couple of useful
>> methods:
>> http://www.jooq.org/javadoc/**latest/org/jooq/**UpdatableRecord.html<http://www.jooq.org/javadoc/latest/org/jooq/UpdatableRecord.html>
>>
>> The explicit DSL API (e.g. create.insertInto(...) ) does not communicate
>> with UpdatableRecord's changed flags. They're merely used for the insert(),
>> update(), store() methods.
>>
>
> Yes, now I've looked it up and will keep in mind for the future. I
> happened to use the plain Record type for my variable, which is another
> thing that threw me off. So here's your code, corrected for that and for
> the changed call (to benefit any future users seeing this thread):
>
> UpdatableRecord rec = create.newRecord(u);
> rec.from(user);
> for (Field<?> f : rec.fields()) if (rec.getValue(f) == null)
> rec.changed(f, false);
> rec.store();
>

That's a fancy almost-one-liner :-)

I wonder if I should add some more fluency to that API, to be ready for a
Java 8 version of the above:

create.newRecord(u)

      .from(user)

      .eachField((ctx) -> {
         if (ctx.rec().getValue(ctx.field()) == null)
ctx.rec().changed(ctx.field(), false);
      })

      .store();


;-)

-- 
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/groups/opt_out.

Reply via email to