Skip to content

Commit

Permalink
Associate transaction during synchronizations
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlloyd committed Mar 14, 2017
1 parent d053c43 commit 4cfb50b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,28 @@ public <E extends Exception> void performAction(ExceptionRunnable<E> action) thr
Object getOutflowLock() {
return outflowLock;
}

final class AssociatingSynchronization implements Synchronization {
private final Synchronization sync;

AssociatingSynchronization(final Synchronization sync) {
this.sync = sync;
}

public void beforeCompletion() {
try {
performConsumer(Synchronization::beforeCompletion, sync);
} catch (SystemException e) {
throw new SynchronizationException(e);
}
}

public void afterCompletion(final int status) {
try {
performConsumer(Synchronization::afterCompletion, sync, status);
} catch (SystemException e) {
throw new SynchronizationException(e);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public boolean delistResource(final XAResource xaRes, final int flag) throws Ill

public void registerSynchronization(final Synchronization sync) throws RollbackException, IllegalStateException, SystemException {
Assert.checkNotNullParam("sync", sync);
transaction.registerSynchronization(sync);
transaction.registerSynchronization(new AssociatingSynchronization(sync));
}

/**
Expand All @@ -162,7 +162,7 @@ public Xid getXid() {

void registerInterposedSynchronization(final Synchronization sync) throws IllegalStateException {
Assert.checkNotNullParam("sync", sync);
owner.getProvider().registerInterposedSynchronization(transaction, sync);
owner.getProvider().registerInterposedSynchronization(transaction, new AssociatingSynchronization(sync));
}

Object getResource(final Object key) throws NullPointerException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ public boolean delistResource(final XAResource xaRes, final int flag) {

public void registerSynchronization(final Synchronization sync) throws RollbackException, IllegalStateException, SystemException {
Assert.checkNotNullParam("sync", sync);
stateRef.get().registerSynchronization(sync);
stateRef.get().registerSynchronization(new AssociatingSynchronization(sync));
}

void registerInterposedSynchronization(final Synchronization sync) throws IllegalStateException {
Assert.checkNotNullParam("sync", sync);
stateRef.get().registerInterposedSynchronization(sync);
stateRef.get().registerInterposedSynchronization(new AssociatingSynchronization(sync));
}

public int hashCode() {
Expand Down

0 comments on commit 4cfb50b

Please # to comment.