When using jOOQ together with the Quarkus Framework, i need to pick the SQL-Dialect manually, because it is not picked-up / resolved from the typical application.conf setting. For example: quarkus.datasource.db-kind=mariadb for mariadb.
I can resolve it manually, by defining an additional property in the application.conf and resolve it manually.
See following example:
...
final Optional<@NotNull SQLDialect> maybeSqlDialect =
Arrays.stream(SQLDialect.families()).filter(x -> x.name().equalsIgnoreCase(jooqDialect)).findFirst();
if (maybeSqlDialect.isEmpty()) {
throw new RuntimeException("sql-dialect not found! " + jooqDialect);
}
final SQLDialect sqlDialect = maybeSqlDialect.get();
Configuration configuration = new DefaultConfiguration()
.set(dataSource)
.set(sqlDialect)
.set(new Settings()
...
);
...
is it possible to let jOOQ automatically resolve the SQLDialect from the javax.sql.Datasource, or are there other alternative i may not know of, to make jOOQ correctly select the SQLDialect for my quarkus datasource configuration, that i setup in the application.conf file?
Used Versions:
- Quarkus 3.8.2
- jOOQ 3.19.6
jOOQ itself won't resolve the
SQLDialectfrom thejavax.sql.DataSourcealone, because to do so, it would have to callDataSource.getConnection(), which is potentially a costly operation. TheSQLDialectis already necessary before theConnectionis fetched, and not all interactions with jOOQ will require aConnection. E.g. when logging formatted SQL, the generated SQL requires only aSQLDialect, not aConnection, as it isn't executed.If you can provide jOOQ with a JDBC
Connectioninstead, then it can find theSQLDialectfrom the meta data, however:Alternatively, if you know how your
DataSourceis set up (e.g. from a properties file), then you can also useJDBCUtils.dialect(String)to have jOOQ look at the JDBC URL to derive theSQLDialectfamily at least. The dialect version can't be detected this way either, for that, a JDBCConnectionis also necessary (and itsDatabaseMetaDataAPI)