Java Code Examples for org.springframework.transaction.support.TransactionSynchronizationUtils

The following examples show how to use org.springframework.transaction.support.TransactionSynchronizationUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public void afterCompletion(int status) {
	switch (status) {
		case Status.STATUS_COMMITTED:
			try {
				TransactionSynchronizationUtils.invokeAfterCommit(this.synchronizations);
			}
			finally {
				TransactionSynchronizationUtils.invokeAfterCompletion(
						this.synchronizations, TransactionSynchronization.STATUS_COMMITTED);
			}
			break;
		case Status.STATUS_ROLLEDBACK:
			TransactionSynchronizationUtils.invokeAfterCompletion(
					this.synchronizations, TransactionSynchronization.STATUS_ROLLED_BACK);
			break;
		default:
			TransactionSynchronizationUtils.invokeAfterCompletion(
					this.synchronizations, TransactionSynchronization.STATUS_UNKNOWN);
	}
}
 
Example 2
@Override
public void initialize() {
	// Set sessionTransacted=true in case of a non-JTA transaction manager.
	if (!this.sessionTransactedCalled &&
			this.transactionManager instanceof ResourceTransactionManager &&
			!TransactionSynchronizationUtils.sameResourceFactory(
					(ResourceTransactionManager) this.transactionManager, obtainConnectionFactory())) {
		super.setSessionTransacted(true);
	}

	// Use bean name as default transaction name.
	if (this.transactionDefinition.getName() == null) {
		String beanName = getBeanName();
		if (beanName != null) {
			this.transactionDefinition.setName(beanName);
		}
	}

	// Proceed with superclass initialization.
	super.initialize();
}
 
Example 3
@Override
public void afterCompletion(int status) {
	switch (status) {
		case Status.STATUS_COMMITTED:
			try {
				TransactionSynchronizationUtils.invokeAfterCommit(this.synchronizations);
			}
			finally {
				TransactionSynchronizationUtils.invokeAfterCompletion(
						this.synchronizations, TransactionSynchronization.STATUS_COMMITTED);
			}
			break;
		case Status.STATUS_ROLLEDBACK:
			TransactionSynchronizationUtils.invokeAfterCompletion(
					this.synchronizations, TransactionSynchronization.STATUS_ROLLED_BACK);
			break;
		default:
			TransactionSynchronizationUtils.invokeAfterCompletion(
					this.synchronizations, TransactionSynchronization.STATUS_UNKNOWN);
	}
}
 
Example 4
@Override
public void initialize() {
	// Set sessionTransacted=true in case of a non-JTA transaction manager.
	if (!this.sessionTransactedCalled &&
			this.transactionManager instanceof ResourceTransactionManager &&
			!TransactionSynchronizationUtils.sameResourceFactory(
					(ResourceTransactionManager) this.transactionManager, obtainConnectionFactory())) {
		super.setSessionTransacted(true);
	}

	// Use bean name as default transaction name.
	if (this.transactionDefinition.getName() == null) {
		String beanName = getBeanName();
		if (beanName != null) {
			this.transactionDefinition.setName(beanName);
		}
	}

	// Proceed with superclass initialization.
	super.initialize();
}
 
Example 5
@Override
public void afterCompletion(int status) {
	switch (status) {
		case Status.STATUS_COMMITTED:
			try {
				TransactionSynchronizationUtils.invokeAfterCommit(this.synchronizations);
			}
			finally {
				TransactionSynchronizationUtils.invokeAfterCompletion(
						this.synchronizations, TransactionSynchronization.STATUS_COMMITTED);
			}
			break;
		case Status.STATUS_ROLLEDBACK:
			TransactionSynchronizationUtils.invokeAfterCompletion(
					this.synchronizations, TransactionSynchronization.STATUS_ROLLED_BACK);
			break;
		default:
			TransactionSynchronizationUtils.invokeAfterCompletion(
					this.synchronizations, TransactionSynchronization.STATUS_UNKNOWN);
	}
}
 
Example 6
@Override
public void afterCompletion(int status) {
	switch (status) {
		case Status.STATUS_COMMITTED:
			try {
				TransactionSynchronizationUtils.invokeAfterCommit(this.synchronizations);
			}
			finally {
				TransactionSynchronizationUtils.invokeAfterCompletion(
						this.synchronizations, TransactionSynchronization.STATUS_COMMITTED);
			}
			break;
		case Status.STATUS_ROLLEDBACK:
			TransactionSynchronizationUtils.invokeAfterCompletion(
					this.synchronizations, TransactionSynchronization.STATUS_ROLLED_BACK);
			break;
		default:
			TransactionSynchronizationUtils.invokeAfterCompletion(
					this.synchronizations, TransactionSynchronization.STATUS_UNKNOWN);
	}
}
 
Example 7
@Override
public void initialize() {
	// Set sessionTransacted=true in case of a non-JTA transaction manager.
	if (!this.sessionTransactedCalled &&
			this.transactionManager instanceof ResourceTransactionManager &&
			!TransactionSynchronizationUtils.sameResourceFactory(
					(ResourceTransactionManager) this.transactionManager, getConnectionFactory())) {
		super.setSessionTransacted(true);
	}

	// Use bean name as default transaction name.
	if (this.transactionDefinition.getName() == null) {
		this.transactionDefinition.setName(getBeanName());
	}

	// Proceed with superclass initialization.
	super.initialize();
}
 
Example 8
@Override
public void rollback(TransactionStatus status) throws TransactionException {
	if(logger.isWarnEnabled()){
		logger.warn("Rollback all connected transactions.");
	}
	try{
		TransactionSynchronizationUtils.triggerBeforeCompletion();
		Map<DataSource, ConnectionHolder> connSet = RoutingSynchronizationManager.getSynchronizations();
		Exception rollbackException = null;
		ConnectionHolder rollbackExceptionConnection = null;

        for (ConnectionHolder connection:connSet.values()) {
            try {
            	connection.rollback();
            	if (logger.isDebugEnabled()) {
        			logger.debug("Connection["+ connection +"] has been rolled back.");
        		}
            } catch (Exception ex) {
                if (rollbackException == null) {
                    rollbackException = ex;
                    rollbackExceptionConnection = connection;
                } else {
                    logger.warn("Rollback exception (" + rollbackExceptionConnection + ") " + ex.getMessage(), ex);
                }
            }
        }
        
        if (rollbackException != null) {
            throw new UnexpectedRollbackException("Rollback exception, originated at ("+rollbackExceptionConnection+") "+
              rollbackException.getMessage(), rollbackException);
        }
	}finally{
		RoutingSynchronizationManager
				.invokeAfterCompletion(TransactionSynchronization.STATUS_ROLLED_BACK);
		RoutingSynchronizationManager.clearSynchronization();
	}
}
 
Example 9
@Test
public void incrementBy1Transactional() throws Exception {
	// Given
	TransactionSynchronizationManager.initSynchronization();
	// When
	batchMetrics.increment("counter.test", 1L);
	TransactionSynchronizationUtils.triggerAfterCompletion(TransactionSynchronization.STATUS_COMMITTED);
	// Then
	TransactionSynchronizationManager.clearSynchronization();
}
 
Example 10
@Test
public void decrementBy1Transactional() throws Exception {
	// Given
	TransactionSynchronizationManager.initSynchronization();
	// When
	batchMetrics.decrement("counter.test", 1L);
	TransactionSynchronizationUtils.triggerAfterCompletion(TransactionSynchronization.STATUS_COMMITTED);
	// Then
	TransactionSynchronizationManager.clearSynchronization();
}
 
Example 11
@Test
public void submitTransactional() throws Exception {
	// Given
	TransactionSynchronizationManager.initSynchronization();
	// When
	batchMetrics.submit("counter.test", 1L);
	TransactionSynchronizationUtils.triggerAfterCompletion(TransactionSynchronization.STATUS_COMMITTED);
	// Then
	TransactionSynchronizationManager.clearSynchronization();
}
 
Example 12
Source Project: sdn-rx   Source File: ReactiveNeo4jTransactionManager.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void flush() {

	TransactionSynchronizationUtils.triggerFlush();
}
 
Example 13
Source Project: sdn-rx   Source File: Neo4jTransactionManager.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void flush() {

	TransactionSynchronizationUtils.triggerFlush();
}
 
Example 14
@Override
public void flush() {
	TransactionSynchronizationUtils.triggerFlush();
}
 
Example 15
@Override
public void flush() {
	if (TransactionSynchronizationManager.isSynchronizationActive()) {
		TransactionSynchronizationUtils.triggerFlush();
	}
}
 
Example 16
@Override
public void flush() {
	TransactionSynchronizationUtils.triggerFlush();
}
 
Example 17
@Override
public void flush() {
	if (TransactionSynchronizationManager.isSynchronizationActive()) {
		TransactionSynchronizationUtils.triggerFlush();
	}
}
 
Example 18
@Override
public void flush() {
	TransactionSynchronizationUtils.triggerFlush();
}
 
Example 19
@Override
public void flush() {
	if (TransactionSynchronizationManager.isSynchronizationActive()) {
		TransactionSynchronizationUtils.triggerFlush();
	}
}
 
Example 20
@Override
public void flush() {
	TransactionSynchronizationUtils.triggerFlush();
}
 
Example 21
public static void invokeAfterCompletion(int completionStatus) {
	List<TransactionSynchronization> synchronizations = TransactionSynchronizationManager
			.getSynchronizations();
	TransactionSynchronizationUtils.invokeAfterCompletion(synchronizations, completionStatus);
}
 
Example 22
Source Project: spring-analysis-note   Source File: JtaTransactionObject.java    License: MIT License 2 votes vote down vote up
/**
 * This implementation triggers flush callbacks,
 * assuming that they will flush all affected ORM sessions.
 * @see org.springframework.transaction.support.TransactionSynchronization#flush()
 */
@Override
public void flush() {
	TransactionSynchronizationUtils.triggerFlush();
}
 
Example 23
Source Project: java-technology-stack   Source File: JtaTransactionObject.java    License: MIT License 2 votes vote down vote up
/**
 * This implementation triggers flush callbacks,
 * assuming that they will flush all affected ORM sessions.
 * @see org.springframework.transaction.support.TransactionSynchronization#flush()
 */
@Override
public void flush() {
	TransactionSynchronizationUtils.triggerFlush();
}
 
Example 24
Source Project: lams   Source File: JtaTransactionObject.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * This implementation triggers flush callbacks,
 * assuming that they will flush all affected ORM sessions.
 * @see org.springframework.transaction.support.TransactionSynchronization#flush()
 */
@Override
public void flush() {
	TransactionSynchronizationUtils.triggerFlush();
}
 
Example 25
/**
 * This implementation triggers flush callbacks,
 * assuming that they will flush all affected ORM sessions.
 * @see org.springframework.transaction.support.TransactionSynchronization#flush()
 */
@Override
public void flush() {
	TransactionSynchronizationUtils.triggerFlush();
}