2013/10/17 Marko Topolnik <[email protected]> > On Thursday, October 17, 2013 12:41:56 PM UTC+2, Lukas Eder wrote: >> >> >> >> >> 2013/10/17 Marko Topolnik <[email protected]> >> >>> >>> On Thursday, October 17, 2013 11:44:32 AM UTC+2, Lukas Eder wrote: >>>> >>>> >>>> 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/**la****test/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(); >>>> >>>> >>>> ;-) >>>> >>> >>> Oh, yes! To tell you the truth, each void method in your API suprises >>> me, you got me hooked on fluency! >>> >> >> Nice. Feel free to send more feature requests or sample code to the >> group. There's lots of room for improvement. >> >> Btw, if you're hooked, you might appreciate jOOX: >> https://code.google.com/**p/joox <https://code.google.com/p/joox> >> > > I've already taken a look at it and this is my view: in my typical > request-response code the work is split between querying one XML and > building another one. I like to query with XPath and I have had my own JDOM > builder for some time. It's only two screenfuls of implementation code > (single class) and allows very condensed client code. I've got one > incarnation of it on a Github project of > mine<https://github.com/mtopolnik/request-age/blob/master/src/com/ingemark/requestage/script/JdomBuilder.java>. > One nice aspect I have is optimized syntax for simple elements: > builder.textel("el1", > "val1", "el2", "val2", ...). >
Yes, I think that's a good approach. JDOM is quite fast for DOM building. The textel method is indeed quite useful for some quick XML building. I guess it would be a bit more verbose with jOOX, and a lot more verbose with DOM. Cheers Lukas jOOX is much more ambitious and supports XML tree manipulation, a la > jQuery. I'd definitely have it as number one consideration if I had a use > case which called for that. > -- 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.
