本文整理了Java中javax.persistence.EntityManager.joinTransaction()
方法的一些代码示例,展示了EntityManager.joinTransaction()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。EntityManager.joinTransaction()
方法的具体详情如下:
包路径:javax.persistence.EntityManager
类名称:EntityManager
方法名:joinTransaction
[英]Indicate to the entity manager that a JTA transaction is active. This method should be called on a JTA application managed entity manager that was created outside the scope of the active transaction to associate it with the current JTA transaction.
[中]向实体经理指示JTA事务处于活动状态。应在活动事务范围之外创建的JTA应用程序管理实体管理器上调用此方法,以将其与当前JTA事务关联。
代码示例来源:origin: rapidoid/rapidoid
@Override
public void joinTransaction() {
em.joinTransaction();
}
代码示例来源:origin: kiegroup/jbpm
@Override
public void joinTransaction() {
if (this.em == null) {
return;
}
if (this.isJTA) {
this.em.joinTransaction();
}
}
代码示例来源:origin: kiegroup/jbpm
public void joinTransaction() {
if (this.em == null) {
return;
}
this.em.joinTransaction();
}
代码示例来源:origin: rapidoid/rapidoid
@Override
public void joinTransaction() {
em().joinTransaction();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testEntityManagerProxyAcceptsProgrammaticTxJoining() {
EntityManager em = entityManagerFactory.createEntityManager();
em.joinTransaction();
}
代码示例来源:origin: spring-projects/spring-framework
this.target.joinTransaction();
logger.debug("Joined JTA transaction");
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testInstantiateAndSave() {
EntityManager em = entityManagerFactory.createEntityManager();
em.joinTransaction();
doInstantiateAndSave(em);
}
代码示例来源:origin: spring-projects/spring-framework
@Test(expected = TransactionRequiredException.class)
public void transactionRequiredExceptionOnJoinTransaction() {
EntityManagerFactory emf = mock(EntityManagerFactory.class);
EntityManager em = SharedEntityManagerCreator.createSharedEntityManager(emf);
em.joinTransaction();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testContainerEntityManagerProxyAllowsJoinTransactionInTransaction() {
createContainerManagedEntityManager().joinTransaction();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testTransactionCommitWithSharedEntityManagerUnsynchronizedJoined() {
given(manager.getTransaction()).willReturn(tx);
tt.execute(status -> {
bean.sharedEntityManagerUnsynchronized.joinTransaction();
bean.sharedEntityManagerUnsynchronized.flush();
return null;
});
verify(tx).commit();
verify(manager).flush();
verify(manager, times(2)).close();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testTransactionCommitWithExtendedEntityManagerUnsynchronizedJoined() {
given(manager.getTransaction()).willReturn(tx);
tt.execute(status -> {
bean.extendedEntityManagerUnsynchronized.joinTransaction();
bean.extendedEntityManagerUnsynchronized.flush();
return null;
});
verify(tx, times(2)).commit();
verify(manager).flush();
verify(manager).close();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testTransactionCommitWithExtendedEntityManagerUnsynchronizedJoinedAndPropagationSupports() {
given(manager.isOpen()).willReturn(true);
tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_SUPPORTS);
tt.execute(status -> {
bean.extendedEntityManagerUnsynchronized.joinTransaction();
bean.extendedEntityManagerUnsynchronized.flush();
return null;
});
verify(manager).flush();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testRollbackOccurs() {
EntityManager em = entityManagerFactory.createEntityManager();
em.joinTransaction();
doInstantiateAndSave(em);
endTransaction(); // Should rollback
assertEquals("Tx must have been rolled back", 0, countRowsInTable(em, "person"));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testContainerEntityManagerProxyRejectsJoinTransactionWithoutTransaction() {
endTransaction();
try {
createContainerManagedEntityManager().joinTransaction();
fail("Should have thrown a TransactionRequiredException");
}
catch (TransactionRequiredException ex) {
// expected
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testCommitOccurs() {
EntityManager em = entityManagerFactory.createEntityManager();
em.joinTransaction();
doInstantiateAndSave(em);
setComplete();
endTransaction(); // Should rollback
assertEquals("Tx must have committed back", 1, countRowsInTable(em, "person"));
// Now clean up the database
deleteFromTables("person");
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testReuseInNewTransaction() {
EntityManager em = entityManagerFactory.createEntityManager();
em.joinTransaction();
doInstantiateAndSave(em);
endTransaction();
assertFalse(em.getTransaction().isActive());
startNewTransaction();
// Call any method: should cause automatic tx invocation
assertFalse(em.contains(new Person()));
assertFalse(em.getTransaction().isActive());
em.joinTransaction();
assertTrue(em.getTransaction().isActive());
doInstantiateAndSave(em);
setComplete();
endTransaction(); // Should rollback
assertEquals("Tx must have committed back", 1, countRowsInTable(em, "person"));
// Now clean up the database
startNewTransaction();
em.joinTransaction();
deleteAllPeopleUsingEntityManager(em);
assertEquals("People have been killed", 0, countRowsInTable(em, "person"));
setComplete();
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testEnversCompatibility() throws Exception {
// revision 1
userTransaction.begin();
entityManager.joinTransaction();
AuditedEntity entity = new AuditedEntity( 1, "Marco Polo" );
entityManager.persist( entity );
userTransaction.commit();
// revision 2
userTransaction.begin();
entityManager.joinTransaction();
entity.setName( "George Washington" );
entityManager.merge( entity );
userTransaction.commit();
entityManager.clear();
// verify audit history revision counts
userTransaction.begin();
final AuditReader auditReader = AuditReaderFactory.get( entityManager );
assertEquals( Arrays.asList( 1, 2 ), auditReader.getRevisions( AuditedEntity.class, 1 ) );
userTransaction.commit();
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testApplicationManagedEntityManagerWithJtaTransaction() throws Exception {
Object testEntity = new Object();
// This one's for the tx (shared)
EntityManager sharedEm = mock(EntityManager.class);
given(sharedEm.getTransaction()).willReturn(new NoOpEntityTransaction());
// This is the application-specific one
EntityManager mockEm = mock(EntityManager.class);
given(mockEmf.createEntityManager()).willReturn(sharedEm, mockEm);
LocalContainerEntityManagerFactoryBean cefb = parseValidPersistenceUnit();
MutablePersistenceUnitInfo pui = ((MutablePersistenceUnitInfo) cefb.getPersistenceUnitInfo());
pui.setTransactionType(PersistenceUnitTransactionType.JTA);
JpaTransactionManager jpatm = new JpaTransactionManager();
jpatm.setEntityManagerFactory(cefb.getObject());
TransactionStatus txStatus = jpatm.getTransaction(new DefaultTransactionAttribute());
EntityManagerFactory emf = cefb.getObject();
assertSame("EntityManagerFactory reference must be cached after init", emf, cefb.getObject());
assertNotSame("EMF must be proxied", mockEmf, emf);
EntityManager em = emf.createEntityManager();
em.joinTransaction();
assertFalse(em.contains(testEntity));
jpatm.commit(txStatus);
cefb.destroy();
verify(mockEm).joinTransaction();
verify(mockEm).contains(testEntity);
verify(mockEmf).close();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testApplicationManagedEntityManagerWithTransaction() throws Exception {
Object testEntity = new Object();
EntityTransaction mockTx = mock(EntityTransaction.class);
// This one's for the tx (shared)
EntityManager sharedEm = mock(EntityManager.class);
given(sharedEm.getTransaction()).willReturn(new NoOpEntityTransaction());
// This is the application-specific one
EntityManager mockEm = mock(EntityManager.class);
given(mockEm.getTransaction()).willReturn(mockTx);
given(mockEmf.createEntityManager()).willReturn(sharedEm, mockEm);
LocalContainerEntityManagerFactoryBean cefb = parseValidPersistenceUnit();
JpaTransactionManager jpatm = new JpaTransactionManager();
jpatm.setEntityManagerFactory(cefb.getObject());
TransactionStatus txStatus = jpatm.getTransaction(new DefaultTransactionAttribute());
EntityManagerFactory emf = cefb.getObject();
assertSame("EntityManagerFactory reference must be cached after init", emf, cefb.getObject());
assertNotSame("EMF must be proxied", mockEmf, emf);
EntityManager em = emf.createEntityManager();
em.joinTransaction();
assertFalse(em.contains(testEntity));
jpatm.commit(txStatus);
cefb.destroy();
verify(mockTx).begin();
verify(mockTx).commit();
verify(mockEm).contains(testEntity);
verify(mockEmf).close();
}
代码示例来源:origin: spring-projects/spring-framework
em.joinTransaction();
assertFalse(em.contains(testEntity));
内容来源于网络,如有侵权,请联系作者删除!