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