names for generated pojo getter/setter

175 views
Skip to first unread message

tod...@googlemail.com

unread,
Oct 1, 2020, 8:52:35 AM10/1/20
to jOOQ User Group

In my DB (SQL server) there are column names in camelCase. For this I would like to generate pojos for which
a) the field names correspond 1: 1 to the camelCase column names
b) the getter / setter according to the scheme:
[get | set] + column names in Pascal Case, i.e. with first char uppercase while the rest of the name should remain the same like the column name.
I guess that's one of the common requirements and the standard case for naming getter / setter after the attribute name.

Example:
Column: activeRevision
getter getActiveRevision
setter: setActiveRevision

The field names of the POJO attributes match with the following strategy/matchers
<fieldMember>
<transform> AS_IS </transform>
<expression> $ 0 </expression>
</fieldMember>


But I can't get the names of the getter / setters:

<fieldGetter>
<transform> AS_IS </transform>
<expression> get $ 0 </expression>
</fieldGetter>

leads to getactiveRevision

<fieldGetter>
<transform> CAMEL </transform>
<expression> $ 0 </expression>
</fieldGetter>

leads to activerevision (where is the UPPER cases 'R' of revision?)

<fieldGetter>
<transform> CAMEL </transform>
<expression> get $ 0 </expression>
</fieldGetter>

leads to getactiverevision

How can I achieve that getter / setter getActiveRevision and setActiveRevision are generated for a column activeRevision? Do I really have to write a custom generator?

Seems to be, that this issue is open since 2013 ?

kind regards
Dominik

tod...@googlemail.com

unread,
Oct 1, 2020, 5:44:50 PM10/1/20
to jOOQ User Group
found the solution by applying 2 mandatory options
 
<javaBeansGettersAndSetters>true</javaBeansGettersAndSetters>
plus
<fieldMember>
    <transform>AS_IS</transform>
    <expression>$0</expression>
</fieldMember>
leads to correctly cased method names for getter/setter.
The first one seems to be the feature toggle mentioned in https://github.com/jOOQ/jOOQ/issues/5354 while the second part provide the basis by adjust the java member name itself.
If one part is missing, the getter/setter are not correctly cased.
Due to such named/cased getter/setter seems to be wide commonly used, this may an additional example for the already extensive documentation.

Lukas Eder

unread,
Oct 5, 2020, 6:58:28 AM10/5/20
to jOOQ User Group
Hi Dominik,

Thanks for your feedback. Yes, we can do better in this area. The most recent and relevant issue is this one: https://github.com/jOOQ/jOOQ/issues/10574. We should offer the expected behaviour out of the box, because the PascalCase or camelCase naming conventions are very popular in SQL Server (unlike e.g. Oracle, PostgreSQL, where snake_case is usually preferred, and for which jOOQ's code generator is optimised).

Issue #10574 aims at fixing this, rather than documenting the status quo.

Thanks,
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 jooq-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jooq-user/36ec744f-2449-455e-bdd7-0b7bab9ea3edn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages