Package org.apache.cayenne.testdo.testmap

Examples of org.apache.cayenne.testdo.testmap.Painting


    public void testSelectViaRelationship() throws Exception {

        createArtistWithPaintingDataSet();
        Artist a1 = Cayenne.objectForPK(context, Artist.class, 8);
        Painting p1 = Cayenne.objectForPK(context, Painting.class, 6);

        Expression e = ExpressionFactory.matchExp(Painting.TO_ARTIST_PROPERTY, a1);
        SelectQuery q = new SelectQuery(Painting.class, e);

        List<Painting> paints = context.performQuery(q);
View Full Code Here


    public void testNewAdd() throws Exception {
        Artist a1 = context.newObject(Artist.class);
        a1.setArtistName("bL");

        Painting p1 = context.newObject(Painting.class);
        p1.setPaintingTitle("xa");

        p1.setToArtist(a1);

        assertSame(a1, p1.getToArtist());
        assertEquals(1, a1.getPaintingArray().size());
        assertSame(p1, a1.getPaintingArray().get(0));

        context.commitChanges();
View Full Code Here

        assertEquals(Cayenne.longPKForObject(a1), tArtist.getLong("ARTIST_ID"));
        assertEquals(Cayenne.longPKForObject(a1), tPainting.getLong("ARTIST_ID"));
    }

    public void testRemove() throws Exception {
        Painting p1 = context.newObject(Painting.class);
        p1.setPaintingTitle("xa");

        Gallery g1 = context.newObject(Gallery.class);
        g1.setGalleryName("yT");

        p1.setToGallery(g1);

        // do save
        context.commitChanges();

        ObjectContext context2 = runtime.getContext();

        // test database data
        Painting p2 = (Painting) Cayenne.objectForQuery(context2, new SelectQuery(
                Painting.class));
        Gallery g2 = p2.getToGallery();

        p2.setToGallery(null);

        // test before save
        assertEquals(0, g2.getPaintingArray().size());
        assertNull(p2.getToGallery());

        // do save II
        context2.commitChanges();

        ObjectContext context3 = runtime.getContext();

        Painting p3 = (Painting) Cayenne.objectForQuery(context3, new SelectQuery(
                Painting.class));
        assertNull(p3.getToGallery());
    }
View Full Code Here

        assertNull(p3.getToGallery());
    }

    public void testReplace() throws Exception {

        Painting p1 = context.newObject(Painting.class);
        p1.setPaintingTitle("xa");

        Gallery g1 = context.newObject(Gallery.class);
        g1.setGalleryName("yTW");

        p1.setToGallery(g1);

        context.commitChanges();
        ObjectContext context2 = runtime.getContext();

        // test database data
        Painting p2 = (Painting) Cayenne.objectForQuery(context2, new SelectQuery(
                Painting.class));
        Gallery g21 = p2.getToGallery();
        assertNotNull(g21);
        assertEquals("yTW", g21.getGalleryName());
        assertEquals(1, g21.getPaintingArray().size());
        assertSame(p2, g21.getPaintingArray().get(0));

        Gallery g22 = context2.newObject(Gallery.class);
        g22.setGalleryName("rE");
        p2.setToGallery(g22);

        // test before save
        assertEquals(0, g21.getPaintingArray().size());
        assertEquals(1, g22.getPaintingArray().size());
        assertSame(p2, g22.getPaintingArray().get(0));

        // do save II
        context2.commitChanges();

        ObjectContext context3 = runtime.getContext();

        Painting p3 = (Painting) Cayenne.objectForQuery(context3, new SelectQuery(
                Painting.class));
        Gallery g3 = p3.getToGallery();
        assertNotNull(g3);
        assertEquals("rE", g3.getGalleryName());
        assertEquals(1, g3.getPaintingArray().size());
        assertSame(p3, g3.getPaintingArray().get(0));
    }
View Full Code Here

        assertEquals(1, g3.getPaintingArray().size());
        assertSame(p3, g3.getPaintingArray().get(0));
    }

    public void testSavedAdd() throws Exception {
        Painting p1 = context.newObject(Painting.class);
        p1.setPaintingTitle("xa");

        assertTrue(context.hasChanges());

        // do save
        context.commitChanges();
        ObjectContext context2 = runtime.getContext();

        // test database data
        Painting p2 = (Painting) Cayenne.objectForQuery(context2, new SelectQuery(
                Painting.class));
        assertNull(p2.getToGallery());

        Gallery g2 = context2.newObject(Gallery.class);
        g2.setGalleryName("rE");

        p2.setToGallery(g2);

        // test before save
        assertEquals(1, g2.getPaintingArray().size());
        assertSame(p2, g2.getPaintingArray().get(0));

        // do save II
        context2.commitChanges();
        ObjectContext context3 = runtime.getContext();

        Painting p3 = (Painting) Cayenne.objectForQuery(context3, new SelectQuery(
                Painting.class));
        Gallery g3 = p3.getToGallery();
        assertNotNull(g3);
        assertEquals("rE", g3.getGalleryName());
        assertEquals(1, g3.getPaintingArray().size());
        assertSame(p3, g3.getPaintingArray().get(0));
    }
View Full Code Here

        query.setParameters(Collections.singletonMap("a", a));

        List<?> objects = context.performQuery(query);
        assertEquals(1, objects.size());

        Painting p = (Painting) objects.get(0);
        assertEquals(7, Cayenne.intPKForObject(p));
    }
View Full Code Here

        // null comparison is unpredictable across DB's ... some would return true on null
        // <> value, some - false
        assertTrue(objects.size() == 1 || objects.size() == 2);

        Painting p = (Painting) objects.get(0);
        assertEquals(6, Cayenne.intPKForObject(p));
    }
View Full Code Here

        query.setParameters(Collections.singletonMap("a", a));

        List<?> objects = context.performQuery(query);
        assertEquals(1, objects.size());

        Painting p = (Painting) objects.get(0);
        assertEquals(7, Cayenne.intPKForObject(p));
    }
View Full Code Here

        query.setParameters(Collections.singletonMap("a", a));

        List<?> objects = context.performQuery(query);
        assertEquals(1, objects.size());

        Painting p = (Painting) objects.get(0);
        assertEquals(7, Cayenne.intPKForObject(p));
    }
View Full Code Here

        query.setParameters(Collections.singletonMap("a", null));

        List<?> objects = context.performQuery(query);
        assertEquals(1, objects.size());

        Painting p = (Painting) objects.get(0);
        assertEquals(8, Cayenne.intPKForObject(p));
    }
View Full Code Here

TOP

Related Classes of org.apache.cayenne.testdo.testmap.Painting

Copyright © 2018 www.massapicom. 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.