Thanks again Lukas
Well, I explored the matcher option and generated the v1 model with it and
the v3 model with the PrefixingGeneratorStrategy (hard coded prefix for
now) [1].
I'm doing the matcher this way:
MatchersTableType matchersTableType = new MatchersTableType();
MatcherRule versionPrefixer = new MatcherRule().withExpression("v"
+ currentVersion + "_$1");
matchersTableType
.withExpression("^(.*)$")
.withTableClass(versionPrefixer)
.withTableIdentifier(versionPrefixer)
.withRecordClass(versionPrefixer)
.withPojoClass(versionPrefixer)
.withDaoClass(versionPrefixer)
.withInterfaceClass(versionPrefixer)
;
The PrefixingGeneratorStrategy is like this:
public class PrefixingGeneratorStrategy extends DefaultGeneratorStrategy {
@Override
public String getJavaClassName(final Definition definition, final Mode
mode) {
return "v3_" + super.getJavaClassName(definition, mode);
}
@Override
public String getJavaIdentifier(Definition definition) {
return "v3_" + super.getJavaIdentifier(definition);
}
}
It turns out that the matcher option prefixes less stuff than the
PrefixingGeneratorStrategy, notably the keys and sequences aren't prefixed.
So the PrefixingGeneratorStrategy wins the best prefix option award :)
However this one could still be better on 2 points:
1 - prefixing the DefaultCatalog, Keys, Sequences and Tables classes as
well
-- currently only the the Schema is prefixed
=> can it be done somehow?
2 - using the PrefixingGeneratorStrategy with various runtime prefixes
would require to use some global state (static, java properties)
-- this saddens me deeply :( Well, I guess you won't change it soon... But
at least the eternal law of xsd is respected: it always comes back to bit
in the a** (IMHO). Would you choose it (or something similar) again if you
could redo this part? Or would you stick to one language (Java in this
case) and its paradigms (DDD powa)? ^^
Thanks again
++
joseph
[1]
https://github.com/cluelessjoe/jooq-flyway-typesafe-migration/tree/issue2/addPrefixToVersionedModels/migrator/src/main/generated-sources/org/jooq/example/migrator/model
On Wednesday, May 3, 2017 at 10:47:55 AM UTC+2, Lukas Eder wrote:
>
> Hi Joseph,
>
> Of course you could run multiple generations with different prefixes each
> time. Just create a new configuration for each generation.
>
> Please note that all these classes are just XJC-generated classes from the
> code generation configuration XSD:
> https://www.jooq.org/xsd/jooq-codegen-3.9.2.xsd
>
> There's no way to configure a strategy like new
> PrefixGenerator("somePrefix") in XML, so there's also no such way in the
> programmatic configuration. You could work around this issue by passing
> some System.setProperty() or some global variable, or whatever.
>
> Another option would be to use the matcher strategies, where you can
> specify regular expressions. Perhaps that's easier for prefixing class
> names:
>
> https://www.jooq.org/doc/latest/manual/code-generation/codegen-matcherstrategy
>
> I hope this helps,
> Lukas
>
> 2017-05-03 9:33 GMT+02:00 <[email protected] <javascript:>>:
>
>> Hi Lukas
>>
>> Thanks :) This helps... a bit!
>>
>> Indeed, I would like to run multiple generations with different prefix
>> each time.
>>
>> This could be for example something like:
>> Generator.withStrategy(new Strategy().with(new
>> PrefixGenerator("somePrefix"))
>>
>> Is something similar possible? I guess I could use some static field
>> somewhere, but I would be sad to have to do so ;)
>>
>> thanks again
>> joseph
>>
>> On Tuesday, May 2, 2017 at 11:06:03 PM UTC+2, Lukas Eder wrote:
>>>
>>> Hi Joseph,
>>>
>>> The strategy is configured in Generator.withStrategy(new
>>> Strategy().withName("fully.qualfied.class.name"))
>>>
>>> Hope this helps,
>>> Lukas
>>>
>>>
>>> 2017-05-01 22:48 GMT+02:00 <[email protected]>:
>>>
>>>> Hi Lukas
>>>>
>>>> thanks for the answer. Actually I just want to prefix everything with a
>>>> version, so it looks like a perfect fit. I would like to make it from Java
>>>> code, but I didn't manage to set it up, even the JPrefixGeneratorStrategy.
>>>> To provide some context I provided the class I'm using for generation(
>>>> https://github.com/cluelessjoe/jooq-flyway-typesafe-migration/blob/master/migrator/src/test/java/LatestModelGenerator.java).
>>>>
>>>> I tried giving the proper name, through withName, as well as
>>>> withGenerate/withStrategy but nothing was working (or even compiling for
>>>> the last two methods).
>>>>
>>>> How should I configure the JPrefixGeneratorStrategy (or mine) ?
>>>>
>>>> Thanks again
>>>>
>>>> On Monday, May 1, 2017 at 3:51:41 PM UTC+2, Lukas Eder wrote:
>>>>>
>>>>> ... Oh, I'm sorry, actually, the original discussion fits your
>>>>> request, but then the discussion was hi-jacked. So here's my answer:
>>>>>
>>>>> The GeneratorStrategy won't allow you to produce your own Java code.
>>>>> It only specifies what each generated Java object's name should be (e.g.
>>>>> class names, package names, method names, setter names, getter names,
>>>>> attribute names, etc.)
>>>>>
>>>>> If you want to produce your own custom Java code, you have two options:
>>>>>
>>>>> - Override the JavaGenerator and implement your own (parts).
>>>>> - Override the JavaGenerator's custom code section methods:
>>>>>
>>>>> https://www.jooq.org/doc/latest/manual/code-generation/codegen-custom-code
>>>>>
>>>>> Let me know if you need any help with those.
>>>>> Cheers,
>>>>> Lukas
>>>>>
>>>>> 2017-05-01 15:47 GMT+02:00 Lukas Eder <[email protected]>:
>>>>>
>>>>>> Hi Joseph,
>>>>>>
>>>>>> I'll start a new discussion thread for this, as I don't think it's
>>>>>> related to the original discussion.
>>>>>>
>>>>>> Stay tuned
>>>>>>
>>>>>>
>>>>>> 2017-05-01 11:28 GMT+02:00 <[email protected]>:
>>>>>>
>>>>>>> Hi
>>>>>>>
>>>>>>> I'm obviously late to the party, yet I've an issue with the
>>>>>>> generation strategy; I've my own I would like to hook in through Java
>>>>>>> code
>>>>>>> (there
>>>>>>> https://github.com/cluelessjoe/jooq-flyway-typesafe-migration/blob/master/migrator/src/test/java/LatestModelGenerator.java),
>>>>>>>
>>>>>>> but I don't find a way.
>>>>>>>
>>>>>>> How should I proceed?
>>>>>>>
>>>>>>> Thanks in advance
>>>>>>>
>>>>>>> best
>>>>>>> joseph
>>>>>>>
>>>>>>> On Monday, April 8, 2013 at 1:13:18 PM UTC+2, Lukas Eder wrote:
>>>>>>>>
>>>>>>>> 2013/4/8 Durchholz, Joachim <[email protected]>:
>>>>>>>> >> However. Extracting these things takes time.
>>>>>>>> >> And then, concrete use-cases matter, too.
>>>>>>>> >
>>>>>>>> > I couldn't agree less!
>>>>>>>> >
>>>>>>>> >> Lots of ideas, so, yes, keep on coming with suggestions.
>>>>>>>> >
>>>>>>>> > Okay, will do.
>>>>>>>> >
>>>>>>>> >> And contributions, of course! :-)
>>>>>>>> >
>>>>>>>> > Heh. Jooq is already near the top end of the list of projects I'd
>>>>>>>> like to contribute to.
>>>>>>>> > Don't hold your breath tough, that list is crammed.
>>>>>>>>
>>>>>>>> Ideas, feedback and discussion are contribution, too. That's great!
>>>>>>>> So, looking forward to the eventual code contribution! :-)
>>>>>>>>
>>>>>>>> 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.
>>>>>>>
>>>>>>
>>>>>>
>>>>> --
>>>> 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.
>>>>
>>>
>>> --
>> 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.