本文整理了Java中javax.transaction.Transaction.enlistResource()
方法的一些代码示例,展示了Transaction.enlistResource()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Transaction.enlistResource()
方法的具体详情如下:
包路径:javax.transaction.Transaction
类名称:Transaction
方法名:enlistResource
[英]Enlist an XA resource with this transaction.
[中]使用此事务登记XA资源。
代码示例来源:origin: spring-projects/spring-framework
@Override
public boolean enlistResource(XAResource xaRes) throws RollbackException, SystemException {
return this.transactionManager.getTransaction().enlistResource(xaRes);
}
代码示例来源:origin: spring-projects/spring-framework
public void beginTransaction() throws Exception {
if (transactionFactory != null && this.xaResource != null) {
this.transaction = transactionFactory.createTransaction(transactionName, transactionTimeout);
this.transaction.enlistResource(this.xaResource);
}
}
代码示例来源:origin: org.springframework/spring-tx
@Override
public boolean enlistResource(XAResource xaRes) throws RollbackException, SystemException {
return this.transactionManager.getTransaction().enlistResource(xaRes);
}
代码示例来源:origin: apache/incubator-shardingsphere
@Override
@SneakyThrows
public void enlistResource(final SingleXAResource xaResource) {
transactionManager.getTransaction().enlistResource(xaResource);
}
代码示例来源:origin: apache/ignite
/** {@inheritDoc} */
@Override public boolean enlistResource(final XAResource xaRes) throws RollbackException, IllegalStateException,
SystemException {
if (xaRes == null)
return false;
// final XAResource res = new IgniteOnePhaseXAResource(xaRes);
Object ibmProxy = Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
new Class[] {onePhaseXAResourceCls},
new InvocationHandler() {
@Override public Object invoke(Object proxy, Method mtd, Object[] args) throws Throwable {
return mtd.invoke(xaRes, args);
}
});
return tx.enlistResource((XAResource)ibmProxy);
}
代码示例来源:origin: org.springframework/spring-tx
public void beginTransaction() throws Exception {
if (transactionFactory != null && this.xaResource != null) {
this.transaction = transactionFactory.createTransaction(transactionName, transactionTimeout);
this.transaction.enlistResource(this.xaResource);
}
}
代码示例来源:origin: apache/geode
void registerTranxConnection(XAConnection xaConn) throws Exception {
try {
synchronized (this) {
if (transManager == null) {
transManager = JNDIInvoker.getTransactionManager();
}
}
Transaction txn = transManager.getTransaction();
if (txn != null) {
XAResource xar = xaConn.getXAResource();
txn.enlistResource(xar);
// Add in the Map after successful registration of XAResource
this.xaResourcesMap.put(xaConn, xar);
}
} catch (Exception ex) {
Exception e = new Exception(
String.format(
"GemFireTransactionDataSource-registerTranxConnection(). Exception in registering the XAResource with the Transaction.Exception occurred= %s",
ex));
e.initCause(ex);
throw e;
}
}
代码示例来源:origin: wildfly/wildfly
public boolean enlistResource(final XAResource xaRes) throws RollbackException, IllegalStateException, SystemException {
Assert.checkNotNullParam("xaRes", xaRes);
final int estimatedRemainingTime = max(1, getEstimatedRemainingTime());
try {
xaRes.setTransactionTimeout(estimatedRemainingTime);
} catch (XAException e) {
throw Log.log.setTimeoutFailed(estimatedRemainingTime, e);
}
return transaction.enlistResource(xaRes);
}
代码示例来源:origin: wildfly/wildfly
@Override
public void beforeDelivery(Method method) throws NoSuchMethodException, ResourceException {
// JCA 1.6 FR 13.5.6
// The application server must set the thread context class loader to the endpoint
// application class loader during the beforeDelivery call.
previousClassLoader = WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(getApplicationClassLoader());
try {
final TransactionManager tm = getTransactionManager();
// TODO: in violation of JCA 1.6 FR 13.5.9?
previousTx = tm.suspend();
boolean isTransacted = service.isDeliveryTransacted(method);
if (isTransacted) {
tm.begin();
currentTx = tm.getTransaction();
if (xaRes != null)
currentTx.enlistResource(xaRes);
}
} catch (Throwable t) {
throw new ApplicationServerInternalException(t);
} finally {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(previousClassLoader);
}
}
代码示例来源:origin: hibernate/hibernate-orm
@Override
public Connection getConnection() throws SQLException {
Transaction currentTransaction = findCurrentTransaction();
try {
if ( currentTransaction == null ) {
// this block handles non enlisted connections ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Connection connection = delegate.getConnection();
nonEnlistedConnections.add( connection );
return connection;
}
// this portion handles enlisted connections ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Connection connection = (Connection) TestingJtaPlatformImpl.synchronizationRegistry().getResource(
CONNECTION_KEY
);
if ( connection == null ) {
connection = delegate.getConnection();
TestingJtaPlatformImpl.synchronizationRegistry().putResource( CONNECTION_KEY, connection );
XAResourceWrapper xaResourceWrapper = new XAResourceWrapper( this, connection );
currentTransaction.enlistResource( xaResourceWrapper );
}
return connection;
}
catch (SQLException e) {
throw e;
}
catch (Exception e) {
throw new SQLException(e);
}
}
代码示例来源:origin: ehcache/ehcache3
xaResource = new EhcacheXAResource<>(underlyingStore, journal, transactionContextFactory);
transactionManagerWrapper.registerXAResource(uniqueXAResourceId, xaResource);
transactionManagerWrapper.getTransactionManager().getTransaction().enlistResource(xaResource);
xaResources.put(transaction, xaResource);
final EhcacheXAResource<K, V> finalXaResource = xaResource;
代码示例来源:origin: apache/geode
txn.enlistResource(xar);
java.util.List resList = (List) xalistThreadLocal.get();
if (resList.size() == 0) {
代码示例来源:origin: apache/geode
txn.enlistResource(xar);
代码示例来源:origin: apache/ignite
else if (!jtaTx.enlistResource(rsrc))
throw new IgniteCheckedException("Failed to enlist XA resource to JTA user transaction.");
代码示例来源:origin: net.sf.ehcache/ehcache
/**
* {@inheritDoc}
*/
public XATransactionContext createTransactionContext() throws SystemException, RollbackException {
XATransactionContext ctx = getCurrentTransactionContext();
if (ctx != null) {
return ctx;
}
Transaction transaction = txnManager.getTransaction();
LOG.debug("enlisting {} in {}", this, transaction);
transaction.enlistResource(this);
// currentXid is set by a call to start() which itself is called by transaction.enlistResource(this)
if (currentXid == null) {
throw new CacheException("enlistment of XAResource of cache named '" + getCacheName() +
"' did not end up calling XAResource.start()");
}
ctx = xidToContextMap.get(currentXid);
if (ctx == null) {
LOG.debug("creating new context for XID [{}]", currentXid);
ctx = new XATransactionContext(underlyingStore);
xidToContextMap.put(currentXid, ctx);
}
return ctx;
}
代码示例来源:origin: net.sf.ehcache/ehcache
transactionController.getCurrentTransactionContext().getTransactionId(), transactionManagerLookup);
transactionManagerLookup.register(xaRes, false);
tx.enlistResource(xaRes);
} else {
tx.registerSynchronization(new JtaLocalEhcacheSynchronization(transactionController,
代码示例来源:origin: org.infinispan/infinispan-core
@Override
public void register(TransactionManager transactionManager) throws Exception {
Transaction transaction = transactionManager.getTransaction();
transaction.enlistResource(new FailXaResource(failMode));
}
}
代码示例来源:origin: org.infinispan/infinispan-core
protected void startTx() throws Exception {
tm(cache).begin();
cache.put(key(), "value");
tx = tm(cache).getTransaction();
tx.enlistResource(new XAResourceAdapter()); // this is to force 2PC and to prevent transaction managers attempting to optimise the call to a 1PC.
txsStarted.countDown();
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testCommit() throws Exception {
assertCommitRollback(0, 0, txInterceptor);
tm.begin();
//enlist another resource adapter to force TM to execute 2PC (otherwise 1PC)
tm.getTransaction().enlistResource(new XAResourceAdapter());
assertCommitRollback(0, 0, txInterceptor);
cache1.put("key", "value");
assertCommitRollback(0, 0, txInterceptor);
tm.commit();
assertCommitRollback(1, 0, txInterceptor);
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testRemoteCommit() throws Exception {
assertCommitRollback(0, 0, txInterceptor2);
tm.begin();
assertCommitRollback(0, 0, txInterceptor2);
//enlist another resource adapter to force TM to execute 2PC (otherwise 1PC)
tm.getTransaction().enlistResource(new XAResourceAdapter());
cache2.put("key", "value");
assertCommitRollback(0, 0, txInterceptor2);
tm.commit();
assertCommitRollback(1, 0, txInterceptor2);
}
内容来源于网络,如有侵权,请联系作者删除!