Thanks for the reply, Lukas. So here's where it gets interesting, taking us back to the whole "with jOOQ you don't need an ORM" issue, which I don't think is as clear-cut as some comments might make it appear.
Let's say I have a Car class (identified by some vehicle identification number <http://en.wikipedia.org/wiki/Vehicle_identification_number> VIN) and a Wheel class, and I want to store a car in a database along with its four wheels. If two people try to store the Car in the database at the same time, I don't care who wins, but I want the whole operation to be atomic, and I want it to replace whatever Car is already in the database (if any) with the same VIN. I also have a CarManager class (which has an implementation JOOQCarManager) along with a WheelManager class (with implementation JOOQWheelManager). I set up a dbcp2 PoolingDataSource (for example) and then create a jOOQ configuration using: final org.jooq.Configuration jooqConfiguration = new DefaultConfiguration() .set(dataSource).set(SQLDialect.POSTGRES).set(new Settings().withExecuteLogging(true)); Somehow that jooqConfiguration instance gets put in some dependency injection container; we don't care how, we only care that the managers have access to it. So inside JOOQCarManager.storeCar(Car car) I create a DSLContext: DSLContext dslContext=DSL.using(getConfiguration()) Question 1: So what do I do now? Do I just start using the DSLContext and it will get a connection as needed? Or do I do this? Connection connection = dslContext.configuration().connectionProvider().acquire(); Question 2: How do I start a transaction? The code I'm reviewing (a mix of several people's code) does this: DSLContext dslTransaction = DSL.using(connection); dslTransaction.execute("SET CONSTRAINTS ALL DEFERRED"); ... //and then goes on to delete the Car if it exists final int deleteCount = dslTransaction.delete(CAR).where(CAR.VIN.equal(vin).execute(); final CarRecord carRecord = dslTransaction.newRecord(CAR); ... //etc. to store the Car info Question 3: So what happens when we want to store the wheels? Does JOOQCarManager call its instance of JOOQWheelManager four times? But how does JOOQWheelManager make sure that it's part of the same transaction? If JOOQWheelManager creates a new DSLContext from the jOOQ Configuration from the DI container, won't that start a new transaction? Do we have to pass the current DSLContext to the WheelManager? Or do we pass the JDBC Connection to the WheelManager, which will use it to form a DSLContext that uses the same connection? I apologize if some of these questions have obvious answers. In fact I hope they do. I am not a relational database expert, but unfortunately I'm the one who gets to research all this stuff for my client's application. I would think that the above scenario is very common and in fact "standard" to some extent when storing an instance tree in a database. I'm hoping there is a straightforward and "standard" solution. -- 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.
