本文整理汇总了Java中com.atomikos.icatch.jta.UserTransactionManager.getTransaction方法的典型用法代码示例。如果您正苦于以下问题:Java UserTransactionManager.getTransaction方法的具体用法?Java UserTransactionManager.getTransaction怎么用?Java UserTransactionManager.getTransaction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.atomikos.icatch.jta.UserTransactionManager
的用法示例。
在下文中一共展示了UserTransactionManager.getTransaction方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTransactionAssistant
import com.atomikos.icatch.jta.UserTransactionManager; //导入方法依赖的package包/类
/** before calling this method, please ensure you have called {@link TransactionConfigurator#setup(String, CommitRollbackCallback)} */
@Override
public TransactionAssistant getTransactionAssistant() throws ResourceException {
//enlist a new resource into the transaction. it will be delisted, when its closed.
final CommitRollbackCallback commitRollbackCallback = TransactionConfigurator.getCommitRollbackCallback(jndiName);
MicroserviceXAResource ms = new MicroserviceXAResource(jndiName, commitRollbackCallback);
UserTransactionManager utm = getTM();
try {
if(utm.getStatus() == Status.STATUS_NO_TRANSACTION){
throw new ResourceException("no transaction found. please start one before getting the transaction assistant. status was: " + utm.getStatus());
}
Transaction tx = utm.getTransaction();
tx.enlistResource(ms);
return new AtomikosTransactionAssistantImpl(ms);
} catch (Exception e) {
throw new ResourceException("Unable to get transaction status", e);
}
}
示例2: close
import com.atomikos.icatch.jta.UserTransactionManager; //导入方法依赖的package包/类
@Override
public void close() {
UserTransactionManager utm = getTransactionManager();
try {
if(utm.getStatus() == Status.STATUS_NO_TRANSACTION){
throw new RuntimeException("no transaction found. please start one before getting the transaction assistant. status was: " + utm.getStatus());
}
Transaction tx = utm.getTransaction();
tx.delistResource(ms, ms.getUnderlyingConnection().wasExecuteSuccessful() ? XAResource.TMSUCCESS : XAResource.TMFAIL);
} catch (Exception e) {
throw new RuntimeException("Unable to delist resource from transaction", e);
}
}