javax.transaction.TransactionManager.resume()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(13.4k)|赞(0)|评价(0)|浏览(136)

本文整理了Java中javax.transaction.TransactionManager.resume()方法的一些代码示例,展示了TransactionManager.resume()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TransactionManager.resume()方法的具体详情如下:
包路径:javax.transaction.TransactionManager
类名称:TransactionManager
方法名:resume

TransactionManager.resume介绍

[英]Resume the association of the calling thread with the given 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

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: jbosstm/narayana

@Test
  public void test() throws Exception
  {
    javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();

    tm.begin();

    javax.transaction.Transaction theTransaction = tm.getTransaction();

    tm.commit();

    tm.resume(theTransaction);
  }
}

代码示例来源: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: 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: 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: 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 );

代码示例来源:origin: org.infinispan/infinispan-core

public void testReadSafetyRollback() throws Exception {
 AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache, "map");
 tm.begin();
 map.put("blah", "blah");
 assert map.size() == 1;
 assert map.get("blah").equals("blah");
 assert map.containsKey("blah");
 Transaction t = tm.suspend();
 assertIsEmpty(map);
 assertIsEmptyMap(cache, "map");
 tm.resume(t);
 tm.rollback();
 assertIsEmpty(map);
 assertIsEmptyMap(cache, "map");
}

代码示例来源:origin: hibernate/hibernate-orm

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();
    .setCacheable( true ).list();
assertEquals( r2.size(), 2 );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertEquals( sessionFactory().getStatistics().getUpdateTimestampsCachePutCount(), 0 );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().resume( tx1 );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
assertEquals( sessionFactory().getStatistics().getUpdateTimestampsCacheMissCount(), 0 );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().resume( tx4 );
List r4 = s4.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
    .setCacheable( true ).list();

代码示例来源:origin: wildfly/wildfly

Transaction existingTx = this.tm.suspend();
  if (existingBatch.getTransaction() != existingTx) {
    throw new IllegalStateException();
this.tm.resume(tx);
setCurrentBatch(batch);
return () -> {
  try {
    this.tm.suspend();
    if (existingBatch != null) {
      try {
        this.tm.resume(existingBatch.getTransaction());
      } catch (InvalidTransactionException e) {
        throw new CacheException(e);

代码示例来源:origin: org.infinispan/infinispan-core

public void testTxCommit2() throws Exception {
 TransactionManager tm = TestingUtil.getTransactionManager(cache);
 cache.put("key", "old");
 tm.begin();
 assertEquals("old", cache.get("key"));
 cache.put("key", "value");
 assertEquals("value", cache.get("key"));
 Transaction t = tm.suspend();
 assertEquals("old", cache.get("key"));
 tm.resume(t);
 tm.commit();
 assertEquals("value", cache.get("key"));
 assertFalse(cache.isEmpty());
}

代码示例来源:origin: wildfly/wildfly

tm.resume(tx);
  tm.suspend();

代码示例来源:origin: org.infinispan/infinispan-core

public void testRollbacks() throws Exception {
 LockTestData tl = lockTestData;
 Cache<String, String> cache = tl.cache;
 TransactionManager tm = tl.tm;
 cache.put("k", "v");
 tm.begin();
 assertEquals("v", cache.get("k"));
 Transaction reader = tm.suspend();
 tm.begin();
 cache.put("k", "v2");
 tm.rollback();
 tm.resume(reader);
 Object value = cache.get("k");
 assertEquals("v", value);
 tm.commit();
 // even after commit
 assertEquals("v", cache.get("k"));
 assertNoLocks();
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void jtaTransactionManagerWithPropagationNotSupported() throws Exception {
  UserTransaction ut = mock(UserTransaction.class);
  TransactionManager tm = mock(TransactionManager.class);
  Transaction tx = mock(Transaction.class);
  given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);
  given(tm.suspend()).willReturn(tx);
  JtaTransactionManager ptm = newJtaTransactionManager(ut, tm);
  TransactionTemplate tt = new TransactionTemplate(ptm);
  tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_NOT_SUPPORTED);
  assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
  tt.execute(new TransactionCallbackWithoutResult() {
    @Override
    protected void doInTransactionWithoutResult(TransactionStatus status) {
      assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
      status.setRollbackOnly();
    }
  });
  assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
  verify(tm).resume(tx);
}

代码示例来源:origin: org.infinispan/infinispan-core

public void testRollbacksOnNullEntry() throws Exception {
   LockTestData tl = lockTestData;
   Cache<String, String> cache = tl.cache;
   TransactionManager tm = tl.tm;
   tm.begin();
   assert null == cache.get("k");
   Transaction reader = tm.suspend();

   tm.begin();
   cache.put("k", "v");
   assertEquals("v", cache.get("k"));
   tm.rollback();

   tm.resume(reader);
   assert null == cache.get("k") : "Expecting null but was " + cache.get("k");
   tm.commit();

   // even after commit
   assert null == cache.get("k");
   assertNoLocks();
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void jtaTransactionManagerWithPropagationRequiresNewAndExisting() throws Exception {
  UserTransaction ut = mock(UserTransaction.class);
  TransactionManager tm = mock(TransactionManager.class);
  Transaction tx = mock(Transaction.class);
  given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);
  given(tm.suspend()).willReturn(tx);
  JtaTransactionManager ptm = newJtaTransactionManager(ut, 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(ut).begin();
  verify(ut).commit();
  verify(tm).resume(tx);
}

代码示例来源:origin: org.infinispan/infinispan-core

public void testPreviousValueIgnored() throws Exception {
 cache.put("k", "init");
 tm.begin();
 cache.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES).put("k", "v1");
 assertEquals("v1", cache.put("k", "v2"));
 Transaction tx = tm.suspend();
 assertEquals("init", cache.put("k", "other"));
 tm.resume(tx);
 commit();
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void jtaTransactionManagerWithPropagationRequiresNewAndExistingWithBeginException() throws Exception {
  UserTransaction ut = mock(UserTransaction.class);
  TransactionManager tm = mock(TransactionManager.class);
  Transaction tx = mock(Transaction.class);
  given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);
  given(tm.suspend()).willReturn(tx);
  willThrow(new SystemException()).given(ut).begin();
  JtaTransactionManager ptm = newJtaTransactionManager(ut, tm);
  TransactionTemplate tt = new TransactionTemplate(ptm);
  tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
  assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
  try {
    tt.execute(new TransactionCallbackWithoutResult() {
      @Override
      protected void doInTransactionWithoutResult(TransactionStatus status) {
        assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
      }
    });
    fail("Should have thrown CannotCreateTransactionException");
  }
  catch (CannotCreateTransactionException ex) {
    // expected
  }
  assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
  verify(tm).resume(tx);
}

相关文章