Observable model

14 views
Skip to first unread message

resend...@gmail.com

unread,
Aug 1, 2016, 3:51:46 PM8/1/16
to jOOQ User Group
Is it possible, via a custom generator strategy or similar, to add custom logic to pojos?

I would like to generate pojos that fire events when properties are changed. I do _not_ want to extend 'Observable'.

Using the old 'PropertyChangeSupport' class as an example...


 public final class MyBean {
     private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);

     public PropertyChangeSupport getChangeSupport() { return pcs; }

     private String value;

     public String getValue() {
         return this.value;
     }

     public void setValue(String newValue) {
         this.pcs.firePropertyChange("value", oldValue, this.oldValue = newValue);
     }

     [...]
 }
 

Lukas Eder

unread,
Aug 2, 2016, 1:38:57 AM8/2/16
to jooq...@googlegroups.com
Hello,

There is the possibility of generating custom code sections in POJOs:

But in your case, that's not going to be sufficient as you want to override setter behaviour. You can still do it, but it's a bit more work. Essentially, you will need to extend the org.jooq.util.JavaGenerator and override the following method:

- org.jooq.util.JavaGenerator.generatePojo(TableDefinition table, JavaWriter out)

Alternatively, you can patch JavaGenerator, of course.

Hope this helps,
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.
For more options, visit https://groups.google.com/d/optout.

resend...@gmail.com

unread,
Aug 2, 2016, 4:36:08 PM8/2/16
to jOOQ User Group
super helpful, thank you
Reply all
Reply to author
Forward
0 new messages