Refine search
@Override protected void doRollback(DefaultTransactionStatus status) { DataSourceTransactionObject txObject = (DataSourceTransactionObject) status.getTransaction(); Connection con = txObject.getConnectionHolder().getConnection(); if (status.isDebug()) { logger.debug("Rolling back JDBC transaction on Connection [" + con + "]"); } try { con.rollback(); } catch (SQLException ex) { throw new TransactionSystemException("Could not roll back JDBC transaction", ex); } }
/** * Return the exception that was the first to be thrown within the failed transaction: * i.e. the application exception, if any, or the TransactionSystemException's own cause. * @return the original exception, or {@code null} if there was none */ @Nullable public Throwable getOriginalException() { return (this.applicationException != null ? this.applicationException : getCause()); }
/** * Perform a rollback, handling rollback exceptions properly. * @param status object representing the transaction * @param ex the thrown application exception or error * @throws TransactionException in case of a rollback error */ private void rollbackOnException(TransactionStatus status, Throwable ex) throws TransactionException { Assert.state(this.transactionManager != null, "No PlatformTransactionManager set"); logger.debug("Initiating transaction rollback on application exception", ex); try { this.transactionManager.rollback(status); } catch (TransactionSystemException ex2) { logger.error("Application exception overridden by rollback exception", ex); ex2.initApplicationException(ex); throw ex2; } catch (RuntimeException | Error ex2) { logger.error("Application exception overridden by rollback exception", ex); throw ex2; } }
@Override protected void doRollback(DefaultTransactionStatus status) { JtaTransactionObject txObject = (JtaTransactionObject) status.getTransaction(); try { int jtaStatus = txObject.getUserTransaction().getStatus(); if (jtaStatus != Status.STATUS_NO_TRANSACTION) { try { txObject.getUserTransaction().rollback(); } catch (IllegalStateException ex) { if (jtaStatus == Status.STATUS_ROLLEDBACK) { // Only really happens on JBoss 4.2 in case of an early timeout... if (logger.isDebugEnabled()) { logger.debug("Rollback failure with transaction already marked as rolled back: " + ex); } } else { throw new TransactionSystemException("Unexpected internal transaction state", ex); } } } } catch (SystemException ex) { throw new TransactionSystemException("JTA failure on rollback", ex); } }
@Override protected Object doSuspend(Object transaction) { JtaTransactionObject txObject = (JtaTransactionObject) transaction; try { return doJtaSuspend(txObject); } catch (SystemException ex) { throw new TransactionSystemException("JTA failure on suspend", ex); } }
new TransactionSystemException("UOWManager transaction processing failed", ex); Throwable appEx = action.getException(); if (appEx != null) { logger.error("Application exception overridden by rollback exception", appEx); tse.initApplicationException(appEx);
assertTrue(ex.getCause() instanceof UOWException); assertSame(rex, ex.getRootCause()); assertSame(rex, ex.getMostSpecificCause());
@Override protected void doCommit(DefaultTransactionStatus status) throws TransactionException { RedissonTransactionObject to = (RedissonTransactionObject) status.getTransaction(); try { to.getTransactionHolder().getTransaction().commit(); } catch (TransactionException e) { throw new TransactionSystemException("Unable to commit transaction", e); } }
/** * This implementation checks the UserTransaction's rollback-only flag. */ @Override public boolean isRollbackOnly() { try { int jtaStatus = this.userTransaction.getStatus(); return (jtaStatus == Status.STATUS_MARKED_ROLLBACK || jtaStatus == Status.STATUS_ROLLEDBACK); } catch (SystemException ex) { throw new TransactionSystemException("JTA failure on getStatus", ex); } }
new TransactionSystemException("UOWManager transaction processing failed", ex); Throwable appEx = action.getException(); if (appEx != null) { logger.error("Application exception overridden by rollback exception", appEx); tse.initApplicationException(appEx);
@Override protected void doCommit(DefaultTransactionStatus status) { DataSourceTransactionObject txObject = (DataSourceTransactionObject) status.getTransaction(); Connection con = txObject.getConnectionHolder().getConnection(); if (status.isDebug()) { logger.debug("Committing JDBC transaction on Connection [" + con + "]"); } try { con.commit(); } catch (SQLException ex) { throw new TransactionSystemException("Could not commit JDBC transaction", ex); } }
@Override protected void doRollback(DefaultTransactionStatus status) throws TransactionException { RedissonTransactionObject to = (RedissonTransactionObject) status.getTransaction(); try { to.getTransactionHolder().getTransaction().rollback(); } catch (TransactionException e) { throw new TransactionSystemException("Unable to commit transaction", e); } }
private Object loadWebLogicTransactionHelper() throws TransactionSystemException { Object helper = this.transactionHelper; if (helper == null) { try { Class<?> transactionHelperClass = getClass().getClassLoader().loadClass(TRANSACTION_HELPER_CLASS_NAME); Method getTransactionHelperMethod = transactionHelperClass.getMethod("getTransactionHelper"); helper = getTransactionHelperMethod.invoke(null); this.transactionHelper = helper; logger.trace("WebLogic TransactionHelper found"); } catch (InvocationTargetException ex) { throw new TransactionSystemException( "WebLogic's TransactionHelper.getTransactionHelper() method failed", ex.getTargetException()); } catch (Exception ex) { throw new TransactionSystemException( "Could not initialize WebLogicJtaTransactionManager because WebLogic API classes are not available", ex); } } return helper; }
/** * Perform a rollback, handling rollback exceptions properly. * @param status object representing the transaction * @param ex the thrown application exception or error * @throws TransactionException in case of a rollback error */ private void rollbackOnException(TransactionStatus status, Throwable ex) throws TransactionException { Assert.state(this.transactionManager != null, "No PlatformTransactionManager set"); logger.debug("Initiating transaction rollback on application exception", ex); try { this.transactionManager.rollback(status); } catch (TransactionSystemException ex2) { logger.error("Application exception overridden by rollback exception", ex); ex2.initApplicationException(ex); throw ex2; } catch (RuntimeException | Error ex2) { logger.error("Application exception overridden by rollback exception", ex); throw ex2; } }
/** * Return the exception that was the first to be thrown within the failed transaction: * i.e. the application exception, if any, or the TransactionSystemException's own cause. * @return the original exception, or {@code null} if there was none */ @Nullable public Throwable getOriginalException() { return (this.applicationException != null ? this.applicationException : getCause()); }
@Override protected void doRollback(DefaultTransactionStatus status) { CciLocalTransactionObject txObject = (CciLocalTransactionObject) status.getTransaction(); Connection con = txObject.getConnectionHolder().getConnection(); if (status.isDebug()) { logger.debug("Rolling back CCI local transaction on Connection [" + con + "]"); } try { con.getLocalTransaction().rollback(); } catch (LocalTransactionException ex) { throw new TransactionSystemException("Could not roll back CCI local transaction", ex); } catch (ResourceException ex) { throw new TransactionSystemException("Unexpected failure on rollback of CCI local transaction", ex); } }
@Override protected void doRollback(DefaultTransactionStatus status) throws TransactionException { RedissonTransactionObject to = (RedissonTransactionObject) status.getTransaction(); try { to.getTransactionHolder().getTransaction().rollback(); } catch (TransactionException e) { throw new TransactionSystemException("Unable to commit transaction", e); } }
@Override @Nullable protected TransactionManager retrieveTransactionManager() throws TransactionSystemException { Object helper = loadWebLogicTransactionHelper(); try { logger.trace("Retrieving JTA TransactionManager from WebLogic TransactionHelper"); Method getTransactionManagerMethod = helper.getClass().getMethod("getTransactionManager"); return (TransactionManager) getTransactionManagerMethod.invoke(this.transactionHelper); } catch (InvocationTargetException ex) { throw new TransactionSystemException( "WebLogic's TransactionHelper.getTransactionManager() method failed", ex.getTargetException()); } catch (Exception ex) { throw new TransactionSystemException( "Could not invoke WebLogic's TransactionHelper.getTransactionManager() method", ex); } }
ex2.initApplicationException(ex); throw ex2; ex2.initApplicationException(ex); throw ex2;
@Test public void testTransactionCommitWithRollbackException() { given(manager.getTransaction()).willReturn(tx); given(tx.getRollbackOnly()).willReturn(true); willThrow(new RollbackException()).given(tx).commit(); final List<String> l = new ArrayList<>(); l.add("test"); assertTrue(!TransactionSynchronizationManager.hasResource(factory)); assertTrue(!TransactionSynchronizationManager.isSynchronizationActive()); try { Object result = tt.execute(new TransactionCallback() { @Override public Object doInTransaction(TransactionStatus status) { assertTrue(TransactionSynchronizationManager.hasResource(factory)); EntityManagerFactoryUtils.getTransactionalEntityManager(factory).flush(); return l; } }); assertSame(l, result); } catch (TransactionSystemException tse) { // expected assertTrue(tse.getCause() instanceof RollbackException); } assertTrue(!TransactionSynchronizationManager.hasResource(factory)); assertTrue(!TransactionSynchronizationManager.isSynchronizationActive()); verify(manager).flush(); verify(manager).close(); }