當前位置: 首頁>>代碼示例>>Java>>正文


Java Transaction.commit方法代碼示例

本文整理匯總了Java中javax.transaction.Transaction.commit方法的典型用法代碼示例。如果您正苦於以下問題:Java Transaction.commit方法的具體用法?Java Transaction.commit怎麽用?Java Transaction.commit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.transaction.Transaction的用法示例。


在下文中一共展示了Transaction.commit方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: commit

import javax.transaction.Transaction; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public void commit() throws JMSException, RollbackException, HeuristicMixedException, HeuristicRollbackException {
    try {
        Transaction tx = _transactionManager.getTransaction();
        if (tx != null) {
            tx.delistResource(getSession().getXAResource(), XAResource.TMSUCCESS);
            tx.commit();
        }
    }
    catch (SystemException e) {
        _logger.error("Failed to rollback", e);
        throw new RuntimeException("Failed to rollback", e);
    }
}
 
開發者ID:erik-wramner,項目名稱:JmsTools,代碼行數:18,代碼來源:XAJmsResourceManager.java

示例2: testConcurrent

import javax.transaction.Transaction; //導入方法依賴的package包/類
public void testConcurrent() throws Exception {
	getSessions().getStatistics().clear();

	DummyTransactionManager.INSTANCE.begin();
	Session s = openSession();
	Map foo = new HashMap();
	foo.put( "name", "Foo" );
	foo.put( "description", "a big foo" );
	s.persist( "Item", foo );
	Map bar = new HashMap();
	bar.put( "name", "Bar" );
	bar.put( "description", "a small bar" );
	s.persist( "Item", bar );
	DummyTransactionManager.INSTANCE.commit();

	getSessions().evictEntity( "Item" );

	DummyTransactionManager.INSTANCE.begin();
	Session s1 = openSession();
	foo = ( Map ) s1.get( "Item", "Foo" );
	//foo.put("description", "a big red foo");
	//s1.flush();
	Transaction tx1 = DummyTransactionManager.INSTANCE.suspend();

	DummyTransactionManager.INSTANCE.begin();
	Session s2 = openSession();
	foo = ( Map ) s2.get( "Item", "Foo" );
	DummyTransactionManager.INSTANCE.commit();

	DummyTransactionManager.INSTANCE.resume( tx1 );
	tx1.commit();

	getSessions().evictEntity( "Item" );

	DummyTransactionManager.INSTANCE.begin();
	s1 = openSession();
	s1.createCriteria( "Item" ).list();
	//foo.put("description", "a big red foo");
	//s1.flush();
	tx1 = DummyTransactionManager.INSTANCE.suspend();

	DummyTransactionManager.INSTANCE.begin();
	s2 = openSession();
	s2.createCriteria( "Item" ).list();
	DummyTransactionManager.INSTANCE.commit();

	DummyTransactionManager.INSTANCE.resume( tx1 );
	tx1.commit();

	DummyTransactionManager.INSTANCE.begin();
	s2 = openSession();
	s2.createCriteria( "Item" ).list();
	DummyTransactionManager.INSTANCE.commit();

	assertEquals( getSessions().getStatistics().getEntityLoadCount(), 7 );
	assertEquals( getSessions().getStatistics().getEntityFetchCount(), 0 );
	assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 3 );
	assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 0 );
	assertEquals( getSessions().getStatistics().getQueryCacheMissCount(), 0 );

	DummyTransactionManager.INSTANCE.begin();
	s = openSession();
	s.createQuery( "delete from Item" ).executeUpdate();
	DummyTransactionManager.INSTANCE.commit();
}
 
開發者ID:cacheonix,項目名稱:cacheonix-core,代碼行數:66,代碼來源:CMTTest.java

示例3: commitTransactionIfPresent

import javax.transaction.Transaction; //導入方法依賴的package包/類
protected void commitTransactionIfPresent() throws Exception {

        Transaction t = Util.getTransactionManager().getTransaction();

        if (t == null || t.getStatus() != Status.STATUS_ACTIVE) {

            return;
        }

        log.info("committing the JTA transaction");

        t.commit();

    }
 
開發者ID:NovaOrdis,項目名稱:playground,代碼行數:15,代碼來源:CacheOperation.java


注:本文中的javax.transaction.Transaction.commit方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。