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


Java DefaultTransactionDefinition类代码示例

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


DefaultTransactionDefinition类属于org.springframework.transaction.support包,在下文中一共展示了DefaultTransactionDefinition类的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: invoke

import org.springframework.transaction.support.DefaultTransactionDefinition; //导入依赖的package包/类
@Override
public EasyTransResult invoke(EasyTransFilterChain filterChain, Map<String, Object> header,
		EasyTransRequest<?, ?> request) {

	Integer pTrxStatus = MetaDataFilter.getMetaData(EasytransConstant.CallHeadKeys.PARENT_TRANSACTION_STATUS);
	if(!pTrxStatus.equals(com.yiqiniu.easytrans.datasource.TransStatusLogger.TransactionStatus.UNKNOWN)){
		// start transaction to update 
		PlatformTransactionManager transactionManager = getTransactionManager(filterChain, request);
		TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager,
				new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED));
		TransactionId pTrxId = MetaDataFilter.getMetaData(EasytransConstant.CallHeadKeys.PARENT_TRX_ID_KEY);
		transactionTemplate.execute(new TransactionCallback<Object>() {
			@Override
			public Object doInTransaction(TransactionStatus status) {
				TransactionId trxId = pTrxId;
				transStatusLogger.updateExecuteFlagForSlaveTrx(trxId, request, pTrxStatus);
				return null;
			}
		});
		boolean commited = pTrxStatus.equals(com.yiqiniu.easytrans.datasource.TransStatusLogger.TransactionStatus.COMMITTED);
		//may be concurrent,but it's ok
		easyTransSynchronizer.cascadeExecuteCachedTransaction(pTrxId, commited);
	}
	
	return filterChain.invokeFilterChain(header, request);
}
 
开发者ID:QNJR-GROUP,项目名称:EasyTransaction,代码行数:27,代码来源:ParentTrxStatusUpdateFilter.java

示例4: addBook

import org.springframework.transaction.support.DefaultTransactionDefinition; //导入依赖的package包/类
@Override
public boolean addBook(Book book) {
	// TODO Auto-generated method stub
	TransactionDefinition definition = new DefaultTransactionDefinition();
	TransactionStatus transactionStatus = transactionManager.getTransaction(definition);

	if (searchBook(book.getISBN()).getISBN() == 98564567l) {
		System.out.println("no book");
		int rows = bookDAO.addBook(book);
		
		if (rows > 0) {
			transactionManager.commit(transactionStatus);
			return true;
		}
	}
	
	return false;
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-5.0,代码行数:19,代码来源:BookServiceImpl.java

示例5: resolveSpecifiedLookupKey

import org.springframework.transaction.support.DefaultTransactionDefinition; //导入依赖的package包/类
/**
 * Supports Integer values for the isolation level constants
 * as well as isolation level names as defined on the
 * {@link org.springframework.transaction.TransactionDefinition TransactionDefinition interface}.
 */
@Override
protected Object resolveSpecifiedLookupKey(Object lookupKey) {
	if (lookupKey instanceof Integer) {
		return lookupKey;
	}
	else if (lookupKey instanceof String) {
		String constantName = (String) lookupKey;
		if (!constantName.startsWith(DefaultTransactionDefinition.PREFIX_ISOLATION)) {
			throw new IllegalArgumentException("Only isolation constants allowed");
		}
		return constants.asNumber(constantName);
	}
	else {
		throw new IllegalArgumentException(
				"Invalid lookup key - needs to be isolation level Integer or isolation level name String: " + lookupKey);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:IsolationLevelDataSourceRouter.java

示例6: 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

示例7: deleteBook

import org.springframework.transaction.support.DefaultTransactionDefinition; //导入依赖的package包/类
@Override
public boolean deleteBook(long ISBN) {
	// TODO Auto-generated method stub
	TransactionDefinition definition = new DefaultTransactionDefinition();
	TransactionStatus transactionStatus = transactionManager.getTransaction(definition);

	if (searchBook(ISBN).getISBN() != 98564567l) {
		boolean deleted = bookDAO.deleteBook(ISBN);

		if (deleted) {
			transactionManager.commit(transactionStatus);
			return true;
		}
	}
	return false;
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-5.0,代码行数:17,代码来源:BookServiceImpl.java

示例8: noExistingTransaction

import org.springframework.transaction.support.DefaultTransactionDefinition; //导入依赖的package包/类
@Test
public void noExistingTransaction() {
	PlatformTransactionManager tm = new TestTransactionManager(false, true);
	DefaultTransactionStatus status1 = (DefaultTransactionStatus)
			tm.getTransaction(new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_SUPPORTS));
	assertTrue("Must not have transaction", status1.getTransaction() == null);

	DefaultTransactionStatus status2 = (DefaultTransactionStatus)
			tm.getTransaction(new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED));
	assertTrue("Must have transaction", status2.getTransaction() != null);
	assertTrue("Must be new transaction", status2.isNewTransaction());

	try {
		tm.getTransaction(new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_MANDATORY));
		fail("Should not have thrown NoTransactionException");
	}
	catch (IllegalTransactionStateException ex) {
		// expected
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:TransactionSupportTests.java

示例9: existingTransaction

import org.springframework.transaction.support.DefaultTransactionDefinition; //导入依赖的package包/类
@Test
public void existingTransaction() {
	PlatformTransactionManager tm = new TestTransactionManager(true, true);
	DefaultTransactionStatus status1 = (DefaultTransactionStatus)
			tm.getTransaction(new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_SUPPORTS));
	assertTrue("Must have transaction", status1.getTransaction() != null);
	assertTrue("Must not be new transaction", !status1.isNewTransaction());

	DefaultTransactionStatus status2 = (DefaultTransactionStatus)
			tm.getTransaction(new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED));
	assertTrue("Must have transaction", status2.getTransaction() != null);
	assertTrue("Must not be new transaction", !status2.isNewTransaction());

	try {
		DefaultTransactionStatus status3 = (DefaultTransactionStatus)
				tm.getTransaction(new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_MANDATORY));
		assertTrue("Must have transaction", status3.getTransaction() != null);
		assertTrue("Must not be new transaction", !status3.isNewTransaction());
	}
	catch (NoTransactionException ex) {
		fail("Should not have thrown NoTransactionException");
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:TransactionSupportTests.java

示例10: jtaTransactionManagerWithDoubleCommit

import org.springframework.transaction.support.DefaultTransactionDefinition; //导入依赖的package包/类
@Test
public void jtaTransactionManagerWithDoubleCommit() throws Exception {
	UserTransaction ut = mock(UserTransaction.class);
	given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION,
			Status.STATUS_ACTIVE, Status.STATUS_ACTIVE);

	JtaTransactionManager ptm = newJtaTransactionManager(ut);
	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
	TransactionStatus status = ptm.getTransaction(new DefaultTransactionDefinition());
	assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
	// first commit
	ptm.commit(status);
	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
	try {
		// second commit attempt
		ptm.commit(status);
		fail("Should have thrown IllegalTransactionStateException");
	}
	catch (IllegalTransactionStateException ex) {
		// expected
	}

	verify(ut).begin();
	verify(ut).commit();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:26,代码来源:JtaTransactionManagerTests.java

示例11: jtaTransactionManagerWithDoubleRollback

import org.springframework.transaction.support.DefaultTransactionDefinition; //导入依赖的package包/类
@Test
public void jtaTransactionManagerWithDoubleRollback() throws Exception {
	UserTransaction ut = mock(UserTransaction.class);
	given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE);

	JtaTransactionManager ptm = newJtaTransactionManager(ut);
	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
	TransactionStatus status = ptm.getTransaction(new DefaultTransactionDefinition());
	assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
	// first rollback
	ptm.rollback(status);
	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
	try {
		// second rollback attempt
		ptm.rollback(status);
		fail("Should have thrown IllegalTransactionStateException");
	}
	catch (IllegalTransactionStateException ex) {
		// expected
	}

	verify(ut).begin();
	verify(ut).rollback();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:JtaTransactionManagerTests.java

示例12: jtaTransactionManagerWithRollbackAndCommit

import org.springframework.transaction.support.DefaultTransactionDefinition; //导入依赖的package包/类
@Test
public void jtaTransactionManagerWithRollbackAndCommit() throws Exception {
	UserTransaction ut = mock(UserTransaction.class);
	given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE);

	JtaTransactionManager ptm = newJtaTransactionManager(ut);
	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
	TransactionStatus status = ptm.getTransaction(new DefaultTransactionDefinition());
	assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
	// first: rollback
	ptm.rollback(status);
	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
	try {
		// second: commit attempt
		ptm.commit(status);
		fail("Should have thrown IllegalTransactionStateException");
	}
	catch (IllegalTransactionStateException ex) {
		// expected
	}

	verify(ut).begin();
	verify(ut).rollback();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:JtaTransactionManagerTests.java

示例13: uowManagerFoundInJndi

import org.springframework.transaction.support.DefaultTransactionDefinition; //导入依赖的package包/类
@Test
public void uowManagerFoundInJndi() {
	MockUOWManager manager = new MockUOWManager();
	ExpectedLookupTemplate jndiTemplate =
			new ExpectedLookupTemplate(WebSphereUowTransactionManager.DEFAULT_UOW_MANAGER_NAME, manager);
	WebSphereUowTransactionManager ptm = new WebSphereUowTransactionManager();
	ptm.setJndiTemplate(jndiTemplate);
	ptm.afterPropertiesSet();

	DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
	assertEquals("result", ptm.execute(definition, new TransactionCallback<String>() {
		@Override
		public String doInTransaction(TransactionStatus status) {
			return "result";
		}
	}));

	assertEquals(UOWManager.UOW_TYPE_GLOBAL_TRANSACTION, manager.getUOWType());
	assertFalse(manager.getJoined());
	assertFalse(manager.getRollbackOnly());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:WebSphereUowTransactionManagerTests.java

示例14: 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

示例15: 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


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