Hi, everyone.
I've been reading the jOOQ manual and I have a couple rudimentary questions
on the re-use of DSLContexts. A relevant page in the jOOQ manual is here:
http://www.jooq.org/doc/3.5/manual/sql-execution/transaction-management/
The first example code block on that page is the following:
create.transaction(configuration -> {
AuthorRecord author =
DSL.using(configuration)
.insertInto(AUTHOR, AUTHOR.FIRST_NAME, AUTHOR.LAST_NAME)
.values("George", "Orwell")
.returning()
.fetchOne();
DSL.using(configuration)
.insertInto(BOOK, BOOK.AUTHOR_ID, BOOK.TITLE)
.values(author.getId(), "1984")
.values(author.getId(), "Animal Farm")
.execute();
// Implicit commit executed here
});
I see here that two DSLContexts are being used; one for each query. They
are each produced using DSL.using(configuration). I'm merely wondering if
there is a reason why two DSLContexts are being used rather than one -
whether it is for stylistic reasons or a functional reason that I'm not
seeing. For example, will the following code behave identically?
create.transaction(configuration -> {
DSLContext dslContext = DSL.using(configuration);
AuthorRecord author =
dslContext
.insertInto(AUTHOR, AUTHOR.FIRST_NAME, AUTHOR.LAST_NAME)
.values("George", "Orwell")
.returning()
.fetchOne();
dslContext
.insertInto(BOOK, BOOK.AUTHOR_ID, BOOK.TITLE)
.values(author.getId(), "1984")
.values(author.getId(), "Animal Farm")
.execute();
});
Going one step further, how about the following?
final DSLContext create = SomeArbitraryDSLContextProducer();
create.transaction(configuration -> {
AuthorRecord author =
create
.insertInto(AUTHOR, AUTHOR.FIRST_NAME, AUTHOR.LAST_NAME)
.values("George", "Orwell")
.returning()
.fetchOne();
create
.insertInto(BOOK, BOOK.AUTHOR_ID, BOOK.TITLE)
.values(author.getId(), "1984")
.values(author.getId(), "Animal Farm")
.execute();
});
Thanks in advance for your help!
Matt
--
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.