本文整理汇总了Java中javax.persistence.EntityManager.joinTransaction方法的典型用法代码示例。如果您正苦于以下问题:Java EntityManager.joinTransaction方法的具体用法?Java EntityManager.joinTransaction怎么用?Java EntityManager.joinTransaction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.persistence.EntityManager
的用法示例。
在下文中一共展示了EntityManager.joinTransaction方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: carLifecycleXA
import javax.persistence.EntityManager; //导入方法依赖的package包/类
/**
* Create, find and delete car using XA Transactions
* @param ut
* @param em
* @throws Exception
*/
protected void carLifecycleXA(UserTransaction ut, EntityManager em) throws Exception {
ut.begin();
em.joinTransaction();
delete(em, Car.class, BLUE_PLATE);
em.persist(createBlueCar());
ut.commit();
Car c = em.find(Car.class, BLUE_PLATE);
assertBlueCar(c);
ut.begin();
em.joinTransaction();
delete(em, Car.class, BLUE_PLATE);
ut.commit();
}
示例2: truckLifecycleXA
import javax.persistence.EntityManager; //导入方法依赖的package包/类
/**
* Create, find and delete car using XA Transactions
* @param ut
* @param em
* @throws Exception
*/
protected void truckLifecycleXA(UserTransaction ut, EntityManager em) throws Exception {
ut.begin();
em.joinTransaction();
delete(em, Truck.class, BLUE_PLATE);
em.persist(createBlueTruck());
ut.commit();
Truck t = em.find(Truck.class, BLUE_PLATE);
assertBlueTruck(t);
ut.begin();
em.joinTransaction();
delete(em, Truck.class, BLUE_PLATE);
ut.commit();
}
示例3: cleanup
import javax.persistence.EntityManager; //导入方法依赖的package包/类
private void cleanup(EntityManager em) throws Exception {
ut.begin();
em.joinTransaction();
delete(em, Car.class, BLACK_CAR_PLATE);
delete(em, Car.class, BLUE_PLATE);
ut.commit();
}
示例4: testEmSupplier
import javax.persistence.EntityManager; //导入方法依赖的package包/类
@Test
public void testEmSupplier() throws Exception {
EmSupplier emSupplier = getService(EmSupplier.class, "(osgi.unit.name=" + XA_TEST_UNIT + ")");
Coordination coordination = coordinator.begin("test", 0);
try {
EntityManager em = emSupplier.get();
carLifecycleXA(ut, em);
Query countQuery = em.createQuery("SELECT Count(c) from Car c");
assertEquals(0l, countQuery.getSingleResult());
ut.begin();
em.joinTransaction();
em.persist(createBlueCar());
em.persist(createGreenCar());
ut.commit();
assertEquals(2l, countQuery.getSingleResult());
TypedQuery<Car> carQuery = em.createQuery("Select c from Car c ORDER by c.engineSize", Car.class);
List<Car> list = carQuery.getResultList();
assertEquals(2, list.size());
assertBlueCar(list.get(0));
assertGreenCar(list.get(1));
ut.begin();
em.joinTransaction();
changeToRed(em.find(Car.class, BLUE_PLATE));
em.remove(em.find(Car.class, GREEN_CAR_PLATE));
em.persist(createBlackCar());
ut.commit();
assertEquals(2l, countQuery.getSingleResult());
list = carQuery.getResultList();
assertEquals(2, list.size());
assertBlackCar(list.get(0));
assertChangedBlueCar(list.get(1));
cleanup(em);
} finally {
coordination.end();
}
}