Skip to content

Commit 5f67fca

Browse files
committed
Fixed jOOQ "findCompanyUsingSimpleStaticStatement()"
1 parent 8b04036 commit 5f67fca

1 file changed

Lines changed: 5 additions & 21 deletions

File tree

src/main/java/com/clevergang/dbtests/repository/impl/jooq/JooqDataRepositoryImpl.java

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,27 +66,11 @@ public Company findCompany(Integer pid) {
6666

6767
@Override
6868
public Company findCompanyUsingSimpleStaticStatement(Integer pid) {
69-
// This is the only way I found how to actually do a static Statement in JOOQ (so not the default
70-
// prepared statement, but simple static statement where you do not bind values). We create new instance of DSLContext
71-
// using Settings which are configured to use static statements. The important factor here is
72-
// to create new context based on the Connection of autowired DSLContext (therefore the usage of create.connection()
73-
// method) - this is the only way to ensure that the this static statement will be executed in same transaction
74-
// as other statements called through autowired DSLContext.
75-
//
76-
// If you create new DSLContext using the some generally available (autowired) datasource, then you'll create
77-
// completely new JOOQ configuration with completely new connection -> such statements will be executed in
78-
// their own transactions!
79-
//
80-
// FIXME: I don't like the usage of AtomicReference here to get the value out of the lambda. If anyone has better class where to store the value, please advise.
81-
AtomicReference<Company> reference = new AtomicReference<>();
82-
create.connection(connection -> {
83-
DSLContext staticStatement = DSL.using(connection, create.dialect(), staticStatementSettings);
84-
reference.set(staticStatement.
85-
selectFrom(COMPANY)
86-
.where(COMPANY.PID.eq(pid))
87-
.fetchOneInto(Company.class));
88-
});
89-
return reference.get();
69+
Configuration configuration = create.configuration().derive(staticStatementSettings);
70+
return DSL.using(configuration)
71+
.selectFrom(COMPANY)
72+
.where(COMPANY.PID.eq(pid))
73+
.fetchOneInto(Company.class));
9074
}
9175

9276
@Override

0 commit comments

Comments
 (0)