From 50f656bc8a6c2959942919aaf6516d79e588714f Mon Sep 17 00:00:00 2001 From: Greg Burd Date: Wed, 15 Nov 2017 09:16:15 -0500 Subject: [PATCH] Fix commit.andThen() logic. --- .../net/helenus/core/AbstractUnitOfWork.java | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/helenus/core/AbstractUnitOfWork.java b/src/main/java/net/helenus/core/AbstractUnitOfWork.java index 7f5e6f1..3f87d05 100644 --- a/src/main/java/net/helenus/core/AbstractUnitOfWork.java +++ b/src/main/java/net/helenus/core/AbstractUnitOfWork.java @@ -17,7 +17,6 @@ package net.helenus.core; import static net.helenus.core.HelenusSession.deleted; -import com.diffplug.common.base.Errors; import com.google.common.base.Stopwatch; import com.google.common.collect.HashBasedTable; import com.google.common.collect.Table; @@ -309,6 +308,18 @@ public abstract class AbstractUnitOfWork */ public PostCommitFunction commit() throws E, TimeoutException { + // Only the outter-most UOW batches statements for commit time, execute them. + if (batch != null) { + try { + committedAt = batch.sync(this); //TODO(gburd): update cache with writeTime... + } catch (Exception e) { + if (!(e instanceof ConflictingUnitOfWorkException)) { + aborted = true; + } + throw e; + } + } + // All nested UnitOfWork should be committed (not aborted) before calls to // commit, check. boolean canCommit = true; @@ -321,7 +332,6 @@ public abstract class AbstractUnitOfWork } if (!canCommit) { - nested.forEach((uow) -> Errors.rethrow().wrap(uow::abort)); elapsedTime.stop(); if (parent == null) { @@ -337,17 +347,10 @@ public abstract class AbstractUnitOfWork return new PostCommitFunction(this, null, null, false); } else { - // Only the outter-most UOW batches statements for commit time, execute them. - if (batch != null) { - committedAt = batch.sync(this); //TODO(gburd): update cache with writeTime... - } - + elapsedTime.stop(); committed = true; aborted = false; - nested.forEach((uow) -> Errors.rethrow().wrap(uow::commit)); - elapsedTime.stop(); - if (parent == null) { // Apply all post-commit commit functions, this is the outter-most UnitOfWork. @@ -355,7 +358,7 @@ public abstract class AbstractUnitOfWork .postOrderTraversal(this) .forEach( uow -> { - applyPostCommitFunctions("committed", commitThunks); + applyPostCommitFunctions("committed", uow.commitThunks); }); // Merge our cache into the session cache.