Fetching the mapped schema and table name at runtime

26 views
Skip to first unread message

Chris Conroy

unread,
Mar 20, 2017, 7:58:39 PM3/20/17
to jOOQ User Group

I am using jOOQ’s awesome runtime schema mapping feature, and I have a use case where I need to drop into raw SQL to hit the MySQL INFORMATION_SCHEMA table on a runtime-mapped table. I don’t see a way in the API to query the actual schema/table name for a given table. Any chance I’m missing something in the API here? I can temporarily workaround by pattern matching on the generated sql from context.selectFrom(table).getQuery().getSQL(); but that’s very brittle!


Lukas Eder

unread,
Mar 21, 2017, 4:43:16 AM3/21/17
to jooq...@googlegroups.com
Hi Chris,

Thanks for your message. Let me see if I correctly understand this: You're using the runtime schema / table mapping and you'd like to check what your table X is being mapped to by some configuration? E.g. along the lines of:

Table<?> unmapped = ...
Table<?> mapped = configuration.map(table);
assertEquals("some_mapped_name", mapped.getName());

jOOQ's internals use the Tools.getMappedTable() method, which essentially just delegates to configuration.schemaMapping().map(table). The SchemaMapping type is deprecated, because it shouldn't be public (but you could still use it as a workaround).

Another workaround that would go in the direction of what you suggested (but is a bit more concise) would be to use DSLContext.render(table). This would generate the SQL only for the table expression, without needing to wrap it in a query. But you'll still get a string, rather than an org.jooq.Table reference.

If that's what you had in mind, great idea! There should be a public Configuration.map(Schema) or map(Table), etc. method (or similar). I've registered a feature request for this:

Cheers,
Lukas

2017-03-21 0:58 GMT+01:00 'Chris Conroy' via jOOQ User Group <jooq...@googlegroups.com>:

I am using jOOQ’s awesome runtime schema mapping feature, and I have a use case where I need to drop into raw SQL to hit the MySQL INFORMATION_SCHEMA table on a runtime-mapped table. I don’t see a way in the API to query the actual schema/table name for a given table. Any chance I’m missing something in the API here? I can temporarily workaround by pattern matching on the generated sql from context.selectFrom(table).getQuery().getSQL(); but that’s very brittle!


--
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.

Chris Conroy

unread,
Mar 21, 2017, 1:29:09 PM3/21/17
to jooq...@googlegroups.com

DSLContext.render(table) works great. Thanks!

--
You received this message because you are subscribed to a topic in the Google Groups "jOOQ User Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jooq-user/ryr-VoiztEc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jooq-user+unsubscribe@googlegroups.com.

Lukas Eder

unread,
Apr 25, 2017, 6:05:15 AM4/25/17
to jOOQ User Group
For the record, issue #5987 is a duplicate of https://github.com/jOOQ/jOOQ/issues/2203, which was implemented in jOOQ 3.0. So, we already have these map() methods, except they're in DSLContext, not in Configuration.

Thanks,
Lukas
Reply all
Reply to author
Forward
0 new messages