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