本文整理了Java中javax.transaction.TransactionManager.suspend()
方法的一些代码示例,展示了TransactionManager.suspend()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TransactionManager.suspend()
方法的具体详情如下:
包路径:javax.transaction.TransactionManager
类名称:TransactionManager
方法名:suspend
[英]Suspend the association the calling thread has to a transaction, and return the suspended transaction. When returning from this method, the calling thread is no longer associated with a transaction.
[中]挂起调用线程与事务的关联,并返回挂起的事务。从该方法返回时,调用线程不再与事务关联。
代码示例来源:origin: wildfly/wildfly
@Override
public Object processInvocation(final InterceptorContext context) throws Exception {
TransactionManager tm = component.getTransactionManager();
int oldTimeout = getCurrentTransactionTimeout(component);
try {
Transaction oldTx = tm.suspend();
try {
return handleInvocation(context);
} finally {
if (oldTx != null) tm.resume(oldTx);
}
} finally {
tm.setTransactionTimeout(oldTimeout == -1 ? 0 : oldTimeout);
}
}
代码示例来源:origin: wildfly/wildfly
@Override
public TransactionBatch createBatch() {
if (this.tm == null) return NON_TX_BATCH;
TransactionBatch batch = getCurrentBatch();
try {
if ((batch != null) && (batch.getState() == Batch.State.ACTIVE)) {
return batch.interpose();
}
this.tm.suspend();
this.tm.begin();
Transaction tx = this.tm.getTransaction();
tx.registerSynchronization(CURRENT_BATCH_SYNCHRONIZATION);
batch = new InfinispanBatch(tx);
setCurrentBatch(batch);
return batch;
} catch (RollbackException | SystemException | NotSupportedException e) {
throw new CacheException(e);
}
}
代码示例来源:origin: wildfly/wildfly
tm.setTransactionTimeout(timeout);
try {
final Transaction suspended = tm.suspend();
try {
tm.begin();
final Transaction transaction = tm.suspend();
SimpleXid gtid = SimpleXid.of(getXid(transaction)).withoutBranch();
known.put(gtid, getEntryFor(transaction, gtid));
} catch (Throwable t) {
if (suspended != null) try {
tm.resume(suspended);
} catch (InvalidTransactionException e) {
e.addSuppressed(t);
代码示例来源:origin: spring-projects/spring-framework
@Test
public void jtaTransactionManagerWithPropagationRequiresNewAndAdapter() throws Exception {
TransactionManager tm = mock(TransactionManager.class);
Transaction tx = mock(Transaction.class);
given(tm.getStatus()).willReturn(Status.STATUS_ACTIVE);
given(tm.suspend()).willReturn(tx);
JtaTransactionManager ptm = newJtaTransactionManager(tm);
TransactionTemplate tt = new TransactionTemplate(ptm);
tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
tt.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
}
});
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
verify(tm).begin();
verify(tm).commit();
verify(tm).resume(tx);
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testPutIfAbsent() throws Throwable {
Object k1 = getKeyForCache(0);
tm(0).begin();
assertNull(cache(0).putIfAbsent(k1, "v1"));
Transaction suspendedTx = tm(0).suspend();
cache(0).put(k1, "v2");
assertEquals(cache(0).get(k1), "v2");
assertEquals(cache(1).get(k1), "v2");
suspendedTx.commit();
assertEquals("v1", cache(0).get(k1));
assertEquals("v1", cache(1).get(k1));
}
代码示例来源:origin: org.infinispan/infinispan-core
@Test (expectedExceptions = TimeoutException.class)
public void testMultiLockFailure() throws Exception {
Cache<String, String> cache1 = cache(0), cache2 = cache(1);
cache1.put("k1", "v");
cache1.put("k2", "v");
cache1.put("k3", "v");
tm(1).begin();
cache2.put("k3", "v2");
tm(1).suspend();
tm(0).begin();
cache1.getAdvancedCache().lock(Arrays.asList("k1", "k2", "k3"));
tm(0).rollback();
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testStaleLock() throws SystemException, NotSupportedException {
c1.put("k", "v");
assert c1.get("k").equals("v");
assert c2.get("k").equals("v");
TransactionManager tm = TestingUtil.getTransactionManager(c1);
tm.begin();
c1.getAdvancedCache().lock("k");
tm.suspend();
// test that both c1 and c2 have locked k
assertLocked(c1, "k");
assertLocked(c2, "k");
cacheManagers.get(0).stop();
TestingUtil.blockUntilViewReceived(c2, 1);
EmbeddedCacheManager cacheManager = c2.getCacheManager();
assert cacheManager.getMembers().size() == 1;
// may take a while from when the view change is seen through to when the lock is cleared
TestingUtil.sleepThread(1000);
assertNotLocked(c2, "k");
}
代码示例来源:origin: jbosstm/narayana
@Test
public void test() throws Exception
{
TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
tm.begin();
Transaction tx = tm.suspend();
tm.begin();
tx.commit();
tm.commit();
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testSimpleReadOnlTx() throws Exception {
tm().begin();
assert cache.get("k") == null;
Transaction transaction = tm().suspend();
LocalXaTransaction localTransaction = (LocalXaTransaction) txTable().getLocalTransaction(transaction);
assert localTransaction != null && localTransaction.isReadOnly();
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testNotROWhenHasWrites() throws Exception {
tm().begin();
cache.put("k", "v");
assert TestingUtil.extractLockManager(cache).isLocked("k");
Transaction transaction = tm().suspend();
LocalXaTransaction localTransaction = (LocalXaTransaction) txTable().getLocalTransaction(transaction);
assert localTransaction != null && !localTransaction.isReadOnly();
}
代码示例来源:origin: hibernate/hibernate-orm
assertEquals( 0, sessionFactory().getStatistics().getEntityLoadCount() );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
Map foo = new HashMap();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s1 = openSession();
foo = ( Map ) s1.get( "Item", "Foo" );
Transaction tx = TestingJtaPlatformImpl.INSTANCE.getTransactionManager().suspend();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s2 = openSession();
foo = ( Map ) s2.get( "Item", "Foo" );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().resume( tx );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
tx = TestingJtaPlatformImpl.INSTANCE.getTransactionManager().suspend();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().resume( tx );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
代码示例来源:origin: org.infinispan/infinispan-core
public void testReplace2() throws Throwable {
Object k1 = getKeyForCache(0);
cache(0).put(k1, "v1");
tm(0).begin();
assertEquals("v1", cache(0).replace(k1, "v2"));
Transaction suspendedTx = tm(0).suspend();
cache(0).put(k1, "v3");
assertEquals(cache(0).get(k1), "v3");
assertEquals(cache(1).get(k1), "v3");
suspendedTx.commit();
assertEquals("v2", cache(0).get(k1));
assertEquals("v2", cache(1).get(k1));
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testSilentMultiLockFailure() throws Exception {
Cache<String, String> cache1 = cache(0), cache2 = cache(1);
cache1.put("k1", "v");
cache1.put("k2", "v");
cache1.put("k3", "v");
tm(1).begin();
cache2.put("k3", "v2");
tm(1).suspend();
tm(0).begin();
assert !cache1.getAdvancedCache().withFlags(FAIL_SILENTLY).lock(Arrays.asList("k1", "k2", "k3"));
tm(0).rollback();
}
代码示例来源:origin: wildfly/wildfly
transactionManager.resume(tx);
if (tx != null) {
if (transactionManager.getStatus() != Status.STATUS_NO_TRANSACTION) {
transactionManager.suspend();
代码示例来源:origin: mulesoft/mule
@Test
public void testTxHandleCommitKeepsThreadAssociation() throws Exception {
// don't wait for ages, has to be set before TX is begun
tm.setTransactionTimeout(TRANSACTION_TIMEOUT_SECONDS);
tm.begin();
Transaction tx = tm.getTransaction();
assertNotNull("Transaction should have started.", tx);
assertEquals("TX should have been active", Status.STATUS_ACTIVE, tx.getStatus());
tx.commit();
tx = tm.getTransaction();
assertNotNull("Committing via TX handle should NOT disassociated TX from the current thread.", tx);
assertEquals("TX status should have been COMMITTED.", Status.STATUS_COMMITTED, tx.getStatus());
// Remove the TX-thread association. The only public API to achieve it is suspend(),
// technically we never resume the same transaction (TX forget).
Transaction suspended = tm.suspend();
assertTrue("Wrong TX suspended?.", suspended.equals(tx));
assertNull("TX should've been disassociated from the thread.", tm.getTransaction());
// should be no-op and never fail
tm.resume(null);
// ensure we don't have any TX-Thread association lurking around a main thread
assertNull(tm.getTransaction());
}
代码示例来源: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
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s = openSession();
Map foo = new HashMap();
bar.put( "description", "a small bar" );
s.persist( "Item", bar );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s4 = openSession();
Transaction tx4 = TestingJtaPlatformImpl.INSTANCE.getTransactionManager().suspend();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
Session s1 = openSession();
List r1 = s1.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
Transaction tx1 = TestingJtaPlatformImpl.INSTANCE.getTransactionManager().suspend();
assertEquals( r2.size(), 2 );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().resume( tx1 );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().resume( tx4 );
List r4 = s4.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
.setCacheable( true ).list();
代码示例来源:origin: org.infinispan/infinispan-core
public void testConditionalRemove() throws Throwable {
Object k1 = getKeyForCache(0);
cache(0).put(k1, "v1");
tm(0).begin();
assertTrue(cache(0).remove(k1, "v1"));
Transaction suspendedTx = tm(0).suspend();
cache(0).put(k1, "v2");
assertEquals(cache(0).get(k1), "v2");
assertEquals(cache(1).get(k1), "v2");
log.trace("here it is");
suspendedTx.commit();
assertNull(cache(0).get(k1));
assertNull(cache(1).get(k1));
}
}
代码示例来源:origin: org.infinispan/infinispan-core
@Test (expectedExceptions = TimeoutException.class)
public void testLockFailure() throws Exception {
Cache<String, String> cache1 = cache(0), cache2 = cache(1);
cache1.put("k", "v");
tm(1).begin();
cache2.put("k", "v2");
tm(1).suspend();
tm(0).begin();
cache1.getAdvancedCache().lock("k");
tm(0).rollback();
}
代码示例来源:origin: hibernate/hibernate-orm
private <T> T doInSuspendedTransaction(HibernateCallable<T> callable) {
try {
Transaction surroundingTransaction = transactionManager.suspend();
LOG.debugf( "Surrounding JTA transaction suspended [%s]", surroundingTransaction );
transactionManager.resume( surroundingTransaction );
LOG.debugf( "Surrounding JTA transaction resumed [%s]", surroundingTransaction );
内容来源于网络,如有侵权,请联系作者删除!