Examples of DMCustomer


Examples of org.apache.openjpa.persistence.detachment.model.DMCustomer

            iemf.close();
        }
    }

    public void testProxyClear() {
        DMCustomer dc = new DMCustomer();
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(System.currentTimeMillis());
        dc.setCal(cal);

        EntityManager iem = emf.createEntityManager();
        try {
            iem.getTransaction().begin();
            iem.persist(dc);
            iem.getTransaction().commit();
            Calendar beforeDetachCal = dc.getCal();
            iem.clear();
            Calendar afterDetachCal = dc.getCal();

            assertTrue(beforeDetachCal instanceof Proxy);
            assertFalse(afterDetachCal instanceof Proxy);
        } finally {
            if (iem.getTransaction().isActive()) {
View Full Code Here

Examples of org.apache.openjpa.persistence.detachment.model.DMCustomer

        item.setName("openjpa");
        item.setPrice(0.0);
        em.getTransaction().begin();       
        em.persist(item);
        // Persist a customer for finding later
        DMCustomer customer = new DMCustomer();
        customer.setFirstName("Open");
        customer.setLastName("JPA");
        em.persist(customer);
        em.getTransaction().commit();
        em.close();

        em = emf.createEntityManager();
        DMItem itemDetached = em.find(DMItem.class, item.getId());
        em.close();       
        em = emf.createEntityManager();
        DMCustomer customer2 = em.find(DMCustomer.class, customer.getId());      
        DMCustomerInventory customerInventory = new DMCustomerInventory();
        customerInventory.setCustomer(customer2);
        customerInventory.setItem(itemDetached);
        customerInventory.setQuantity(20);
        customer2.getCustomerInventories().add(customerInventory);
        em.getTransaction().begin();
        em.merge(customer2);       
        // At this point, itemDetached is still detached.
        // The following commit causes a persist on CustomerInventory,
        // which leads to a cascade-persist on the detached item.
View Full Code Here

Examples of org.apache.openjpa.persistence.detachment.model.DMCustomer

        item.setName("openjpa");
        item.setPrice(0.0);
        em.getTransaction().begin();       
        em.persist(item);
        // Persist a customer for finding later
        DMCustomer customer = new DMCustomer();
        customer.setFirstName("Open");
        customer.setLastName("JPA");
        em.persist(customer);
        em.getTransaction().commit();
        em.close();

        em = emf.createEntityManager();
        DMItem itemDetached = em.find(DMItem.class, item.getId());
        em.close();       
        em = emf.createEntityManager();
        DMCustomer customer2 = em.find(DMCustomer.class, customer.getId());
        DMCustomerInventory customerInventory = new DMCustomerInventory();
        customerInventory.setCustomer(customer2);
        customerInventory.setItem(itemDetached);
        customerInventory.setQuantity(20);
        customer2.getCustomerInventories().add(customerInventory);
        em.getTransaction().begin();
        em.merge(customer2);       
        // At this point, itemDetached is still detached.
        // The following commit causes a persist on CustomerInventory,
        // which leads to a cascade-persist on the detached item.
View Full Code Here

Examples of org.apache.openjpa.persistence.detachment.model.DMCustomer

    }
   
    public void testDetachRemovesEntityAndCascadedRelationFromContext() {
        em.getTransaction().begin();
       
        DMCustomer pc = em.find(DMCustomer.class, root.getId());
        List<DMCustomerInventory> inventories = pc.getCustomerInventories();
        DMItem item = inventories.get(0).getItem();
       
        assertNotDetached(pc);
        for (DMCustomerInventory i : inventories) assertNotDetached(i);
        assertNotDetached(item);  
       
        em.detach(pc);
       
        assertDetached(pc);
        for (DMCustomerInventory i : inventories) assertDetached(i);
       
        em.getTransaction().rollback();
       
        assertNotNull(pc.getFirstName());
    }
View Full Code Here

Examples of org.apache.openjpa.persistence.detachment.model.DMCustomer

        assertNotNull(pc.getFirstName());
    }
   
    public void testDetachingDirtyEntityDoesNotImplicitlyFlush() {
        em.getTransaction().begin();
        DMCustomer pc = em.find(DMCustomer.class, root.getId());
        String original = pc.getLastName();
        pc.setLastName("Changed That Should not be Saved");
        em.detach(pc);
        em.getTransaction().commit();
       
        DMCustomer pc2 = em.find(DMCustomer.class, root.getId());
        assertNotNull(pc2);
        assertEquals(original, pc2.getLastName());
    }
View Full Code Here

Examples of org.apache.openjpa.persistence.detachment.model.DMCustomer

        assertEquals(original, pc2.getLastName());
    }
   
    public void testDetachingNewEntityIsIgnored() {
        em.getTransaction().begin();
        DMCustomer pc = em.find(DMCustomer.class, root.getId());
        List<DMCustomerInventory> inventories = pc.getCustomerInventories();
       
        DMCustomer newPC = new DMCustomer();
        newPC.setCustomerInventories(inventories);
        for (DMCustomerInventory inventory : inventories)
            inventory.setCustomer(newPC);
       
        em.detach(newPC);
        for (DMCustomerInventory inventory : inventories) {
View Full Code Here

Examples of org.apache.openjpa.persistence.detachment.model.DMCustomer

        em.getTransaction().rollback();
    }
   
    public void testDetachingDetachedEntityIsIgnored() {
        em.getTransaction().begin();
        DMCustomer pc = em.find(DMCustomer.class, root.getId());
        List<DMCustomerInventory> inventories = pc.getCustomerInventories();
       
        em.detach(pc);
        DMCustomer detached = pc;
        assertDetached(detached);
        for (DMCustomerInventory inventory : inventories) {
            assertDetached(inventory);
        }
       
        List<DMCustomerInventory> newInventories =
            new ArrayList<DMCustomerInventory>();
        newInventories.addAll(inventories);
        DMCustomerInventory newInventory = new DMCustomerInventory();
        newInventory.setCustomer(detached);
        newInventories.add(newInventory);
        detached.setCustomerInventories(newInventories);
        em.persist(newInventory);
        assertNotDetached(newInventory);
       
        em.detach(detached);
        assertDetached(detached);
View Full Code Here

Examples of org.apache.openjpa.persistence.detachment.model.DMCustomer

    }
   
    public void testManagedEntityContinuesToReferDetachedEntities() {
        em.getTransaction().begin();
       
        DMCustomer pc = em.find(DMCustomer.class, root.getId());
        List<DMCustomerInventory> inventories = pc.getCustomerInventories();
        DMItem item = inventories.get(1).getItem();
       
        em.detach(inventories.get(0));
       
        DMCustomerInventory attached0 = inventories.get(0);
        DMCustomerInventory attached1 = inventories.get(1);
       
        assertSame(pc.getCustomerInventories().get(0), attached0);
        assertSame(pc.getCustomerInventories().get(1), attached1);
       
        em.getTransaction().rollback();
    }
View Full Code Here

Examples of org.apache.openjpa.persistence.detachment.model.DMCustomer

       
        DMCustomerInventory inventory1 = new DMCustomerInventory();
        DMCustomerInventory inventory2 = new DMCustomerInventory();
        inventory1.setItem(item1); inventory1.setQuantity(10);
        inventory2.setItem(item2); inventory2.setQuantity(20);
        DMCustomer customer = new DMCustomer();
        customer.setFirstName("Detached"); customer.setLastName("Customer");
        customer.setCustomerInventories(Arrays.asList(
            new DMCustomerInventory[]{inventory1,inventory2}));
        inventory1.setCustomer(customer);
        inventory2.setCustomer(customer);
       
        em.getTransaction().begin();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.