本文整理匯總了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);
}
}
示例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();
}
示例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();
}