So my first attempt was to create my own GeneratorStrategy and overwrite 

   - DefaultGeneratorStrategy.getJavaClassExtends(Definition, Mode)  (org.
   jooq.util) 


but for some reason this does not get called for DAOs. Even if this would 
have been possible, because setConfiguration is final, I wouldn't be able 
to overwrite and annotate the method. I agree it would have been the best 
to annotate the constructor, but there is no method in the JavaGenerator 
that I can overwrite. I've found 

if (generateSpringAnnotations())
            out.println("@%s", 
out.ref("org.springframework.stereotype.Repository"));

which adds an annotation to the constructor. Maybe this can be rewritten 
and extracted into a protected method writeConstructorAnnotations or 
something? I could then overwrite that method and add my annotations to 
inject the configuration via constructor so there is no need to remove the 
final keyword from setConfiguration. 

Great (frame) work btw!


Am Montag, 26. Oktober 2015 16:07:27 UTC+1 schrieb Lukas Eder:
>
> I'm not sure how Guice works in detail, but could you, perhaps, inject the 
> configuration via the constructor instead?
>
> Note that we've had a lot of feedback about "final" on methods in DAOImpl. 
> It appears that our "best practice" of closing our implementation from the 
> outside is mostly criticised in this context, where - apparently - we did 
> something wrong in our design of this particular class. I suspect that for 
> the time being, it may be useful for users to be able to override behaviour 
> in their implementations, even if we prefer discussing things to come to a 
> better API.
>
> Thus, I've created this feature request for jOOQ 3.8:
> https://github.com/jOOQ/jOOQ/issues/4696
>
> Best Regards,
> Lukas
>
> 2015-10-22 11:41 GMT+02:00 <[email protected] <javascript:>>:
>
>> I don't know if this helps or if it's a best practice, but I extended the 
>> JavaGenerator to inject the Configuration. Sadly setConfiguration in 
>> DaoImpl is final so I had to create a new method for all DAOs. Here is the 
>> Generator-Class:
>>
>> public class InjectConfigurationGenerator extends JavaGenerator {
>>
>>     @Override
>>     protected void generateDaoClassFooter(TableDefinition table, 
>> JavaWriter out) {
>>         super.generateDaoClassFooter(table, out);
>>         out.tab(1).println("@com.google.inject.Inject");
>>         out.tab(1).println("public void injectConfiguration(Configuration 
>> configuration) {");
>>             out.tab(2).println("super.setConfiguration(configuration);");
>>         out.tab(1).println("}");
>>     }
>>
>>     @Override
>>     protected void printClassAnnotations(JavaWriter out, SchemaDefinition 
>> schema) {
>>         super.printClassAnnotations(out, schema);
>>         if(out.file().getName().contains("Dao")){
>>             out.println("@%s", "com.google.inject.Singleton");
>>         }
>>     }
>>
>> }
>>
>> Has anyone a better idea how to implement this properly?
>>
>> Am Mittwoch, 14. Oktober 2015 17:22:52 UTC+2 schrieb Lukas Eder:
>>>
>>> Hi Sachin,
>>>
>>> Well, yes you can do that. The generated DAO just links the generated 
>>> Table to the generated POJO type, and adds some convenience methods for 
>>> fetching.
>>>
>>> What is the concern you are having? I mean, why did you think there 
>>> might be a risk in doing so?
>>>
>>> Cheers,
>>> Lukas
>>>
>>> 2015-10-12 18:26 GMT+02:00 <[email protected]>:
>>>
>>>> Hi Lukas,
>>>>
>>>> My query is, can I directly use the generated DAO in production 
>>>> environment.
>>>>
>>>> Thanks,
>>>> Sachin
>>>>
>>>> --
>>>> 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.

Reply via email to