> Is it possible to set the schema to use at runtime for the generated
> sources?
Yes, have a look at this section of the manual:
http://www.jooq.org/manual/ADVANCED/SchemaMapping/
You can override schema names both at codegen-time and at runtime, or
make it disappear entirely by specifying a default schema at runtime.
Cheers
Lukas
2012/4/24 Ian Clarke <ian.c...@gmail.com>:
Another option to switch schema names is to use a default schema for the Factory's underlying Connection. Many RDBMS support a USE or SET SCHEMA command, which you can call like this:
// Set the default schema
Schema MY_BOOK_WORLD = ...
create.use(MY_BOOK_WORLD);
// Run queries with factory having a default schema
create.selectFrom(T_AUTHOR).fetch();
Yes, I'm aware of this. It is not really up to date. It should be
improved soon. In the mean time, use something along these lines:
new Factory(connection, dialect,
new Settings().withRenderMapping(
new RenderMapping().withDefaultSchema("MySchema")));
The above Factory will avoid rendering "MySchema". With jOOQ 2.3.0,
there will also be a way to specify Settings.setRenderSchema(false),
to avoid rendering schema names all together. Right now, the default
schema will be your only option.
Cheers
Lukas
Yes, I'm aware of this. It is not really up to date. It should be
improved soon. In the mean time, use something along these lines:
new Factory(connection, dialect,
new Settings().withRenderMapping(
new RenderMapping().withDefaultSchema("MySchema")));
The above Factory will avoid rendering "MySchema". With jOOQ 2.3.0,
there will also be a way to specify Settings.setRenderSchema(false),
to avoid rendering schema names all together. Right now, the default
schema will be your only option.
Au contraire. Look at it this way:
- jOOQ by default fully qualifies schemata
- jOOQ is thus capable of running queries against multiple schemata
- Most users probably have only one schema. They want to use that as
the "default schema"
- The default schema can be set in the JDBC string in many databases
- The default schema can be overridden using SQL statements in many
databases. Examples
-- Oracle syntax
ALTER SESSION SET current_schema = my_other_schema;
-- MySQL, Sybase ASE, Sybase SQL Anywhere
USE my_other_schema;
-- DB2, Derby, H2, HSQLDB
SET SCHEMA my_other_schema
- hence, jOOQ can't make any assumption regarding a default schema,
you need to tell jOOQ
So in other words, write this:
new Factory(connection, dialect,
new Settings().withRenderMapping(
new RenderMapping().withDefaultSchema("[the-schema-name-that-you-consider-the-default-schema]")));
As I said, jOOQ 2.3.0 will include a more user-friendly feature for
the simple use-case of not fully qualifying table names...
Hope this helps
Lukas