Hi Josh,
2014-09-08 2:21 GMT+02:00 Josh Padnick <[email protected]>:
> No problem at all :) It is nice to know Google Groups isn't accepting
> posts intermittently, and what actually happened. Regarding your original
> question...
>
>>
>> - I hadn't considered writing a custom generator. The only snag here
>> is that we add annotations to certain methods depending on how we want
>> these POJOs concerted to JSON. Will look into this; a cool idea toward
>> automating!
>>
>> *Can you show a couple of examples? Maybe, we'll be able to factor out a
> new feature request. *
>
> So, we're using EmberJS on the frontend, and Postgres on the backend.
> Therefore, a single row of data makes a journey from "row in table" to
> "POJO" to "JSON" and back in reverse when we get data from our front-end.
>
> jOOQ gets us from "row in table" to POJO using the awesome into() method.
> We don't even overwrite the default behavior here, and for POJOs with
> complex relationships, we just manually read the select results "into" the
> appropriate POJO and then manually assemble the POJO. Maybe this could be
> more automated, but it's nice to have explicit code about how our POJOs are
> constructed.
>
> So, in the POJOs, we do things like the following:
>
> *NotifyEvent.java*
>
> // We start by inheriting from the auto-generated POJO
> public class NotifyEvent extends db.jooq.generated...tables.pojos.
> NotifyEvent {
>
> private Integer notifyEventId;
> private Integer notifyConversationId;
>
> // This it the code that jOOQ auto-generates, but Ember Data in
> EmberJS will need our JSON to return a property named // "id", so we
> use Jackson JSON Annotations so that Json.toJson( thisPojo ) will
> automatically produce this.
> // Note that "Json.toJson" is specific to Play Framework, but it is
> just a util method that wraps native Jackson
> // functionality
> @JsonProperty("id")
> public java.lang.Integer getNotifyEventId() {
> return this.notifyEventId;
> }
>
> // Likewise, when Ember sends us data, we need to tell our POJO that
> "id" in the JSON is really this property
> @JsonProperty("id")
> public void setNotifyEventId(java.lang.Integer notifyEventId) {
> this.notifyEventId = notifyEventId;
> }
>
> // To handle foreign key relationships, sometimes we want to embed
> the full JSON of the related object,
> // but sometimes (like in this case), we just want to report the id.
> This automates that, too.
> @JsonProperty("notifyConversation")
> public java.lang.Integer getNotifyConversationId() {
> return this.notifyConversationId;
> }
>
>
> @JsonProperty("notifyConversation")
> public void setNotifyConversationId(java.lang.Integer
> notifyConversationId) {
> this.notifyConversationId = notifyConversationId;
> }
>
> So, in an ideal world, jOOQ's auto-generator could let us:
>
> - Explicitly handle inheritance relationships in the POJOs that are
> generated, perhaps with some kind of separate XML file (do you see this as
> viable today by overriding the generator behavior?)
>
>
> - Explicitly declare annotations, perhaps in a separate XML file
>
> Then we could have jOOQ read our SQL, read our XML annotation
> declarations, and read our XML inheritance declarations and then just
> auto-generate everything.
>
If I understood you correctly, this should be quite easy to do already
today by extending the JavaGenerator from jooq-codegen. You could override
org.jooq.util.JavaGenerator.generatePojo(TableDefinition table) and call
the super method (which generates db.jooq.generated...NotifyEvent) before
you generate your own subtype (NotifyEvent).
Since you're choosing extension, you'll have full control over the contents
of your own subtype. Also, such a solution would give you complete liberty
with respect to how you'd like to structure and interpret that XML file.
>
>
> Hope that answers your question,
>
Yep. :-)
I think this is a solution quite tightly coupled to your requirements, so
I'm not sure if this could go into jOOQ at the current stage. But probably,
with what we have today and a bit of extension code at your side, you can
already achieve that automation.
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.