Hi Ben, 2014-05-26 11:38 GMT+02:00 Ben Hood <[email protected]>:
> > 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 intuition tells me that this would quickly evolve into something like setIfNotNull(...), setIfNotEmpty(...), setIfNotBlank(...), setIfNull(...), setIfGtZero(...) And what about the equivalent counterpart in the values() clause? valuesIfNotNull(...) What about fluent predicate building? Condition.andIfNotNull(something, Condition) :-) On a more serious note, we're going to be evaluating the use of some more functional elements in the SQL DSL that will allow for generalising your idea: https://github.com/jOOQ/jOOQ/issues/3258 Maybe, there is room for a more general setIf(Predicate, ...) API, but I still feel that these kinds of additions will be a huge overkill, if we want to cover all use-cases for the entire DSL. Note that you can always just keep a reference to the InsertSetMoreStep, and write a couple of if-else statements. Another way forward here would then be to use the model API through DSLContext.updateQuery(); http://www.jooq.org/javadoc/latest/org/jooq/DSLContext.html#insertQuery(org.jooq.Table) 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". Yes, that use-case will be covered by this Setting here: https://github.com/jOOQ/jOOQ/issues/2704 Although, only for UpdatableRecords. There is not that much point in saying: UPDATE table SET column1 = 1, column2 = NULL, column3 = 3 OH AND BY THE WAY I DIDNT MEAN THE NULL PARTS; ... because 1) simply don't set the NULL values, 2) what if something *evaluates* to NULL? UPDATE table SET column1 = 1, column2 = CASE WHEN 1 = 1 THEN 1 ELSE NULL END, column3 = 3 OH AND BY THE WAY I DIDNT MEAN THE NULL PARTS; Cheers, Lukas -- 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.
