本文整理匯總了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;
}
}
示例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();
}
}
示例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;
}
}
示例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
}
}
示例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
}
}
示例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
}
}
示例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);
}
示例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;
}
示例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);
}
示例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
}
}
示例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
}
}
示例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");
}
}
示例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);
}
}
示例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);
}
}
示例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);
}