/** * Run the specified code inside a single transaction, with the contained code returning a value * of the parameter type A. * * <p>In most cases this is not needed, because the primitives always create their own transaction * automatically, but it is needed in some circumstances. */ public static <A> A run(Lambda0<A> code) { synchronized (transactionLock) { // If we are already inside a transaction (which must be on the same // thread otherwise we wouldn't have acquired transactionLock), then // keep using that same transaction. Transaction transWas = currentTransaction; try { startIfNecessary(); return code.apply(); } finally { if (transWas == null) currentTransaction.close(); currentTransaction = transWas; } } }
static void run(Handler<Transaction> code) { synchronized (transactionLock) { // If we are already inside a transaction (which must be on the same // thread otherwise we wouldn't have acquired transactionLock), then // keep using that same transaction. Transaction transWas = currentTransaction; try { startIfNecessary(); code.run(currentTransaction); } finally { if (transWas == null) currentTransaction.close(); currentTransaction = transWas; } } }