Kailayla
Kailayla

Reputation: 323

How to make a jOOQ Configuration object?

I want to have my jOOQ connection stored so I can access it from all my classes without having to specify the url, username, password, etc.

I found this page from the jOOQ documentation. I understand I need to use DSLContext, but right now I create a new context in every class.
My eye fell on this piece of info from that same page:

If you do not have a reference to a pre-existing Configuration object (e.g. created from org.jooq.impl.DefaultConfiguration), the various overloaded DSL.using() methods will create one for you.

So as far as I understand, this is what I need to have. This may sound like a noob question, but: how do I make a "pre-existing Configuration object" and how do I create a "reference" to that?

Upvotes: 4

Views: 2675

Answers (1)

Lukas Eder
Lukas Eder

Reputation: 220932

The easiest way is to create a new DefaultConfiguration, e.g.

Configuration configuration = new DefaultConfiguration()
    .set(dataSource)
    .set(dialect)
    .set(settings)
    .set(...);

People often create such a DefaultConfiguration using Spring and then inject that into all the relevant classes, see e.g. this page from the manual:

http://www.jooq.org/doc/latest/manual/getting-started/tutorials/jooq-with-spring

Upvotes: 2

Related Questions