Обсуждение: How to set transaction isolation level for the given transaction only.
In database server, it has a default isolation level, and if we want to use
a different one, we can easily do:
begin;
set transaction isolation level xx;
commit;
We can see that the isolation level is set at the transaction level. However when I
check the API, looks I can only set it at *connection* level via Connection.setTransactionIsolation(x); If I want to rollback the original, I have
to remember to reset it after this transaction which would be boring in practice.
What would be the best practice for this?
Best Regards
Andy Fan
Re: How to set transaction isolation level for the given transaction only.
От
Steven Schlansker
Дата:
Maybe there's a neat way of doing this in the driver I'm not aware of, but usually this is left to the job of a higher level library or class you write yourself.
To shamelessly plug my own, Jdbi handles this nicely:
http://jdbi.org/apidocs/org/jdbi/v3/core/Handle.html#inTransaction-org.jdbi.v3.core.transaction.TransactionIsolationLevel-org.jdbi.v3.core.HandleCallback-
On Thu, Aug 13, 2020 at 5:53 AM Andy Fan <zhihui.fan1213@gmail.com> wrote:
In database server, it has a default isolation level, and if we want to usea different one, we can easily do:begin;set transaction isolation level xx;commit;We can see that the isolation level is set at the transaction level. However when Icheck the API, looks I can only set it at *connection* level via Connection.setTransactionIsolation(x); If I want to rollback the original, I haveto remember to reset it after this transaction which would be boring in practice.What would be the best practice for this?--Best RegardsAndy Fan
On Thu, Aug 13, 2020 at 11:16 PM Steven Schlansker <stevenschlansker@gmail.com> wrote:
Maybe there's a neat way of doing this in the driver I'm not aware of, but usually this is left to the job of a higher level library or class you write yourself.
To shamelessly plug my own, Jdbi handles this nicely:
http://jdbi.org/apidocs/org/jdbi/v3/core/Handle.html#inTransaction-org.jdbi.v3.core.transaction.TransactionIsolationLevel-org.jdbi.v3.core.HandleCallback-
Thanks for the info, I will try the similar on my own.
Best Regards
Andy Fan
You can set the transaction isolation level on the connection using the setTransactionIsolation method.
I believe that is what you are looking for.
Cheers, Rob.
On Fri, 14 Aug 2020 at 17:16, Andy Fan <zhihui.fan1213@gmail.com> wrote:
On Thu, Aug 13, 2020 at 11:16 PM Steven Schlansker <stevenschlansker@gmail.com> wrote:Maybe there's a neat way of doing this in the driver I'm not aware of, but usually this is left to the job of a higher level library or class you write yourself.
To shamelessly plug my own, Jdbi handles this nicely:
http://jdbi.org/apidocs/org/jdbi/v3/core/Handle.html#inTransaction-org.jdbi.v3.core.transaction.TransactionIsolationLevel-org.jdbi.v3.core.HandleCallback-Thanks for the info, I will try the similar on my own.--Best RegardsAndy Fan