Java Code Examples for org.springframework.transaction.support.TransactionSynchronization#STATUS_COMMITTED

The following examples show how to use org.springframework.transaction.support.TransactionSynchronization#STATUS_COMMITTED . 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
Source File: DataSourceTransactionManagerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void beforeCommit(boolean readOnly) {
	if (this.status != TransactionSynchronization.STATUS_COMMITTED) {
		fail("Should never be called");
	}
	assertFalse(this.beforeCommitCalled);
	this.beforeCommitCalled = true;
}
 
Example 2
Source File: DataSourceTransactionManagerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void afterCommit() {
	if (this.status != TransactionSynchronization.STATUS_COMMITTED) {
		fail("Should never be called");
	}
	assertFalse(this.afterCommitCalled);
	this.afterCommitCalled = true;
}
 
Example 3
Source File: DataSourceTransactionManagerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void beforeCommit(boolean readOnly) {
	if (this.status != TransactionSynchronization.STATUS_COMMITTED) {
		fail("Should never be called");
	}
	assertFalse(this.beforeCommitCalled);
	this.beforeCommitCalled = true;
}
 
Example 4
Source File: DataSourceTransactionManagerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void afterCommit() {
	if (this.status != TransactionSynchronization.STATUS_COMMITTED) {
		fail("Should never be called");
	}
	assertFalse(this.afterCommitCalled);
	this.afterCommitCalled = true;
}
 
Example 5
Source File: DataSourceTransactionManagerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void beforeCommit(boolean readOnly) {
	if (this.status != TransactionSynchronization.STATUS_COMMITTED) {
		fail("Should never be called");
	}
	assertFalse(this.beforeCommitCalled);
	this.beforeCommitCalled = true;
}
 
Example 6
Source File: DataSourceTransactionManagerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void afterCommit() {
	if (this.status != TransactionSynchronization.STATUS_COMMITTED) {
		fail("Should never be called");
	}
	assertFalse(this.afterCommitCalled);
	this.afterCommitCalled = true;
}
 
Example 7
Source File: PersistenceImpl.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void afterCompletion(int status) {
    if (status == TransactionSynchronization.STATUS_COMMITTED)
        statisticsAccumulator.incCommittedTransactionsCount();
    else
        statisticsAccumulator.incRolledBackTransactionsCount();
}
 
Example 8
Source File: PersistenceImplSupport.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void afterCompletion(int status) {
    try {
        Collection<Entity> instances = container.getAllInstances();
        if (log.isTraceEnabled())
            log.trace("ContainerResourceSynchronization.afterCompletion: instances = " + instances);
        for (Object instance : instances) {
            if (instance instanceof BaseGenericIdEntity) {
                if (status == TransactionSynchronization.STATUS_COMMITTED) {
                    if (BaseEntityInternalAccess.isNew((BaseGenericIdEntity) instance)) {
                        // new instances become not new and detached only if the transaction was committed
                        BaseEntityInternalAccess.setNew((BaseGenericIdEntity) instance, false);
                    }
                } else { // commit failed or the transaction was rolled back
                    makeDetached(instance);
                    for (Entity entity : container.getNewDetachedInstances()) {
                        BaseEntityInternalAccess.setNew((BaseGenericIdEntity) entity, true);
                        BaseEntityInternalAccess.setDetached((BaseGenericIdEntity) entity, false);
                    }
                }
            }
        }
        for (AfterCompleteTransactionListener listener : afterCompleteTxListeners) {
            listener.afterComplete(status == TransactionSynchronization.STATUS_COMMITTED, instances);
        }
    } finally {
        super.afterCompletion(status);
    }
}
 
Example 9
Source File: DataSourceTransactionManagerTests.java    From effectivejava with Apache License 2.0 5 votes vote down vote up
@Override
public void beforeCommit(boolean readOnly) {
	if (this.status != TransactionSynchronization.STATUS_COMMITTED) {
		fail("Should never be called");
	}
	assertFalse(this.beforeCommitCalled);
	this.beforeCommitCalled = true;
}
 
Example 10
Source File: DataSourceTransactionManagerTests.java    From effectivejava with Apache License 2.0 5 votes vote down vote up
@Override
public void afterCommit() {
	if (this.status != TransactionSynchronization.STATUS_COMMITTED) {
		fail("Should never be called");
	}
	assertFalse(this.afterCommitCalled);
	this.afterCommitCalled = true;
}
 
Example 11
Source File: TransactionSupportUtil.java    From alfresco-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void afterCompletion(int status)
{
    // As in Spring 5 the synchronisations are cleared after the transaction is committed or rolled back.
    // It is required to remove synchronization, as it is enforces binding of
    // new txn synchronization if one will be started in afterCommit/afterRollback listeners.
    TransactionSupportUtil.unbindResource(RESOURCE_KEY_TXN_SYNCH);

    String statusStr = "unknown";
    switch (status)
    {
        case TransactionSynchronization.STATUS_COMMITTED:
            statusStr = "committed";
            break;
        case TransactionSynchronization.STATUS_ROLLED_BACK:
            statusStr = "rolled-back";
            break;
        default:
    }
    if (logger.isDebugEnabled())
    {
        logger.debug("After completion (" + statusStr + "): " + this);
    }

    Set<Integer> priorities = priorityLookup.keySet();

    SortedSet<Integer> sortedPriorities = new ConcurrentSkipListSet<Integer>(REVERSE_INTEGER_ORDER);
    sortedPriorities.addAll(priorities);

    // Need to run these in reverse order cache,lucene,listeners
    for(Integer priority : sortedPriorities)
    {
        Set<TransactionListener> listeners = new HashSet<TransactionListener>(priorityLookup.get(priority));

        for(TransactionListener listener : listeners)
        {
            try
            {
                if (status  == TransactionSynchronization.STATUS_COMMITTED)
                {
                    listener.afterCommit();
                }
                else
                {
                    listener.afterRollback();
                }
            }
            catch (RuntimeException e)
            {
                logger.error("After completion (" + statusStr + ") exception", e);
            }
        }
    }
    if(logger.isDebugEnabled())
    {
        logger.debug("After Completion: DONE");
    }

    TransactionSupportUtil.clearResources();
}