Hello, What you're looking for is called "runtime schema mapping" in jOOQ. More details can be found here: http://www.jooq.org/doc/latest/manual/sql-building/dsl-context/runtime-schema-mapping
It'll do exactly what you want: DSLContext dsl = DSL.using(datasource1, SQLDialect.MYSQL, settingsWithMapping1); Result<Record> result1 = dsl.select().from(AUTHOR).fetch(); // select * from BookStore1.Author DSLContext dsl = DSL.using(datasource2, SQLDialect.MYSQL, settingsWithMapping2); Result<Record> result1 = dsl.select().from(AUTHOR).fetch(); // select * from BookStore2.Author Hope this helps, Lukas 2016-07-21 6:35 GMT+02:00 Goddamned Qu <[email protected]>: > Is there a easy way to keep the static typing, for instance like this: > > DSLContext dsl = DSL.using(datasource1, SQLDialect.MYSQL); > Result<Record> result1 = dsl.select().from(AUTHOR).fetch(); > // select * from BookStore1.Author > > DSLContext dsl = DSL.using(datasource2, SQLDialect.MYSQL); > Result<Record> result1 = dsl.select().from(AUTHOR).fetch(); > // select * from BookStore2.Author > > 在 2016年7月21日星期四 UTC+8下午12:02:31,Goddamned Qu写道: > >> some sharding strategy is to use number to label different db instances, >> but each db has the same table schemas >> >> eg. has 2 BookStore db with the same table Author >> >> Create Database BookStore1; >> use BookStore1; >> CREATE TABLE `Author` ( >> `id` int NOT NULL, >> `firstName` varchar(255) DEFAULT NULL, >> `lastName` varchar(255) DEFAULT NULL, >> PRIMARY KEY (`id`) >> ); >> >> Create Database BookStore2; >> use BookStore2; >> CREATE TABLE `Author` ( >> `id` int NOT NULL, >> `firstName` varchar(255) DEFAULT NULL, >> `lastName` varchar(255) DEFAULT NULL, >> PRIMARY KEY (`id`) >> ); >> >> >> >> how could jooq deal with same table schema with different db name without >> generate a lot of repeated code? >> > -- > 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. > -- 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.
