Right, of course now I can see how that makes sense for database fields. I think because this was mapping multiple tables along with some CASE and computed fields I put an #as() for each field that camel case corresponded to the beans setters. This is the most complicated query I had so I thought I'd try it first with JOOQ. It's overly dynamic and comes through a REST request that allows the REST client to specify what fields they want returned and what criteria they would like to add.
The only problem I have with using a RecordMapper or parsing the ResultSet myself is that I end up having to do double the work -- finding out which fields are present again and how I want those mapped to a bean. That's why I thought it would be nice to have a Converter in the values field instantiations. I could simply iterate through the value fields (or map invocations) and have the setter methods called as they are present. In almost all other cases my usages of JOOQ will be more straight forward. The solution I can up with creates a cached map of all POSSIBLE fields, mapped by their string name. The value is a lambda to set the field. Then I wrap #select() so that each time a field is added (I add them one by one with repeated calls to #select(field)) it is also looked up in the cached map and added (in order) to an array. Them my mapper just iterates through fields and lambdas (sync'd by their position). It's more code than I would like but it works. Thanks! On Tuesday, January 6, 2015 11:04:10 PM UTC-8, Lukas Eder wrote: > > Hello, > > Thank you for your input! > > As you expected, this isn't really a bug but a limitation. I can see your > point and I've registered an issue to improve this for jOOQ 3.6: > https://github.com/jOOQ/jOOQ/issues/3903 > > The main reason why this wasn't implemented this way (and why probably > only few people have brought it up in the past) is because people don't let > the JavaBeans naming conventions leak into their databases, i.e. few people > actually have case-sensitive "firstName" column names in their databases. > What we've observed so far are two conventions in SQL: > > - ALL_UPPER_CASE (most databases) > - PascalCase (T-SQL databases) > > This is why the current behaviour seems suitable enough to map database > conventions to Java. The first column would map to any of these setters: > > - setALL_UPPER_CASE(...) > - ALL_UPPER_CASE(...) > - setAllUpperCase(...) // This matches JavaBeans conventions > - allUpperCase(...) > > Adding support for #3903 certainly doesn't hurt, here. > > If you want to add this sort of behaviour already before jOOQ 3.6, you can > implement your own RecordMapper and RecordMapperProvider to replace / > enhance the current DefaultRecordMapper: > > http://www.jooq.org/doc/latest/manual/sql-execution/fetching/pojos-with-recordmapper-provider/ > > Cheers, > Lukas > > 2015-01-06 23:14 GMT+01:00 Robert DiFalco <[email protected] > <javascript:>>: > >> There seems to be a bug in the field to POJO mapping. Typically, with >> Java Beans, if you have a value named "firstName" it will find the setter >> "setFirstName". Consider JSON parsing libraries like JSON or GSON. >> >> Unfortunately, with JOOQ, it will only look for "setfirstName", >> "setfirstname", or "setFirstname". It might be a limitation instead of a >> bug but it feels like a bug. Personally, I would consider making the first >> match be "set" + name.substring(0,1).toUpper() + name.substring(0, >> name.length). Then all will be well (and as expected). >> >> I'm actually surprised this hasn't been a bigger issue with how mature >> the JOOQ codebase is. Was there a reason for not adopting the same bean >> mapping rules other domains (like JSON) adopt? >> >> Thanks! >> >> -- >> 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] <javascript:>. >> 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.
