本文整理汇总了Java中org.springframework.transaction.IllegalTransactionStateException类的典型用法代码示例。如果您正苦于以下问题:Java IllegalTransactionStateException类的具体用法?Java IllegalTransactionStateException怎么用?Java IllegalTransactionStateException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IllegalTransactionStateException类属于org.springframework.transaction包,在下文中一共展示了IllegalTransactionStateException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: commit
import org.springframework.transaction.IllegalTransactionStateException; //导入依赖的package包/类
/**
* This implementation of commit handles participating in existing
* transactions and programmatic rollback requests.
* Delegates to {@code isRollbackOnly}, {@code doCommit}
* and {@code rollback}.
* @see org.springframework.transaction.TransactionStatus#isRollbackOnly()
* @see #doCommit
* @see #rollback
*/
@Override
public final void commit(TransactionStatus status) throws TransactionException {
if (status.isCompleted()) {
throw new IllegalTransactionStateException(
"Transaction is already completed - do not call commit or rollback more than once per transaction");
}
DefaultTransactionStatus defStatus = (DefaultTransactionStatus) status;
if (defStatus.isLocalRollbackOnly()) {
if (defStatus.isDebug()) {
logger.debug("Transactional code has requested rollback");
}
processRollback(defStatus);
return;
}
if (!shouldCommitOnGlobalRollbackOnly() && defStatus.isGlobalRollbackOnly()) {
if (defStatus.isDebug()) {
logger.debug("Global transaction is marked as rollback-only but transactional code requested commit");
}
processRollback(defStatus);
// Throw UnexpectedRollbackException only at outermost transaction boundary
// or if explicitly asked to.
if (status.isNewTransaction() || isFailEarlyOnGlobalRollbackOnly()) {
throw new UnexpectedRollbackException(
"Transaction rolled back because it has been marked as rollback-only");
}
return;
}
processCommit(defStatus);
}
示例2: propagationMandatoryFailsInCaseOfNoExistingTransaction
import org.springframework.transaction.IllegalTransactionStateException; //导入依赖的package包/类
@Test
public void propagationMandatoryFailsInCaseOfNoExistingTransaction() {
MockUOWManager manager = new MockUOWManager();
WebSphereUowTransactionManager ptm = new WebSphereUowTransactionManager(manager);
DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
definition.setPropagationBehavior(TransactionDefinition.PROPAGATION_MANDATORY);
try {
ptm.execute(definition, new TransactionCallback<String>() {
@Override
public String doInTransaction(TransactionStatus status) {
return "result";
}
});
fail("Should have thrown IllegalTransactionStateException");
}
catch (IllegalTransactionStateException ex) {
// expected
}
}
示例3: propagationNeverFailsInCaseOfExistingTransaction
import org.springframework.transaction.IllegalTransactionStateException; //导入依赖的package包/类
@Test
public void propagationNeverFailsInCaseOfExistingTransaction() {
MockUOWManager manager = new MockUOWManager();
manager.setUOWStatus(UOWManager.UOW_STATUS_ACTIVE);
WebSphereUowTransactionManager ptm = new WebSphereUowTransactionManager(manager);
DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
definition.setPropagationBehavior(TransactionDefinition.PROPAGATION_NEVER);
try {
ptm.execute(definition, new TransactionCallback<String>() {
@Override
public String doInTransaction(TransactionStatus status) {
return "result";
}
});
fail("Should have thrown IllegalTransactionStateException");
}
catch (IllegalTransactionStateException ex) {
// expected
}
}
示例4: testPropagationMandatoryFailsInCaseOfNoExistingTransaction
import org.springframework.transaction.IllegalTransactionStateException; //导入依赖的package包/类
public void testPropagationMandatoryFailsInCaseOfNoExistingTransaction() {
MockUOWManager manager = new MockUOWManager();
WebSphereUowTransactionManager ptm = new WebSphereUowTransactionManager(manager);
DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
definition.setPropagationBehavior(TransactionDefinition.PROPAGATION_MANDATORY);
try {
ptm.execute(definition, new TransactionCallback() {
@Override
public Object doInTransaction(TransactionStatus status) {
return "result";
}
});
fail("Should have thrown IllegalTransactionStateException");
}
catch (IllegalTransactionStateException ex) {
// expected
}
}
示例5: testPropagationNeverFailsInCaseOfExistingTransaction
import org.springframework.transaction.IllegalTransactionStateException; //导入依赖的package包/类
public void testPropagationNeverFailsInCaseOfExistingTransaction() {
MockUOWManager manager = new MockUOWManager();
manager.setUOWStatus(UOWManager.UOW_STATUS_ACTIVE);
WebSphereUowTransactionManager ptm = new WebSphereUowTransactionManager(manager);
DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
definition.setPropagationBehavior(TransactionDefinition.PROPAGATION_NEVER);
try {
ptm.execute(definition, new TransactionCallback() {
@Override
public Object doInTransaction(TransactionStatus status) {
return "result";
}
});
fail("Should have thrown IllegalTransactionStateException");
}
catch (IllegalTransactionStateException ex) {
// expected
}
}
示例6: rollback
import org.springframework.transaction.IllegalTransactionStateException; //导入依赖的package包/类
/**
* This implementation of rollback handles participating in existing
* transactions. Delegates to {@code doRollback} and
* {@code doSetRollbackOnly}.
* @see #doRollback
* @see #doSetRollbackOnly
*/
@Override
public final void rollback(TransactionStatus status) throws TransactionException {
if (status.isCompleted()) {
throw new IllegalTransactionStateException(
"Transaction is already completed - do not call commit or rollback more than once per transaction");
}
DefaultTransactionStatus defStatus = (DefaultTransactionStatus) status;
processRollback(defStatus);
}
示例7: commit
import org.springframework.transaction.IllegalTransactionStateException; //导入依赖的package包/类
public void commit() {
if (rollbackCalled) {
throw new IllegalTransactionStateException("Cannot call commit after rollback. Start another transaction first!");
}
try {
/*final Object[] objects =*/ redisTemplate.exec();
commitCalled = true;
} catch (Exception e) {
throw new TransactionSystemException("Exception occurred committing back Redis transaction: " + e.getMessage());
}
}
示例8: testFlushWithoutTransaction
import org.springframework.transaction.IllegalTransactionStateException; //导入依赖的package包/类
@Test
public void testFlushWithoutTransaction() {
try {
new TransactionalAspectMethods().testFlushWithoutTransaction();
Assertions.failExceptionExpected();
} catch (final Throwable t) {
Assertions.assertThat(t).isInstanceOf(IllegalTransactionStateException.class);
}
}
示例9: testFlushWithoutTransaction
import org.springframework.transaction.IllegalTransactionStateException; //导入依赖的package包/类
@Test
public void testFlushWithoutTransaction() {
Assertions.assertThrows(IllegalTransactionStateException.class, new Executable() {
@Override
public void execute() throws Throwable {
new TransactionalAspectMethods().testFlushWithoutTransaction();
}
});
}
示例10: testMandatoryFailsWhenInvokedWithoutTx
import org.springframework.transaction.IllegalTransactionStateException; //导入依赖的package包/类
@Test(expected = IllegalTransactionStateException.class)
public void testMandatoryFailsWhenInvokedWithoutTx() {
txUtil.executeWith_MANDATORY(new Runnable() {
@Override
public void run() {
fail("Must never reach this point!");
}
});
}
示例11: testMandatoryPropagation
import org.springframework.transaction.IllegalTransactionStateException; //导入依赖的package包/类
/** */
public void testMandatoryPropagation() {
IgniteCache<Integer, String> c = grid().cache(CACHE_NAME);
try {
service.putWithMandatoryPropagation(c);
}
catch (IllegalTransactionStateException e) {
assertEquals("No existing transaction found for transaction marked with propagation 'mandatory'", e.getMessage());
}
assertEquals(0, c.size());
}
示例12: proceed
import org.springframework.transaction.IllegalTransactionStateException; //导入依赖的package包/类
private Object proceed(ProceedingJoinPoint pjp, Retry retryAnnotation) throws Throwable {
int times = retryAnnotation.times();
Class<? extends Throwable>[] retryOn = retryAnnotation.on();
Assert.isTrue(times > 0, "@Retry{times} should be greater than 0!");
Assert.isTrue(retryOn.length > 0, "@Retry{on} should have at least one Throwable!");
if (retryAnnotation.failInTransaction() && TransactionSynchronizationManager.isActualTransactionActive()) {
throw new IllegalTransactionStateException(
"You shouldn't retry an operation from within an existing Transaction." +
"This is because we can't retry if the current Transaction was already rolled back!");
}
LOGGER.info("Proceed with {} retries on {}", times, Arrays.toString(retryOn));
return tryProceeding(pjp, times, retryOn);
}
示例13: testRetryFailsOnTransaction
import org.springframework.transaction.IllegalTransactionStateException; //导入依赖的package包/类
@Test(expected = IllegalTransactionStateException.class)
public void testRetryFailsOnTransaction() {
try {
TransactionSynchronizationManager.setActualTransactionActive(true);
itemService.saveItem();
} finally {
TransactionSynchronizationManager.setActualTransactionActive(false);
}
}
示例14: commit
import org.springframework.transaction.IllegalTransactionStateException; //导入依赖的package包/类
/**
* This implementation of commit handles participating in existing
* transactions and programmatic rollback requests.
* Delegates to {@code isRollbackOnly}, {@code doCommit}
* and {@code rollback}.
* @see org.springframework.transaction.TransactionStatus#isRollbackOnly()
* @see #doCommit
* @see #rollback
*/
public final void commit(TransactionStatus status) throws TransactionException {
if (status.isCompleted()) {
throw new IllegalTransactionStateException(
"Transaction is already completed - do not call commit or rollback more than once per transaction");
}
DefaultTransactionStatus defStatus = (DefaultTransactionStatus) status;
if (defStatus.isLocalRollbackOnly()) {
if (defStatus.isDebug()) {
logger.debug("Transactional code has requested rollback");
}
processRollback(defStatus);
return;
}
if (!shouldCommitOnGlobalRollbackOnly() && defStatus.isGlobalRollbackOnly()) {
if (defStatus.isDebug()) {
logger.debug("Global transaction is marked as rollback-only but transactional code requested commit");
}
processRollback(defStatus);
// Throw UnexpectedRollbackException only at outermost transaction boundary
// or if explicitly asked to.
if (status.isNewTransaction() || isFailEarlyOnGlobalRollbackOnly()) {
throw new UnexpectedRollbackException(
"Transaction rolled back because it has been marked as rollback-only");
}
return;
}
processCommit(defStatus);
}
示例15: rollback
import org.springframework.transaction.IllegalTransactionStateException; //导入依赖的package包/类
/**
* This implementation of rollback handles participating in existing
* transactions. Delegates to {@code doRollback} and
* {@code doSetRollbackOnly}.
* @see #doRollback
* @see #doSetRollbackOnly
*/
public final void rollback(TransactionStatus status) throws TransactionException {
if (status.isCompleted()) {
throw new IllegalTransactionStateException(
"Transaction is already completed - do not call commit or rollback more than once per transaction");
}
DefaultTransactionStatus defStatus = (DefaultTransactionStatus) status;
processRollback(defStatus);
}