Sorry if this has been asked before, but I have two basic questions.1. Why do the functions for the transaction methods take a config instead of a DSLContext? Couldn't you have just gotten the DSLContext internally with DSL.using(config) so that the transaction function to execute just had the DSLContext?
2. Is there a way to use these methods so that instead of creating nested transaction when one is called from another that they reference count?
--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 jooq-user+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
2017-05-19 18:08 GMT+02:00 <robert....@cloudability.com>:Sorry if this has been asked before, but I have two basic questions.1. Why do the functions for the transaction methods take a config instead of a DSLContext? Couldn't you have just gotten the DSLContext internally with DSL.using(config) so that the transaction function to execute just had the DSLContext?While the DSLContext type is quite useful to your SQL building usage, Configuration is really the "interesting" type behind the scenes. It would be a bit weird for DSLContext to be an argument type for any jOOQ SPI method.
I'm struggling to try to find the right way to pass context (or configuration or transaction or connection) around between multiple separate methods of my classes.
Suppose I have a method like this, and I want to call it perhaps sometimes inside a transaction and sometimes not inside a transaction:
public void updateBook(int bookId, int authorId) {}
Which of these alternative would be best, and is there an even better way?
public void updateBook(DSLContext context, int bookId, int authorId) {}
public void updateBook(Configuration configuration, int bookId, int authorId) {}
public void updateBook(Connection connection, int bookId, int authorId) {}
You comments here indicate that passing the DSLContext is not good, but which object should I pass?
Also, is there any difference between calling DSL.using(configuration) compared to configuration.dsl() ?
Hi Ed,
Also, is there any difference between calling DSL.using(configuration) compared to configuration.dsl() ?No. The latter was introduced merely for convenience:
class Transactor {
private final DSLContext ctx;
Transactor(DSLContext ctx) {
this.ctx = ctx;
}
<T> T apply(Function<DSLContext, T> sql) {
ctx.transactionResult(config ->
sql.apply(DSL.using(config)));
}
void accept(Consumer<DSLContext> sql) {
ctx.transaction(config ->
sql.accept(DSL.using(config)));
}
}
public OltpCredentialsDao(DSLContext dslContext) {
this.transactor = new Transactor(dslContext);
}
Optional<CredentialsRecord> findByUUID(UUID id) {
return transactor.apply(sql ->
Optional.ofNullable(
sql.selectFrom(CREDENTIALS)
.where(CREDENTIALS.UUID.eq(id.toString()))
.fetchAny()));
}
--
You received this message because you are subscribed to a topic in the Google Groups "jOOQ User Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jooq-user/FeXUH-yTUQc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jooq-user+unsubscribe@googlegroups.com.
--
You received this message because you are subscribed to a topic in the Google Groups "jOOQ User Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jooq-user/FeXUH-yTUQc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jooq-user+...@googlegroups.com.