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


Java EntityManager.joinTransaction方法代碼示例

本文整理匯總了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();
}
 
開發者ID:apache,項目名稱:aries-jpa,代碼行數:22,代碼來源:AbstractCarJPAITest.java

示例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();
}
 
開發者ID:apache,項目名稱:aries-jpa,代碼行數:22,代碼來源:AbstractCarJPAITest.java

示例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();
}
 
開發者ID:apache,項目名稱:aries-jpa,代碼行數:8,代碼來源:JPAContainerTest.java

示例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();
    }
}
 
開發者ID:apache,項目名稱:aries-jpa,代碼行數:46,代碼來源:JPAContainerTest.java


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