本文整理了Java中javax.transaction.TransactionManager.commit()
方法的一些代码示例,展示了TransactionManager.commit()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TransactionManager.commit()
方法的具体详情如下:
包路径:javax.transaction.TransactionManager
类名称:TransactionManager
方法名:commit
[英]Commit the transaction associated with the calling thread.
[中]提交与调用线程关联的事务。
代码示例来源:origin: hibernate/hibernate-orm
private <T> T doInNewTransaction(HibernateCallable<T> callable, TransactionManager transactionManager) {
try {
// start the new isolated transaction
transactionManager.begin();
try {
T result = callable.call();
// if everything went ok, commit the isolated transaction
transactionManager.commit();
return result;
}
catch (Exception e) {
try {
transactionManager.rollback();
}
catch (Exception ignore) {
LOG.unableToRollbackIsolatedTransaction( e, ignore );
}
throw new HibernateException( "Could not apply work", e );
}
}
catch (SystemException e) {
throw new HibernateException( "Unable to start isolated transaction", e );
}
catch (NotSupportedException e) {
throw new HibernateException( "Unable to start isolated transaction", e );
}
}
代码示例来源: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 testPferNoAutoCommitExplicitTransaction() throws Exception {
tm().begin();
cache.putForExternalRead("k1","v");
tm().commit();
assert cache.get("k1").equals("v"); //here is the failure!
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testTxCleanupWithSize() throws Exception {
tm().begin();
assertEquals(0, cache.size());
TransactionTable txTable = getTransactionTable(cache);
assertEquals(1, txTable.getLocalTransactions().size());
tm().commit();
assertEquals(0, txTable.getLocalTransactions().size());
}
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testTransactionalReplace(Method m) throws Exception {
assertEquals(ComponentStatus.RUNNING, cache.getStatus());
assertNotInCacheAndStore(k(m, 1));
assertNotInCacheAndStore(k(m, 2));
cache.put(k(m, 2), v(m));
tm.begin();
cache.put(k(m, 1), v(m, 1));
cache.replace(k(m, 2), v(m, 1));
Transaction t = tm.suspend();
assertNotInCacheAndStore(k(m, 1));
assertInCacheAndStore(k(m, 2), v(m));
tm.resume(t);
tm.commit();
assertInCacheAndStore(k(m, 1), v(m, 1));
assertInCacheAndStore(k(m, 2), v(m, 1));
}
代码示例来源: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: 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
private void assertAllHaveNewValue(Object key) throws Exception {
for (Cache c : caches()) {
Object actual;
TestingUtil.getTransactionManager(c).begin();
actual = c.get(key);
TestingUtil.getTransactionManager(c).commit();
assertEquals(actual, "newValue");
}
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testRemoteCommit() throws Exception {
assertCommitRollback(0, 0, txInterceptor2);
tm.begin();
assertCommitRollback(0, 0, txInterceptor2);
//enlist another resource adapter to force TM to execute 2PC (otherwise 1PC)
tm.getTransaction().enlistResource(new XAResourceAdapter());
cache2.put("key", "value");
assertCommitRollback(0, 0, txInterceptor2);
tm.commit();
assertCommitRollback(1, 0, txInterceptor2);
}
代码示例来源:origin: hibernate/hibernate-orm
assertEquals( 0, sessionFactory().getStatistics().getEntityLoadCount() );
bar.put( "description", "a small bar" );
s.persist( "Item", bar );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertEquals(0, sessionFactory().getStatistics().getUpdateTimestampsCacheHitCount());
assertEquals(2, sessionFactory().getStatistics().getUpdateTimestampsCachePutCount()); // One preinvalidate & one invalidate
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();
s2.createCriteria( "Item" ).list();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().resume( tx );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
s2.createCriteria( "Item" ).list();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
s = openSession();
s.createQuery( "delete from Item" ).executeUpdate();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
代码示例来源:origin: kiegroup/optaplanner
protected <S extends Score, E extends AbstractTestJpaEntity<S>> void findAndAssert(
Class<E> jpaEntityClass, Long id, S score) {
try {
transactionManager.begin();
EntityManager em = entityManagerFactory.createEntityManager();
E jpaEntity = em.find(jpaEntityClass, id);
assertEquals(score, jpaEntity.getScore());
transactionManager.commit();
} catch (NotSupportedException | SystemException | RollbackException | HeuristicMixedException | HeuristicRollbackException e) {
throw new RuntimeException("Transaction failed.", e);
}
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testTxCleanupWithEntrySet() throws Exception {
tm().begin();
assertEquals(0, cache.entrySet().size());
TransactionTable txTable = getTransactionTable(cache);
assertEquals(1, txTable.getLocalTransactions().size());
tm().commit();
assertEquals(0, txTable.getLocalTransactions().size());
}
代码示例来源:origin: hibernate/hibernate-orm
bar.put( "description", "a small bar" );
s.persist( "Item", bar );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
Transaction tx1 = TestingJtaPlatformImpl.INSTANCE.getTransactionManager().suspend();
assertEquals( r2.size(), 2 );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().resume( tx1 );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
s3.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
.setCacheable( true ).list();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().resume( tx4 );
List r4 = s4.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
.setCacheable( true ).list();
assertEquals( r4.size(), 2 );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
s = openSession();
s.createQuery( "delete from Item" ).executeUpdate();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
代码示例来源:origin: kiegroup/optaplanner
protected <S extends Score, E extends AbstractTestJpaEntity<S>> Long persistAndAssert(E jpaEntity) {
try {
transactionManager.begin();
EntityManager em = entityManagerFactory.createEntityManager();
em.persist(jpaEntity);
transactionManager.commit();
} catch (NotSupportedException | SystemException | RollbackException | HeuristicRollbackException | HeuristicMixedException e) {
throw new RuntimeException("Transaction failed.", e);
}
Long id = jpaEntity.getId();
assertNotNull(id);
return id;
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testTxCleanupWithKeySet() throws Exception {
tm().begin();
assertEquals(0, cache.keySet().size());
TransactionTable txTable = getTransactionTable(cache);
assertEquals(1, txTable.getLocalTransactions().size());
tm().commit();
assertEquals(0, txTable.getLocalTransactions().size());
}
代码示例来源:origin: hibernate/hibernate-orm
bar.put( "description", "a small bar" );
s.persist( "Item", bar );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
.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();
s3.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
.setCacheable( true ).list();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
assertEquals( sessionFactory().getStatistics().getUpdateTimestampsCacheMissCount(), 0 );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().resume( tx4 );
List r4 = s4.createCriteria( "Item" ).addOrder( Order.asc( "description" ) )
.setCacheable( true ).list();
assertEquals( r4.size(), 2 );
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
s = openSession();
s.createQuery( "delete from Item" ).executeUpdate();
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
代码示例来源:origin: kiegroup/optaplanner
protected <S extends Score, E extends AbstractTestJpaEntity<S>> void findAssertAndChangeScore(
Class<E> jpaEntityClass, Long id, S oldScore, S newScore) {
try {
transactionManager.begin();
EntityManager em = entityManagerFactory.createEntityManager();
E jpaEntity = em.find(jpaEntityClass, id);
em.persist(jpaEntity);
assertEquals(oldScore, jpaEntity.getScore());
jpaEntity.setScore(newScore);
jpaEntity = em.merge(jpaEntity);
transactionManager.commit();
} catch (NotSupportedException | SystemException | RollbackException | HeuristicRollbackException | HeuristicMixedException e) {
throw new RuntimeException("Transaction failed.", e);
}
}
代码示例来源:origin: org.infinispan/infinispan-core
public void testTxCleanupWithValues() throws Exception {
tm().begin();
assertEquals(0, cache.values().size());
TransactionTable txTable = getTransactionTable(cache);
assertEquals(1, txTable.getLocalTransactions().size());
tm().commit();
assertEquals(0, txTable.getLocalTransactions().size());
}
代码示例来源:origin: org.jberet/jberet-core
private long getNextIdFor(final String key) {
final long nextId;
final TransactionManager infinispanTransactionManager = sequenceCache.getAdvancedCache().getTransactionManager();
try {
infinispanTransactionManager.begin();
sequenceCache.getAdvancedCache().lock(key);
nextId = sequenceCache.get(key) + 1;
sequenceCache.put(key, nextId);
infinispanTransactionManager.commit();
return nextId;
} catch (final Exception e) {
throw BatchMessages.MESSAGES.failToGetNextId(e, key);
}
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testDropDuringActiveJtaTransaction() throws Exception {
final SessionFactory sessionFactory = buildSessionFactory();
JtaPlatformStandardTestingImpl.INSTANCE.transactionManager().begin();
try {
sessionFactory.close();
}
finally {
JtaPlatformStandardTestingImpl.INSTANCE.transactionManager().commit();
}
}
内容来源于网络,如有侵权,请联系作者删除!