On 01-12-2020 16:16, shalamyansky wrote:
> This example shows how to configure TPB for db connect through code not
> via config.
Wasn't that what you asked for? You showed that you had already found
how to change it through config.
> So please hint me how to start a transaction and set the desired TPB for
> it in the context of my controller. Sorry, I'm not so familiar with JDBC
> and Java.
>
> I expect something like this code:
>
> Transaction transaction = connection.getTransaction();
> transaction.setTpb( ... );
> transaction.start();
> myRepository.doSomething();
> transaction.commit();
>
> Is it possible?
JDBC doesn't offer explicit transactions, so there is no such mechanism.
JDBC only provides transactions that are implicitly started when needed.
The code I show does exactly what you want, assuming there is no current
active transaction (the transaction config set will take effect from the
next transaction started, until the config is changed or the isolation
level is changed).
So what you can do is
Connection connection = ....
// ensure no active transaction
connection.commit();
FirebirdConnection fbConnection =
connection.unwrap(FirebirdConnection.class);
TransactionParameterBuffer tpb =
fbConnection.createTransactionParameterBuffer();
tpb.addArgument(TransactionParameterBuffer.READ_COMMITTED);
tpb.addArgument(TransactionParameterBuffer.REC_VERSION);
tpb.addArgument(TransactionParameterBuffer.WRITE);
tpb.addArgument(TransactionParameterBuffer.NO_WAIT);
connection.setTransactionParameterBuffer(tpb);
And the next transaction that is started will use this transaction
configuration (assuming there is no call to setTransactionIsolation
which would reset the transaction config to the one explicitly (or
default) configured for the isolation level)
However, I'm not sure how well this will interact with Spring Data JPA
related code. I don't normally fiddle with these kind of low-level stuff
when using Spring Data.
Mark
--
Mark Rotteveel