private R doWork()

in tx-control-services/tx-control-service-common/src/main/java/org/apache/aries/tx/control/service/common/impl/AbstractTransactionControlImpl.java [156:218]


		private <R> R doWork(Callable<R> transactionalWork,
				AbstractTransactionContextImpl currentTran, 
				boolean endTransaction) {
			R result;
			try {
				result = transactionalWork.call();

			} catch (Throwable t) {
				if(!currentTran.ignoredExceptions.contains(t) && 
						requiresRollback(t)) {
					currentTran.safeSetRollbackOnly();
				}
				if(endTransaction) {
					try {
						currentTran.finish();
					} catch (Exception e) {
						currentTran.recordFailure(e);
					}
				}
				
				TransactionContext toPropagate = endTransaction ? null : currentTran;
				
				ScopedWorkException workException;
				
				if(t instanceof ScopedWorkException) {
					workException = new ScopedWorkException("A nested piece of scoped work threw an exception", 
							t.getCause(), toPropagate);
					workException.addSuppressed(t);
				} else {
					workException = new ScopedWorkException("The scoped work threw an exception", 
							t, toPropagate);
				}
				
				Throwable throwable = currentTran.firstUnexpectedException.get();
				if(throwable != null) {
					workException.addSuppressed(throwable);
				}
				currentTran.subsequentExceptions.stream().forEach(workException::addSuppressed);
				
				throw workException;
			}
			
			if(endTransaction) {
				try {
					currentTran.finish();
				} catch (Exception e) {
					currentTran.recordFailure(e);
				}
			}
			
			Throwable throwable = currentTran.firstUnexpectedException.get();
			if(throwable != null) {
				TransactionException te = currentTran.getTransactionStatus() == ROLLED_BACK ?
						new TransactionRolledBackException("The transaction rolled back due to a failure", throwable) :
						new TransactionException("There was an error in the Transaction completion.", throwable);
				
				currentTran.subsequentExceptions.stream().forEach(te::addSuppressed);
				
				throw te;
			}
			
			return result;
		}