A way to add "extends" to pojos in generator

566 views
Skip to first unread message

Agharta agharta

unread,
Mar 19, 2012, 9:51:34 AM3/19/12
to jooq...@googlegroups.com
Hi Mr Lukas Eder,

Could i tell you if there is a way to pass a "extends" code to generated pojos into code generator??

An example: OpenSwing project requires that the user mapped objects int its components extends the class org.openswing.swing.message.receive.java.ValueObjectImpl

For example, if i have a jooq generated pojo, to make it compatible with OpenSwing i need to add extends org.openswing.swing.message.receive.java.ValueObjectImpl in class definition, as above:


package dbLayer.db.tables.pojos;

import org.openswing.swing.message.receive.java.ValueObjectImpl;

@javax.annotation.Generated(value    = {"http://www.jooq.org", "2.0.5"},
                            comments = "This class is generated by jOOQ")
public class Vaccine  extends ValueObjectImpl implements java.io.Serializable {

    private static final long serialVersionUID = 946855733;

    private java.lang.Integer id;
    private java.lang.String  description;
    private java.lang.String  dosage;
    private java.lang.String  givingPeriod;
    private java.lang.Integer illnessId;
    private java.lang.String  note;

bla bla bla
.......


I want ask you: is possible to add a tag in code generator xml to provide an extends class to include in pojo??

Example:
<generate>
......
  <pojos>true</pojos>
<pojos-extends-class>org.openswing.swing.message.receive.java.ValueObjectImpl</pojos-extends-class>
......
</generate>


Better way if adding the complete <pojo-extends-class> as xx.yy.ZZ, the generator calls the import directive in java class and simply use ZZ in extends definition, as written in code example.

Sorry for my bad english, hope i was clear, if not tell me your trouble.

Thank you again for your fantastic work!

Best regards,

Agharta

Lukas Eder

unread,
Mar 19, 2012, 10:11:10 AM3/19/12
to jooq...@googlegroups.com
Hello Agharta,

> Could i tell you if there is a way to pass a "extends" code to generated
> pojos into code generator??

This makes perfect sense and it has been suggested before by Sander:
https://groups.google.com/d/topic/jooq-user/YuTp9-5K9fs/discussion

I'll file this as feature request #1243:
https://sourceforge.net/apps/trac/jooq/ticket/1243

I'm not quite sure about the implementation details, though. Ideally,
jOOQ-codegen would support velocity or XSLT or any other "scripting"
language for arbitrary source code generation, the way minute project
does already:
http://minuteproject.wikispaces.com/JOOQ

That would then allow for much more flexible generated artefacts. But
extending base classes in POJOs is quite a common use case, so I might
add it as you suggested in jooq-codegen.

Cheers
Lukas

> Better way if adding the complete <pojo-extends-class> as xx.yy.ZZ, the
> generator calls the import directive in java class and simply use ZZ in
> extends definition, as written in code example.

I prefer not to import classes in generated artefacts. The risk of
collisions is too high.

Cheers
Lukas

Agharta agharta

unread,
Mar 19, 2012, 10:37:02 AM3/19/12
to jooq...@googlegroups.com
Hi,
Thank you for quicky reply!!!!

I've not seen the ticket #1243, sorry for duplicate request.

Your collision problem is right, full class declare is the better way.

Minute project is the best way to implement this feature. As "extends" feature, "implements" feature could be done in same way. Your decision. In any case you are right, "extends" is the common used feature.

Thank you again for you patience,

Cheers,

   Agharta

Lukas Eder

unread,
Mar 19, 2012, 10:44:36 AM3/19/12
to jooq...@googlegroups.com
Hello again,

> I've not seen the ticket #1243, sorry for duplicate request.

I've just created that ticket after your e-mail :-)

> Minute project is the best way to implement this feature. As "extends"
> feature, "implements" feature could be done in same way. Your decision. In
> any case you are right, "extends" is the common used feature.

#1243 will somehow support "extends" and "implements". In that
previous discussion with Sander, the point was that many tables have
common columns, such as CREATED_BY, CREATED_AT, MODIFIED_BY,
MODIFIED_AT, etc. Allowing for implementing interfaces might help
abstracting these fields to a higher level:

--------------------------------------------------------
public interface DatabaseObject {
Long getId();
String getCreatedBy();
Timestamp getCreatedAt();
String getModifiedBy();
Timestamp getModifiedAt();
}
--------------------------------------------------------

With an API like this, generic DAO classes can be written easily. So
it makes perfect sense for jOOQ-generated POJOs to implement custom
interfaces, as well as to extend custom classes.

Cheers
Lukas

Lukas Eder

unread,
Mar 21, 2012, 4:54:47 PM3/21/12
to jooq...@googlegroups.com
Hi Agharta,

Ticket #1243 is implemented on SVN trunk and will be included in the
next snapshots:
https://sourceforge.net/apps/trac/jooq/ticket/1243

I decided to add this feature to the GeneratorStrategy, rather than
adding more XML configuration elements. I think this is the best
place, as people wanting to customise artefacts on that level will
probably have a custom GeneratorStrategy anyway (e.g. to add a "Pojo"
suffix to POJO classes).

This feature will be documented when I release jOOQ 2.2.0

Cheers
Lukas

Agharta agharta

unread,
Mar 22, 2012, 4:11:34 AM3/22/12
to jooq...@googlegroups.com
Yeah!

I've see the getJavaClassExtends and the getJavaClassImplements methods  in the DefaultGeneratorStrategy.java, great!

In this way you have a single access point to customize the generated code, you're right, as always!!!


Thank you again,

Best Regards,

          Agharta

Lukas Eder

unread,
Mar 22, 2012, 4:42:02 AM3/22/12
to jooq...@googlegroups.com
Thanks for the feedback

Cheers
Lukas

2012/3/22 Agharta agharta <agha...@gmail.com>:

Reply all
Reply to author
Forward
0 new messages