Generate custom global artefact

16 views
Skip to first unread message

serge....@gmail.com

unread,
Nov 19, 2017, 12:21:44 PM11/19/17
to jOOQ User Group
Hi everyone,

I'm currently evaluating jOOQ for use with Amazon Redshift. We currently get events in a JSON format and I'm trying to find the best way to map the JSON structure to a specific jOOQ Record. These events have an event_type field that allows me to know which concrete record type to insert in the database.

However, I'd like to avoid a very very big switch statement to make the decision in runtime. Assuming there's no better way, I'd like to generate this switch statement + deserialization logic using jOOQ's capabilities. It seems, though, that I can't generate new classes or global artifacts. Am I missing something or did I hit a limitation?

Thank you,

Lukas Eder

unread,
Nov 20, 2017, 5:07:44 AM11/20/17
to jooq...@googlegroups.com
Hi Serge,

Thanks for your message. That looks like an interesting case for "custom code sections" in the code generator:

I could see a generated static method in the generated Schema class, which does the switch for you. Something along the lines of:

public UpdatableRecord<?> newRecord(Configuration configuration, String json) {
  switch (...) {
    case "type1": 
      UpdatableRecord<?> record = DSL.using(configuration).newRecord(Tables.TYPE1);
      // ...
      return record;
  }
}

Does that help?

Thanks,
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

serge....@gmail.com

unread,
Nov 20, 2017, 5:27:57 AM11/20/17
to jOOQ User Group
Hi!

That seems to do the trick!! Thanks a lot Lukas.

Best,
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages