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

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

本文整理了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

  1. @Override
  2. public Object processInvocation(final InterceptorContext context) throws Exception {
  3. TransactionManager tm = component.getTransactionManager();
  4. int oldTimeout = getCurrentTransactionTimeout(component);
  5. try {
  6. Transaction oldTx = tm.suspend();
  7. try {
  8. return handleInvocation(context);
  9. } finally {
  10. if (oldTx != null) tm.resume(oldTx);
  11. }
  12. } finally {
  13. tm.setTransactionTimeout(oldTimeout == -1 ? 0 : oldTimeout);
  14. }
  15. }

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

  1. tm.setTransactionTimeout(timeout);
  2. try {
  3. final Transaction suspended = tm.suspend();
  4. try {
  5. tm.begin();
  6. final Transaction transaction = tm.suspend();
  7. SimpleXid gtid = SimpleXid.of(getXid(transaction)).withoutBranch();
  8. known.put(gtid, getEntryFor(transaction, gtid));
  9. } catch (Throwable t) {
  10. if (suspended != null) try {
  11. tm.resume(suspended);
  12. } catch (InvalidTransactionException e) {
  13. e.addSuppressed(t);

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

  1. @Test
  2. public void jtaTransactionManagerWithPropagationRequiresNewAndAdapter() throws Exception {
  3. TransactionManager tm = mock(TransactionManager.class);
  4. Transaction tx = mock(Transaction.class);
  5. given(tm.getStatus()).willReturn(Status.STATUS_ACTIVE);
  6. given(tm.suspend()).willReturn(tx);
  7. JtaTransactionManager ptm = newJtaTransactionManager(tm);
  8. TransactionTemplate tt = new TransactionTemplate(ptm);
  9. tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
  10. assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
  11. tt.execute(new TransactionCallbackWithoutResult() {
  12. @Override
  13. protected void doInTransactionWithoutResult(TransactionStatus status) {
  14. assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
  15. }
  16. });
  17. assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
  18. verify(tm).begin();
  19. verify(tm).commit();
  20. verify(tm).resume(tx);
  21. }

代码示例来源:origin: jbosstm/narayana

  1. @Test
  2. public void test() throws Exception
  3. {
  4. javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
  5. tm.begin();
  6. javax.transaction.Transaction theTransaction = tm.getTransaction();
  7. tm.commit();
  8. tm.resume(theTransaction);
  9. }
  10. }

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

  1. assertEquals( 0, sessionFactory().getStatistics().getEntityLoadCount() );
  2. TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
  3. Session s = openSession();
  4. Map foo = new HashMap();
  5. TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
  6. Session s1 = openSession();
  7. foo = ( Map ) s1.get( "Item", "Foo" );
  8. Transaction tx = TestingJtaPlatformImpl.INSTANCE.getTransactionManager().suspend();
  9. TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
  10. Session s2 = openSession();
  11. foo = ( Map ) s2.get( "Item", "Foo" );
  12. TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
  13. TestingJtaPlatformImpl.INSTANCE.getTransactionManager().resume( tx );
  14. TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
  15. tx = TestingJtaPlatformImpl.INSTANCE.getTransactionManager().suspend();
  16. TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
  17. TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
  18. TestingJtaPlatformImpl.INSTANCE.getTransactionManager().resume( tx );
  19. TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();

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

  1. transactionManager.resume(tx);
  2. if (tx != null) {
  3. if (transactionManager.getStatus() != Status.STATUS_NO_TRANSACTION) {
  4. transactionManager.suspend();

代码示例来源:origin: mulesoft/mule

  1. @Test
  2. public void testTxHandleCommitKeepsThreadAssociation() throws Exception {
  3. // don't wait for ages, has to be set before TX is begun
  4. tm.setTransactionTimeout(TRANSACTION_TIMEOUT_SECONDS);
  5. tm.begin();
  6. Transaction tx = tm.getTransaction();
  7. assertNotNull("Transaction should have started.", tx);
  8. assertEquals("TX should have been active", Status.STATUS_ACTIVE, tx.getStatus());
  9. tx.commit();
  10. tx = tm.getTransaction();
  11. assertNotNull("Committing via TX handle should NOT disassociated TX from the current thread.", tx);
  12. assertEquals("TX status should have been COMMITTED.", Status.STATUS_COMMITTED, tx.getStatus());
  13. // Remove the TX-thread association. The only public API to achieve it is suspend(),
  14. // technically we never resume the same transaction (TX forget).
  15. Transaction suspended = tm.suspend();
  16. assertTrue("Wrong TX suspended?.", suspended.equals(tx));
  17. assertNull("TX should've been disassociated from the thread.", tm.getTransaction());
  18. // should be no-op and never fail
  19. tm.resume(null);
  20. // ensure we don't have any TX-Thread association lurking around a main thread
  21. assertNull(tm.getTransaction());
  22. }

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

  1. TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
  2. Session s = openSession();
  3. Map foo = new HashMap();
  4. bar.put( "description", "a small bar" );
  5. s.persist( "Item", bar );
  6. TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
  7. TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
  8. Session s4 = openSession();
  9. Transaction tx4 = TestingJtaPlatformImpl.INSTANCE.getTransactionManager().suspend();
  10. TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
  11. Session s1 = openSession();
  12. List r1 = s1.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
  13. Transaction tx1 = TestingJtaPlatformImpl.INSTANCE.getTransactionManager().suspend();
  14. assertEquals( r2.size(), 2 );
  15. TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
  16. TestingJtaPlatformImpl.INSTANCE.getTransactionManager().resume( tx1 );
  17. TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
  18. TestingJtaPlatformImpl.INSTANCE.getTransactionManager().resume( tx4 );
  19. List r4 = s4.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
  20. .setCacheable( true ).list();

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

  1. private <T> T doInSuspendedTransaction(HibernateCallable<T> callable) {
  2. try {
  3. Transaction surroundingTransaction = transactionManager.suspend();
  4. LOG.debugf( "Surrounding JTA transaction suspended [%s]", surroundingTransaction );
  5. transactionManager.resume( surroundingTransaction );
  6. LOG.debugf( "Surrounding JTA transaction resumed [%s]", surroundingTransaction );

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

  1. public void testReadSafetyRollback() throws Exception {
  2. AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache, "map");
  3. tm.begin();
  4. map.put("blah", "blah");
  5. assert map.size() == 1;
  6. assert map.get("blah").equals("blah");
  7. assert map.containsKey("blah");
  8. Transaction t = tm.suspend();
  9. assertIsEmpty(map);
  10. assertIsEmptyMap(cache, "map");
  11. tm.resume(t);
  12. tm.rollback();
  13. assertIsEmpty(map);
  14. assertIsEmptyMap(cache, "map");
  15. }

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

  1. bar.put( "description", "a small bar" );
  2. s.persist( "Item", bar );
  3. TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
  4. TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
  5. Session s4 = openSession();
  6. Transaction tx4 = TestingJtaPlatformImpl.INSTANCE.getTransactionManager().suspend();
  7. TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
  8. .setCacheable( true ).list();
  9. assertEquals( r2.size(), 2 );
  10. TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
  11. assertEquals( sessionFactory().getStatistics().getUpdateTimestampsCachePutCount(), 0 );
  12. TestingJtaPlatformImpl.INSTANCE.getTransactionManager().resume( tx1 );
  13. TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
  14. TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
  15. assertEquals( sessionFactory().getStatistics().getUpdateTimestampsCacheMissCount(), 0 );
  16. TestingJtaPlatformImpl.INSTANCE.getTransactionManager().resume( tx4 );
  17. List r4 = s4.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
  18. .setCacheable( true ).list();

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

  1. Transaction existingTx = this.tm.suspend();
  2. if (existingBatch.getTransaction() != existingTx) {
  3. throw new IllegalStateException();
  4. this.tm.resume(tx);
  5. setCurrentBatch(batch);
  6. return () -> {
  7. try {
  8. this.tm.suspend();
  9. if (existingBatch != null) {
  10. try {
  11. this.tm.resume(existingBatch.getTransaction());
  12. } catch (InvalidTransactionException e) {
  13. throw new CacheException(e);

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

  1. public void testTxCommit2() throws Exception {
  2. TransactionManager tm = TestingUtil.getTransactionManager(cache);
  3. cache.put("key", "old");
  4. tm.begin();
  5. assertEquals("old", cache.get("key"));
  6. cache.put("key", "value");
  7. assertEquals("value", cache.get("key"));
  8. Transaction t = tm.suspend();
  9. assertEquals("old", cache.get("key"));
  10. tm.resume(t);
  11. tm.commit();
  12. assertEquals("value", cache.get("key"));
  13. assertFalse(cache.isEmpty());
  14. }

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

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

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

  1. public void testRollbacks() throws Exception {
  2. LockTestData tl = lockTestData;
  3. Cache<String, String> cache = tl.cache;
  4. TransactionManager tm = tl.tm;
  5. cache.put("k", "v");
  6. tm.begin();
  7. assertEquals("v", cache.get("k"));
  8. Transaction reader = tm.suspend();
  9. tm.begin();
  10. cache.put("k", "v2");
  11. tm.rollback();
  12. tm.resume(reader);
  13. Object value = cache.get("k");
  14. assertEquals("v", value);
  15. tm.commit();
  16. // even after commit
  17. assertEquals("v", cache.get("k"));
  18. assertNoLocks();
  19. }

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

  1. @Test
  2. public void jtaTransactionManagerWithPropagationNotSupported() throws Exception {
  3. UserTransaction ut = mock(UserTransaction.class);
  4. TransactionManager tm = mock(TransactionManager.class);
  5. Transaction tx = mock(Transaction.class);
  6. given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);
  7. given(tm.suspend()).willReturn(tx);
  8. JtaTransactionManager ptm = newJtaTransactionManager(ut, tm);
  9. TransactionTemplate tt = new TransactionTemplate(ptm);
  10. tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_NOT_SUPPORTED);
  11. assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
  12. tt.execute(new TransactionCallbackWithoutResult() {
  13. @Override
  14. protected void doInTransactionWithoutResult(TransactionStatus status) {
  15. assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
  16. status.setRollbackOnly();
  17. }
  18. });
  19. assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
  20. verify(tm).resume(tx);
  21. }

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

  1. public void testRollbacksOnNullEntry() throws Exception {
  2. LockTestData tl = lockTestData;
  3. Cache<String, String> cache = tl.cache;
  4. TransactionManager tm = tl.tm;
  5. tm.begin();
  6. assert null == cache.get("k");
  7. Transaction reader = tm.suspend();
  8. tm.begin();
  9. cache.put("k", "v");
  10. assertEquals("v", cache.get("k"));
  11. tm.rollback();
  12. tm.resume(reader);
  13. assert null == cache.get("k") : "Expecting null but was " + cache.get("k");
  14. tm.commit();
  15. // even after commit
  16. assert null == cache.get("k");
  17. assertNoLocks();
  18. }
  19. }

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

  1. @Test
  2. public void jtaTransactionManagerWithPropagationRequiresNewAndExisting() throws Exception {
  3. UserTransaction ut = mock(UserTransaction.class);
  4. TransactionManager tm = mock(TransactionManager.class);
  5. Transaction tx = mock(Transaction.class);
  6. given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);
  7. given(tm.suspend()).willReturn(tx);
  8. JtaTransactionManager ptm = newJtaTransactionManager(ut, tm);
  9. TransactionTemplate tt = new TransactionTemplate(ptm);
  10. tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
  11. assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
  12. tt.execute(new TransactionCallbackWithoutResult() {
  13. @Override
  14. protected void doInTransactionWithoutResult(TransactionStatus status) {
  15. assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
  16. }
  17. });
  18. assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
  19. verify(ut).begin();
  20. verify(ut).commit();
  21. verify(tm).resume(tx);
  22. }

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

  1. public void testPreviousValueIgnored() throws Exception {
  2. cache.put("k", "init");
  3. tm.begin();
  4. cache.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES).put("k", "v1");
  5. assertEquals("v1", cache.put("k", "v2"));
  6. Transaction tx = tm.suspend();
  7. assertEquals("init", cache.put("k", "other"));
  8. tm.resume(tx);
  9. commit();
  10. }

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

  1. @Test
  2. public void jtaTransactionManagerWithPropagationRequiresNewAndExistingWithBeginException() throws Exception {
  3. UserTransaction ut = mock(UserTransaction.class);
  4. TransactionManager tm = mock(TransactionManager.class);
  5. Transaction tx = mock(Transaction.class);
  6. given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);
  7. given(tm.suspend()).willReturn(tx);
  8. willThrow(new SystemException()).given(ut).begin();
  9. JtaTransactionManager ptm = newJtaTransactionManager(ut, tm);
  10. TransactionTemplate tt = new TransactionTemplate(ptm);
  11. tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
  12. assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
  13. try {
  14. tt.execute(new TransactionCallbackWithoutResult() {
  15. @Override
  16. protected void doInTransactionWithoutResult(TransactionStatus status) {
  17. assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
  18. }
  19. });
  20. fail("Should have thrown CannotCreateTransactionException");
  21. }
  22. catch (CannotCreateTransactionException ex) {
  23. // expected
  24. }
  25. assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
  26. verify(tm).resume(tx);
  27. }

相关文章