Examples of Toy


Examples of org.apache.openjpa.persistence.merge.model.Toy

    public void testPersist() {
        EntityManager em = emf.createEntityManager();

        em.getTransaction().begin();
        Toy t = new Toy(1);
        ToyBox tb = new ToyBox(1);

        tb.setToyList(Arrays.asList(new Toy[] { t }));
        em.persist(tb);
View Full Code Here

Examples of org.apache.openjpa.persistence.merge.model.Toy

    public void testOneToManyCascadeMergeSingleEntity() {
        EntityManager em = emf.createEntityManager();

        try {
            // Create toy
            Toy toy = new Toy(1);
            toy.setToyName("Toy Train");

            // Create toybox
            ToyBox toybox = new ToyBox(1);
            toybox.setOwnerName("Evan");

            // Establish relationship
            toy.setToybox(toybox);
            toybox.getToyList().add(toy);

            // Perform the merge
            em.getTransaction().begin();
            ToyBox mergedToyBox = em.merge(toybox);
            assertNotNull("Assert em.merge() didn't return null", mergedToyBox);

            // Verify the merge
            ToyBox toyboxFind = em.find(ToyBox.class, 1);
            Toy toyFind = em.find(Toy.class, 1);
            assertNotNull("Assert em.find() for ToyBox(id=1) did not return null.", toyboxFind);
            assertNotNull("Assert em.find() for Toy(id=1) did not return null.", toyFind);
            assertTrue("Assert em.find() returns the ToyBox returned by em.merge()", mergedToyBox == toyboxFind);
            assertTrue("Assert tahat ToyBox(id=1).toyList is size 1", toyboxFind.getToyList().size() == 1);
            assertTrue("Assert that ToyBox(id=1).toyList contains the managed Toy(id=1).", toyboxFind.getToyList()
                .contains(toyFind));
            assertTrue("Assert that Toy(id=1) references the managed ToyBox(id=1).", toyFind.getToybox() == toyboxFind);

            em.getTransaction().commit();

            // Verify successful save to the database
            em.clear();
View Full Code Here

Examples of org.apache.openjpa.persistence.merge.model.Toy

    public void testOneToManyCascadeMergeDoubleEntity() {
        EntityManager em = emf.createEntityManager();

        try {
            // Create toys
            Toy toy1 = new Toy(1);
            toy1.setToyName("Toy Train");

            Toy toy2 = new Toy(2);
            toy2.setToyName("Toy Plane");

            // Create toybox
            ToyBox toybox = new ToyBox(1);
            toybox.setOwnerName("Evan");

            // Establish relationship
            toy1.setToybox(toybox);
            toy2.setToybox(toybox);
            toybox.getToyList().add(toy1);
            toybox.getToyList().add(toy2);

            // Perform the merge
            em.getTransaction().begin();
            ToyBox mergedToyBox = em.merge(toybox);
            assertNotNull("Assert em.merge() didn't return null", mergedToyBox);
            em.getTransaction().commit();

            // Verify the merge
            ToyBox toyboxFind = em.find(ToyBox.class, 1);
            Toy toy1Find = em.find(Toy.class, 1);
            Toy toy2Find = em.find(Toy.class, 2);
            assertNotNull("Assert em.find() for ToyBox(id=1) did not return null.", toyboxFind);
            assertNotNull("Assert em.find() for Toy(id=1) did not return null.", toy1Find);
            assertNotNull("Assert em.find() for Toy(id=2) did not return null.", toy2Find);
            assertTrue("Assert em.find() returns the ToyBox returned by em.merge()", mergedToyBox == toyboxFind);
            assertTrue("Assert tahat ToyBox(id=1).toyList is size 2", toyboxFind.getToyList().size() == 2);
            assertTrue("Assert that ToyBox(id=1).toyList contains the managed Toy(id=1).", toyboxFind.getToyList()
                .contains(toy1Find));
            assertTrue("Assert that ToyBox(id=1).toyList contains the managed Toy(id=2).", toyboxFind.getToyList()
                .contains(toy2Find));
            assertTrue("Assert that Toy(id=1) references the managed ToyBox(id=1).",
                toy1Find.getToybox() == toyboxFind);
            assertTrue("Assert that Toy(id=2) references the managed ToyBox(id=1).",
                toy2Find.getToybox() == toyboxFind);

            em.clear();
            assertNotNull("Assert em.find(Toy.class, 1) doesn't return null.", em.find(Toy.class, 1));
            assertNotNull("Assert em.find(Toy.class, 2) doesn't return null.", em.find(Toy.class, 2));
            assertNotNull("Assert em.find(ToyBox.class, 1) doesn't return null.", em.find(ToyBox.class, 1));
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.