On 2017-12-27 12:03, dandh988 wrote:
> You cannot nest transactions nor can you promote a read to a write.
> You need to rewrite your code or use txn which correctly checks if a
> transaction is available and if not will begin the correct one,
> either READ or WRITE.
If you have a look at the TXN code, there is no way to know if it is a read or
a write.
Just some snipsets.
public static <T extends Transactional, X> X calculateRead(T txn, Supplier<X>
r) {
boolean b = txn.isInTransaction() ;
if ( !b )
txn.begin(ReadWrite.READ) ;
public static <T extends Transactional> void executeWrite(T txn, Runnable r) {
boolean b = txn.isInTransaction() ;
if ( !b )
txn.begin(ReadWrite.WRITE) ;
And then if you go to isInTransaction() there is no way to know if read or
write. It is just a boolean.
>
> Dick -------- Original message --------From: George News
> <[email protected]> Date: 27/12/2017 10:27 (GMT+00:00) To: Jena
> User Mailing List <[email protected]> Subject: Txn code not
> handling type of transaction Hi,
>
> As you know from other threads I'm having some issues with
> transactions. Your suggestion is to use Txn instead of begin/end.
> Just for curiosity I have checked the Txn code at [1] and it seems
> that inside you use begin/end.
>
> However I have a doubt concerning how you handle the begin/end for
> READ and WRITE. It seems that you open a transaction based on
> txn.isInTransaction(), but how do you know if it is a READ or WRITE?
>
> If you create something like:
>
> Txn.executeRead(dataset, { Txn.executeWrite(dataset, { // Whatever }
> } }
>
> the txn.begin(ReadWrite.WRITE) is not called and therefore it might
> be leading to unexepected behaviours for the txn.commit().
>
> could you give some hints on how this is handle internally? Before
> fully modify the code I have, it might be easier to replicate the
> txn behaviour ;) but I would like to know the above (if possible).
>
> As always, thanks in advanced Jorge
>
> [1]: jena/jena-arq/src/main/java/org/apache/jena/system/Txn.java
>