Java Code Examples for org.springframework.transaction.PlatformTransactionManager#rollback()
The following examples show how to use
org.springframework.transaction.PlatformTransactionManager#rollback() .
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: SampleDataLoader.java From sakai with Educational Community License v2.0 | 6 votes |
public void init() { log.info("Initializing " + getClass().getName()); if(cmAdmin == null) { return; } if(loadSampleData) { loginToSakai(); PlatformTransactionManager tm = (PlatformTransactionManager)beanFactory.getBean("org.sakaiproject.springframework.orm.hibernate.GlobalTransactionManager"); DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); TransactionStatus status = tm.getTransaction(def); try { load(); } catch (Exception e) { log.error("Unable to load CM data: " + e); tm.rollback(status); } finally { if(!status.isCompleted()) { tm.commit(status); } } logoutFromSakai(); } else { if(log.isInfoEnabled()) log.info("Skipped CM data load"); } }
Example 2
Source File: SagaConsumer.java From choerodon-starters with Apache License 2.0 | 6 votes |
private void invokeError(final PlatformTransactionManager platformTransactionManager, final TransactionStatus status, final SagaTaskInstanceDTO data, final String errorMsg) { try { platformTransactionManager.rollback(status); } catch (Exception e) { LOGGER.warn("@SagaTask method code: {}, id: {} transaction rollback error", data.getTaskCode(), data.getId(), e); } finally { try { consumerClient.updateStatus(data.getId(), UpdateStatusDTO.UpdateStatusDTOBuilder.newInstance() .withStatus(SagaDefinition.TaskInstanceStatus.FAILED.name()) .withExceptionMessage(errorMsg) .withId(data.getId()) .withObjectVersionNumber(data.getObjectVersionNumber()).build()); runningTasks.remove(data.getId()); } catch (Exception ex) { CompletableFuture.supplyAsync(() -> this.retryUpdateStatusFailed(data.getId(), errorMsg), executor); } } }
Example 3
Source File: ScheduleConsumer.java From choerodon-starters with Apache License 2.0 | 6 votes |
private void invokeError(final PlatformTransactionManager platformTransactionManager, final TransactionStatus status, final ScheduleInstanceConsumerDTO data, final String errorMsg) { try { platformTransactionManager.rollback(status); } catch (Exception e) { LOGGER.warn("@JobTask method: {}, id: {} transaction rollback error", data.getMethod(), data.getId(), e); } finally { try { scheduleConsumerClient.updateStatus(data.getId(), new UpdateStatusDTO(data.getId(), QuartzDefinition.InstanceStatus.FAILED.name(), null, errorMsg, data.getObjectVersionNumber())); runningTasks.remove(data.getId()); } catch (Exception ex) { LOGGER.warn("@JobTask method: {}, id: {} updateStatusFailed error, error message: {}", data.getMethod(), data.getId(), ex.getMessage()); runningTasks.remove(data.getId()); } } }
Example 4
Source File: StartCompensationHandler.java From Raincat with GNU Lesser General Public License v3.0 | 6 votes |
/** * 补偿的时候,不走分布式事务处理. * * @param point point 切点 * @param info 信息 * @return Object * @throws Throwable ex */ @Override public Object handler(final ProceedingJoinPoint point, final TxTransactionInfo info) throws Throwable { TxTransactionLocal.getInstance().setTxGroupId(CommonConstant.COMPENSATE_ID); PlatformTransactionManager platformTransactionManager = TransactionManagerHelper.getTransactionManager(info.getTransactionManager()); DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); TransactionStatus transactionStatus = platformTransactionManager.getTransaction(def); try { final Object proceed = point.proceed(); platformTransactionManager.commit(transactionStatus); return proceed; } catch (Throwable e) { platformTransactionManager.rollback(transactionStatus); throw e; } finally { TxTransactionLocal.getInstance().removeTxGroupId(); CompensationLocal.getInstance().removeCompensationId(); } }
Example 5
Source File: ChainedTransactionManager.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * * {@inheritDoc} */ public void rollback( TransactionStatus status ) { for ( PlatformTransactionManager dataSourceManager : _transactionManagers ) { try { dataSourceManager.rollback( ( ( (MultiTransactionStatus) status ).getTransactionStatus( dataSourceManager ) ) ); } catch( Exception ex ) { _log.error( ex.getMessage( ), ex ); } } if ( ( (MultiTransactionStatus) status ).isNewSynchonization( ) ) { TransactionSynchronizationManager.clear( ); } }
Example 6
Source File: MicroServiceTemplateSupport.java From nh-micro with Apache License 2.0 | 6 votes |
public Object execGroovyRetObjByDbTranNest(String groovyName, String methodName, Integer nestDef, Object... paramArray) throws Exception{ /* MicroMetaDao microDao=MicroMetaDao.getInstance(dbName,dbType); DataSource dataSource=microDao.getMicroDataSource(); PlatformTransactionManager transactionManager=new DataSourceTransactionManager(dataSource);*/ PlatformTransactionManager transactionManager=MicroTranManagerHolder.getTransactionManager(dbName); DefaultTransactionDefinition def =new DefaultTransactionDefinition(); def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_COMMITTED); if(nestDef==null){ nestDef=TransactionDefinition.PROPAGATION_REQUIRED; } def.setPropagationBehavior(nestDef); TransactionStatus status=transactionManager.getTransaction(def); try { Object retObj= GroovyExecUtil.execGroovyRetObj(groovyName, methodName, paramArray); transactionManager.commit(status); return retObj; } catch(Exception ex) { transactionManager.rollback(status); throw ex; } }
Example 7
Source File: SampleDataLoader.java From sakai with Educational Community License v2.0 | 6 votes |
public void init() { log.info("Initializing " + getClass().getName()); if(cmAdmin == null) { return; } if(loadSampleData) { loginToSakai(); PlatformTransactionManager tm = (PlatformTransactionManager)beanFactory.getBean("org.sakaiproject.springframework.orm.hibernate.GlobalTransactionManager"); DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); TransactionStatus status = tm.getTransaction(def); try { load(); } catch (Exception e) { log.error("Unable to load CM data: " + e); tm.rollback(status); } finally { if(!status.isCompleted()) { tm.commit(status); } } logoutFromSakai(); } else { if(log.isInfoEnabled()) log.info("Skipped CM data load"); } }
Example 8
Source File: MicroServiceTemplateSupport.java From nh-micro with Apache License 2.0 | 6 votes |
public Object execGroovyRetObjByDbTran(String groovyName, String methodName, Object... paramArray) throws Exception{ /* MicroMetaDao microDao=MicroMetaDao.getInstance(dbName,dbType); DataSource dataSource=microDao.getMicroDataSource(); PlatformTransactionManager transactionManager=new DataSourceTransactionManager(dataSource);*/ PlatformTransactionManager transactionManager=MicroTranManagerHolder.getTransactionManager(dbName); DefaultTransactionDefinition def =new DefaultTransactionDefinition(); def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_COMMITTED); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); TransactionStatus status=transactionManager.getTransaction(def); try { Object retObj= GroovyExecUtil.execGroovyRetObj(groovyName, methodName, paramArray); transactionManager.commit(status); return retObj; } catch(Exception ex) { transactionManager.rollback(status); throw ex; } }
Example 9
Source File: MicroServiceTemplateSupport.java From nh-micro with Apache License 2.0 | 6 votes |
public Object execGroovyRetObjByDbTranNest(String groovyName, String methodName, Integer nestDef, Object... paramArray) throws Exception{ /* MicroMetaDao microDao=MicroMetaDao.getInstance(dbName,dbType); DataSource dataSource=microDao.getMicroDataSource(); PlatformTransactionManager transactionManager=new DataSourceTransactionManager(dataSource);*/ PlatformTransactionManager transactionManager=MicroTranManagerHolder.getTransactionManager(dbName); DefaultTransactionDefinition def =new DefaultTransactionDefinition(); def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_COMMITTED); if(nestDef==null){ nestDef=TransactionDefinition.PROPAGATION_REQUIRED; } def.setPropagationBehavior(nestDef); TransactionStatus status=transactionManager.getTransaction(def); try { Object retObj= GroovyExecUtil.execGroovyRetObj(groovyName, methodName, paramArray); transactionManager.commit(status); return retObj; } catch(Exception ex) { transactionManager.rollback(status); throw ex; } }
Example 10
Source File: MicroServiceTemplateSupport.java From nh-micro with Apache License 2.0 | 5 votes |
public Integer getSeqByMysql(String seqKey){ PlatformTransactionManager transactionManager=MicroTranManagerHolder.getTransactionManager(dbName); DefaultTransactionDefinition def =new DefaultTransactionDefinition(); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); TransactionStatus status=transactionManager.getTransaction(def); try { String sql="select get_micro_seq('"+seqKey+"') as seq"; List retList=getInnerDao().queryObjJoinByCondition(sql); if(retList==null){ transactionManager.commit(status); return null; } Map retMap=(Map) retList.get(0); Integer seq=(Integer) retMap.get("seq"); transactionManager.commit(status); return seq; } catch(Exception ex) { transactionManager.rollback(status); throw new RuntimeException("getseq error",ex); } }
Example 11
Source File: PayrateImportServiceImpl.java From kfs with GNU Affero General Public License v3.0 | 5 votes |
/** * If retrieving budget locks fails, this method rolls back previous changes * */ protected void doRollback() { PlatformTransactionManager transactionManager = SpringContext.getBean(PlatformTransactionManager.class); DefaultTransactionDefinition defaultTransactionDefinition = new DefaultTransactionDefinition(); TransactionStatus transactionStatus = transactionManager.getTransaction(defaultTransactionDefinition); transactionManager.rollback( transactionStatus ); }
Example 12
Source File: MicroServiceTemplateSupport.java From nh-micro with Apache License 2.0 | 5 votes |
public Integer getSeqByMysql(String seqKey){ PlatformTransactionManager transactionManager=MicroTranManagerHolder.getTransactionManager(dbName); DefaultTransactionDefinition def =new DefaultTransactionDefinition(); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); TransactionStatus status=transactionManager.getTransaction(def); try { String sql="select get_micro_seq('"+seqKey+"') as seq"; List retList=getInnerDao().queryObjJoinByCondition(sql); if(retList==null){ transactionManager.commit(status); return null; } Map retMap=(Map) retList.get(0); Integer seq=(Integer) retMap.get("seq"); transactionManager.commit(status); return seq; } catch(Exception ex) { transactionManager.rollback(status); throw new RuntimeException("getseq error",ex); } }
Example 13
Source File: MicroServiceTemplateSupport.java From nh-micro with Apache License 2.0 | 5 votes |
public void dbTranNestRollbackAndThrow() throws Exception{ PlatformTransactionManager transactionManager=MicroTranManagerHolder.getTransactionManager(dbName); DefaultTransactionDefinition def =new DefaultTransactionDefinition(); def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_COMMITTED); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); TransactionStatus status=transactionManager.getTransaction(def); transactionManager.rollback(status); throw new RuntimeException("dbTranNestRollbackAndThrow"); }
Example 14
Source File: MicroServiceTemplateSupport.java From nh-micro with Apache License 2.0 | 5 votes |
public void dbTranNestRollback() throws Exception{ PlatformTransactionManager transactionManager=MicroTranManagerHolder.getTransactionManager(dbName); DefaultTransactionDefinition def =new DefaultTransactionDefinition(); def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_COMMITTED); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); TransactionStatus status=transactionManager.getTransaction(def); transactionManager.rollback(status); }
Example 15
Source File: AbstractPollingMessageListenerContainer.java From spring-analysis-note with MIT License | 5 votes |
/** * Perform a rollback, handling rollback exceptions properly. * @param status object representing the transaction * @param ex the thrown listener exception or error */ private void rollbackOnException(PlatformTransactionManager manager, TransactionStatus status, Throwable ex) { logger.debug("Initiating transaction rollback on listener exception", ex); try { manager.rollback(status); } catch (RuntimeException ex2) { logger.error("Listener exception overridden by rollback exception", ex); throw ex2; } catch (Error err) { logger.error("Listener exception overridden by rollback error", ex); throw err; } }
Example 16
Source File: MicroServiceTemplateSupport.java From nh-micro with Apache License 2.0 | 5 votes |
public void dbTranNestRollbackAndThrow() throws Exception{ PlatformTransactionManager transactionManager=MicroTranManagerHolder.getTransactionManager(dbName); DefaultTransactionDefinition def =new DefaultTransactionDefinition(); def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_COMMITTED); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); TransactionStatus status=transactionManager.getTransaction(def); transactionManager.rollback(status); throw new RuntimeException("dbTranNestRollbackAndThrow"); }
Example 17
Source File: SpringTransaction.java From copper-engine with Apache License 2.0 | 5 votes |
public void run(PlatformTransactionManager transactionManager, DataSource dataSource, TransactionDefinition def) throws Exception { TransactionStatus txnStatus = transactionManager.getTransaction(def); try { Connection con = DataSourceUtils.getConnection(dataSource); try { execute(con); } finally { DataSourceUtils.releaseConnection(con, dataSource); } } catch (Exception e) { transactionManager.rollback(txnStatus); throw e; } transactionManager.commit(txnStatus); }
Example 18
Source File: MultipleDataSourcesTransactionManager.java From cobarclient with Apache License 2.0 | 5 votes |
@Override protected void doRollback(DefaultTransactionStatus status) throws TransactionException { @SuppressWarnings("unchecked") List<DefaultTransactionStatus> list = (List<DefaultTransactionStatus>) status.getTransaction(); logger.info("prepare to rollback transactions on multiple data sources."); Validate.isTrue(list.size() <= this.getTransactionManagers().size()); TransactionException lastException = null; for(int i=list.size()-1; i>=0; i--){ PlatformTransactionManager transactionManager=this.getTransactionManagers().get(i); TransactionStatus localTransactionStatus=list.get(i); try { transactionManager.rollback(localTransactionStatus); } catch (TransactionException e) { // Log exception and try to complete rollback lastException = e; logger.error("error occured when rolling back the transaction. \n{}",e); } } if (lastException != null) { throw lastException; } }
Example 19
Source File: InsideCompensationHandler.java From Raincat with GNU Lesser General Public License v3.0 | 5 votes |
/** * 处理补偿内嵌的远程方法的时候,不提交,只调用. * * @param point point 切点 * @param info 信息 * @return Object * @throws Throwable 异常 */ @Override public Object handler(final ProceedingJoinPoint point, final TxTransactionInfo info) throws Throwable { DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); PlatformTransactionManager platformTransactionManager = TransactionManagerHelper.getTransactionManager(info.getTransactionManager()); TransactionStatus transactionStatus = platformTransactionManager.getTransaction(def); try { return point.proceed(); } finally { platformTransactionManager.rollback(transactionStatus); } }
Example 20
Source File: AbstractPollingMessageListenerContainer.java From java-technology-stack with MIT License | 5 votes |
/** * Perform a rollback, handling rollback exceptions properly. * @param status object representing the transaction * @param ex the thrown listener exception or error */ private void rollbackOnException(PlatformTransactionManager manager, TransactionStatus status, Throwable ex) { logger.debug("Initiating transaction rollback on listener exception", ex); try { manager.rollback(status); } catch (RuntimeException ex2) { logger.error("Listener exception overridden by rollback exception", ex); throw ex2; } catch (Error err) { logger.error("Listener exception overridden by rollback error", ex); throw err; } }