Runtime Validation Of Jooq Generated Classes After Schema Update?
I use the org.jooq.util.DefaultGenerator during the build process to generate jOOQ classes to represent my database schema. While the application runs, the schema is expected to ch
Solution 1:
A jOOQ 3.0 solution using org.jooq.Meta
In the upcoming jOOQ 3.0, JDBC's DatabaseMetaData can be accessed in a "jOOQ way" through a new org.jooq.Meta object (implemented with feature request #1968). This object provides access to various objects of these types:
org.jooq.Catalogorg.jooq.Schemaorg.jooq.Tableorg.jooq.Fieldorg.jooq.DataType
These could be compared to your generated classes, e.g.
MY_SCHEMA.getTables().equals(create.meta().getTables())
A jOOQ 2.x solution using JDBC DatabaseMetaData
The above solution can be implemented manually, querying the Connection.getMetaData(). It'll be a bit more work, of course
A trick querying all the tables
Another simple solution would be to query all the generated tables like this:
List<Table<?>> invalidTables = new ArrayList<>();
for (Table<?> table : MY_SCHEMA.getTables()) {
try {
create.selectFrom(table).where(Factory.falseCondition()).fetch();
}
// If table names / column names change, the above query would failcatch (DataAccessException e) {
invalidTables.add(table);
}
}
This trick would allow to detect if increments are compatible
Post a Comment for "Runtime Validation Of Jooq Generated Classes After Schema Update?"