當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。