I'm an experienced and happy jOOQ user.
I'm now working on a project that need to support multiple database engines (PostgreSQL, MySQL, Oracle at least).
We want something with the low level enough to have control on our queries. JPA/Hibernate are too high level for us.
I know jOOQ works with a metamodel, and that metamodel is generated from the database schema.
Is there any way to reuse the same jOOQ query definitions against different database engines (with the same schema, apart from engine specific differences)?
Fine if we need to recompile the java classes if necessary. Compile time configuration is fine for us.
jOOQ has been designed for this. You need to do these things:
Configuration
with a SQLDialect
ready depending on your JDBC connection. That's the easy part. That Configuration
will automatically generate vendor specific SQL for all of your jOOQ queries. This can be done at runtime. No need for any compile time adaptations.@Support({ MYSQL, ORACLE, POSTGRES })
. For example, DSL.toDate()
cannot be used, because it doesn't support MySQL, but DSL.trunc()
can be used, because all 3 target dialects are present. We're increasingly also adding dialect specific information to the jOOQ manual, eg for the SHL()
function :
-- ASE, HSQLDB, SQLDATAWAREHOUSE, SQLSERVER, SYBASE
(1 * CAST(power(2, 4) AS int))
-- AURORA_MYSQL, AURORA_POSTGRES, COCKROACHDB, CUBRID, MARIADB, MEMSQL, MYSQL, POSTGRES, SQLITE, VERTICA
(1 << 4)
-- DB2, INFORMIX
(1 * CAST(power(2, 4) AS integer))
-- FIREBIRD
bin_shl(1, 4)
-- H2
lshift(1, 4)
-- ORACLE
(1 * CAST(power(2, 4) AS number(10)))
-- TERADATA
shiftleft(1, 4)
-- ACCESS, DERBY, HANA, INGRES, REDSHIFT
/* UNSUPPORTED */
In order to ensure you're not accidentally writing a query that doesn't work on some dialect, you can:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.