当前位置: 首页>>代码示例>>Java>>正文


Java DefaultTransactionDefinition.setPropagationBehavior方法代码示例

本文整理汇总了Java中org.springframework.transaction.support.DefaultTransactionDefinition.setPropagationBehavior方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultTransactionDefinition.setPropagationBehavior方法的具体用法?Java DefaultTransactionDefinition.setPropagationBehavior怎么用?Java DefaultTransactionDefinition.setPropagationBehavior使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.transaction.support.DefaultTransactionDefinition的用法示例。


在下文中一共展示了DefaultTransactionDefinition.setPropagationBehavior方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execGroovyRetObjByDbTran

import org.springframework.transaction.support.DefaultTransactionDefinition; //导入方法依赖的package包/类
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;
	    }
		
	}
 
开发者ID:jeffreyning,项目名称:nh-micro,代码行数:24,代码来源:MicroServiceTemplateSupport.java

示例2: handler

import org.springframework.transaction.support.DefaultTransactionDefinition; //导入方法依赖的package包/类
/**
 * 补偿的时候,不走分布式事务处理
 *
 * @param point point 切点
 * @param info  信息
 * @return Object
 * @throws Throwable
 */
@Override
public Object handler(ProceedingJoinPoint point, TxTransactionInfo info) throws Throwable {
    TxTransactionLocal.getInstance().setTxGroupId(CommonConstant.COMPENSATE_ID);
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
    TransactionStatus transactionStatus = platformTransactionManager.getTransaction(def);
    try {
        final Object proceed = point.proceed();
        platformTransactionManager.commit(transactionStatus);
        LogUtil.info(LOGGER, "补偿事务执行成功!事务组id为:{}", info::getTxGroupId);
        return proceed;
    } catch (Throwable e) {
        LogUtil.info(LOGGER, "补偿事务执行失败!事务组id为:{}", info::getTxGroupId);
        platformTransactionManager.rollback(transactionStatus);
        throw e;
    } finally {
        TxTransactionLocal.getInstance().removeTxGroupId();
        CompensationLocal.getInstance().removeCompensationId();
    }
}
 
开发者ID:yu199195,项目名称:happylifeplat-transaction,代码行数:29,代码来源:StartCompensationHandler.java

示例3: execGroovyRetObjByDbTranNest

import org.springframework.transaction.support.DefaultTransactionDefinition; //导入方法依赖的package包/类
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;
	    }
		
	}
 
开发者ID:jeffreyning,项目名称:nh-micro,代码行数:27,代码来源:MicroServiceTemplateSupport.java

示例4: propagationMandatoryFailsInCaseOfNoExistingTransaction

import org.springframework.transaction.support.DefaultTransactionDefinition; //导入方法依赖的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
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:WebSphereUowTransactionManagerTests.java

示例5: propagationNeverFailsInCaseOfExistingTransaction

import org.springframework.transaction.support.DefaultTransactionDefinition; //导入方法依赖的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
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:WebSphereUowTransactionManagerTests.java

示例6: propagationNestedFailsInCaseOfExistingTransaction

import org.springframework.transaction.support.DefaultTransactionDefinition; //导入方法依赖的package包/类
@Test
public void propagationNestedFailsInCaseOfExistingTransaction() {
	MockUOWManager manager = new MockUOWManager();
	manager.setUOWStatus(UOWManager.UOW_STATUS_ACTIVE);
	WebSphereUowTransactionManager ptm = new WebSphereUowTransactionManager(manager);
	DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
	definition.setPropagationBehavior(TransactionDefinition.PROPAGATION_NESTED);

	try {
		ptm.execute(definition, new TransactionCallback<String>() {
			@Override
			public String doInTransaction(TransactionStatus status) {
				return "result";
			}
		});
		fail("Should have thrown NestedTransactionNotSupportedException");
	}
	catch (NestedTransactionNotSupportedException ex) {
		// expected
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:WebSphereUowTransactionManagerTests.java

示例7: TransactionImpl

import org.springframework.transaction.support.DefaultTransactionDefinition; //导入方法依赖的package包/类
public TransactionImpl(PlatformTransactionManager transactionManager, PersistenceImpl persistence, boolean join,
                       @Nullable TransactionParams params, String storeName) {
    this.tm = transactionManager;
    this.persistence = persistence;
    this.storeName = storeName;

    td = new DefaultTransactionDefinition();
    if (join)
        td.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    else
        td.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);

    if (params != null) {
        if (params.getTimeout() != 0)
            td.setTimeout(params.getTimeout());
        if (params.isReadOnly())
            td.setReadOnly(true);
    }

    ts = tm.getTransaction(td);

    persistence.registerSynchronizations(storeName);
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:24,代码来源:TransactionImpl.java

示例8: doInTransaction

import org.springframework.transaction.support.DefaultTransactionDefinition; //导入方法依赖的package包/类
/**
 * @param task
 *            Set the method to run in a transaction
 * @return the object returned by the callable method
 * @throws Exception
 *             if there is a problem running the method
 */
protected final Object doInTransaction(final Callable task)
		throws Exception {
	DefaultTransactionDefinition transactionDefinition = new DefaultTransactionDefinition();
	transactionDefinition.setName("test");
	transactionDefinition
	.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
	TransactionStatus status = transactionManager
			.getTransaction(transactionDefinition);
	Object value = null;
	try {
		value = task.call();
	} catch (Exception ex) {
		transactionManager.rollback(status);
		throw ex;
	}
	transactionManager.commit(status);
	return value;
}
 
开发者ID:RBGKew,项目名称:eMonocot,代码行数:26,代码来源:AbstractPersistenceTest.java

示例9: beforeJob

import org.springframework.transaction.support.DefaultTransactionDefinition; //导入方法依赖的package包/类
@Override
public void beforeJob(JobExecution je) { 
   Date startTime = Calendar.getInstance().getTime();
   JobParameters jobParams = je.getJobParameters();
   Integer defId = Integer.valueOf(jobParams.getString("cohort_definition_id"));
   Integer sourceId = Integer.valueOf(jobParams.getString("source_id"));
	
   DefaultTransactionDefinition initTx = new DefaultTransactionDefinition();
   initTx.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
   TransactionStatus initStatus = this.transactionTemplate.getTransactionManager().getTransaction(initTx);
   CohortDefinition df = this.cohortDefinitionRepository.findOne(defId);
   CohortGenerationInfo info = findBySourceId(df.getGenerationInfoList(), sourceId);
   info.setIsValid(false);
   info.setStartTime(startTime);
   info.setStatus(GenerationStatus.RUNNING);    
   this.cohortDefinitionRepository.save(df);
   this.transactionTemplate.getTransactionManager().commit(initStatus);	
}
 
开发者ID:OHDSI,项目名称:WebAPI,代码行数:19,代码来源:GenerationJobExecutionListener.java

示例10: testPropagationMandatoryFailsInCaseOfNoExistingTransaction

import org.springframework.transaction.support.DefaultTransactionDefinition; //导入方法依赖的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
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:20,代码来源:WebSphereUowTransactionManagerTests.java

示例11: testPropagationNeverFailsInCaseOfExistingTransaction

import org.springframework.transaction.support.DefaultTransactionDefinition; //导入方法依赖的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
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:21,代码来源:WebSphereUowTransactionManagerTests.java

示例12: init

import org.springframework.transaction.support.DefaultTransactionDefinition; //导入方法依赖的package包/类
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");
	}
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:27,代码来源:SampleDataLoader.java

示例13: testDeleteTransactionsByProviderId

import org.springframework.transaction.support.DefaultTransactionDefinition; //导入方法依赖的package包/类
@Transactional(propagation = Propagation.SUPPORTS)
public void testDeleteTransactionsByProviderId() {
    int txTransactionId = 1;
    String providerId = new String("provider");
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setPropagationBehavior(Propagation.REQUIRES_NEW.value());
    TransactionStatus status = transactionManager.getTransaction(def);
    dbeTransactionDAO.deleteTransactionsByProviderId(providerId);
    transactionManager.commit(status);
    List<DbeTransaction> listDbeTr = dbeTransactionDAO.getTransactionsByProviderId(providerId);

    if (listDbeTr != null && listDbeTr.size() > 0) {
        DbeTransactionDaoImplTest.LOGGER.debug("looking result list data....");
        DbeTransactionDaoImplTest.LOGGER.error("Obtained:" + listDbeTr.get(0).getTxTransactionId());
        Assert.assertTrue("0 data obtained ", listDbeTr.get(0).getTxTransactionId() == txTransactionId);
    } else {
        DbeTransactionDaoImplTest.LOGGER.debug("Obtained 0 data is not possible with datatest values");
        Assert.assertTrue("0 data obtained ", true);
    }

}
 
开发者ID:conwetlab,项目名称:fiware-rss,代码行数:22,代码来源:DbeTransactionDaoImplTest.java

示例14: handler

import org.springframework.transaction.support.DefaultTransactionDefinition; //导入方法依赖的package包/类
/**
 * 处理补偿内嵌的远程方法的时候,不提交,只调用
 *
 * @param point point 切点
 * @param info  信息
 * @return Object
 * @throws Throwable 异常
 */
@Override
public Object handler(ProceedingJoinPoint point, TxTransactionInfo info) throws Throwable {

    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    TransactionStatus transactionStatus = platformTransactionManager.getTransaction(def);
    try {
        return point.proceed();
    } finally {
        platformTransactionManager.rollback(transactionStatus);
    }

}
 
开发者ID:yu199195,项目名称:happylifeplat-transaction,代码行数:22,代码来源:InsideCompensationHandler.java

示例15: assertExistingTransaction

import org.springframework.transaction.support.DefaultTransactionDefinition; //导入方法依赖的package包/类
/**
 * Vérifie qu'une transaction est ouverte
 * Correspond au @Transaction(REQUIRED)
 */
public void assertExistingTransaction() {
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_MANDATORY);

    // Va envoyer une Exception s'il n'y a pas de Transaction ouverte
    getTransactionManager().getTransaction(def);
}
 
开发者ID:shared-vd,项目名称:tipi-engine,代码行数:12,代码来源:TxTemplate.java


注:本文中的org.springframework.transaction.support.DefaultTransactionDefinition.setPropagationBehavior方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。