JOOQ DSLContext creation via producer in JakartaEE environment
I've read up and down JooQ documentation and did many online searches but I didn't find an answer to this question. Which is the best (or the only one!) method of DSLContext creation using a producer in JakartaEE environment?
Method A
public class DSLContextProducer {
@Resource(lookup = "jdbc/dsname")
DataSource ds;
DSLContext ctx;
@Produces
@DSLCtx
public DSLContext getContext() {
// reuse cached DSLContext
if(ctx==null) ctx = org.jooq.impl.DSL.using(ds, SQLDialect.MYSQL);
return ctx;
}
}
or
Method B
public class DSLContextProducer {
@Resource(lookup = "jdbc/dsname")
DataSource ds;
@Produces
@DSLCtx
public DSLContext getContext() {
return org.jooq.impl.DSL.using(ds, SQLDialect.MYSQL);
}
}
That is, can be DSLContext be cached and reused (is thread safe)? Is it safe when doing transactions?
Thank you!