本文整理汇总了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);
}