thank you Lukas,
im currently using a custom GeneratorStrategy.
It seems when i use a custom GeneratorStrategy i can not additionally use the Matchers.
Quote:
- "...Instead of specifying a strategy name, you can also specify a <matchers/> element as explained in the following subsections.."
So its an either or i guess? (either strategy name or matchers)
---
i have tried the matchers out and it was very easy to achieve the result i asked about. Really nice!
.withStrategy(new Strategy()
...
.withMatchers(new Matchers()
.withForeignKeys(
new MatchersForeignKeyType()
.withExpression("^(.*)_(.*?)(Id)?$")
.withPathMethodName(new MatcherRule()
.withExpression("$2")
)
.withPathMethodNameManyToMany(new MatcherRule()
.withExpression("$2")
)
.withPathMethodNameInverse(new MatcherRule()
.withExpression("$2")
)
)
)
)
---
but unfortunately i still need a Custom GeneratorStrategy for creating Getters/Setters correctly.
When i use the default Strategy (Strategy()) instead, then the Getters/Setters look somehow off to me.
For example:
i have following fields in the database:
- clientId
- userId
The code-generator would generate following Getters/Setters for them with the default-settings:
- setUserid / getUserid
- setClientid / getClientid
This seemed strange to me, and i fixed those with a CustomGenerator, so the "Id" stays as it is in the database
(only Uppercasing the first Letter of the fieldname and adding a leading "set" / "get")
- setUserId / getUserId
- setClientId / getClientId
In addtion to that i also have some fields in the database (liquibase) that are completely uppercase:
- CONTEXTS
- LABELS
The code-generator would generate following Getters/Setters for them with the default-settings:
- setContexts / getContexts
- setLabels / getLabels
I also would like to keep the fieldname behind the setter/getter exactly in uppercase like its in the database, only Uppercasing the first Letter of the fieldname
- setCONTEXTS / getCONTEXTS
- setLABELS / getLABELS
i also think somewhere i had problems with using Java-Reflection on the methods/fields and by changing it that way,
this helped me to get java-reflection work.
When i checked the MatcherStrategies i could not find a way to replicate this behavior with the Matchers.
I tried out following which came pretty close, if the "withTransform" would only apply to the Source (before applying the expression/regex on it)
.withFields(
new MatchersFieldType()
.withFieldIdentifier(new MatcherRule()
.withTransform(MatcherTransformType.AS_IS))
.withFieldMember(new MatcherRule()
.withTransform(MatcherTransformType.AS_IS))
.withFieldGetter(new MatcherRule()
.withExpression("$0")
.withTransform(MatcherTransformType.UPPER_FIRST_LETTER))
.withFieldSetter(new MatcherRule()
.withExpression("$0")
.withTransform(MatcherTransformType.UPPER_FIRST_LETTER))
)
---
still a pretty great API here!
i wonder why i need to customize the Getters/Setters so much though.
It seems to me that normally the defaults of jooq should be the best, but i needed to change those (as named for the reasons above)
My CustomGenerator looks like this:
public final class FkGeneratorStrategy extends DefaultGeneratorStrategy {
@Override
public String getJavaSetterName(Definition definition, Mode mode) {
return "set" + definition.getOutputName().substring(0, 1).toUpperCase() + definition.getOutputName().substring(1);
}
@Override
public String getJavaGetterName(Definition definition, Mode mode) {
return "get" + definition.getOutputName().substring(0, 1).toUpperCase() + definition.getOutputName().substring(1);
}
@Override
public String getJavaMethodName(Definition definition, Mode mode) {
return definition.getOutputName();
}
@Override
public String getJavaMemberName(Definition definition, Mode mode) {
return definition.getOutputName();
}
}