Package org.apache.art

Examples of org.apache.art.Painting


        createTestData("P2");

        // reset context
        context = createDataContext();

        Painting painting = fetchPainting("P_artist2", false);
        Artist artist = painting.getToArtist();
        assertEquals(PersistenceState.HOLLOW, artist.getPersistenceState());
        assertNull(artist.readPropertyDirectly("artistName"));

        // this must trigger a fetch
        artist.setDateOfBirth(new Date());
View Full Code Here


     * Helper method that takes one of the artists from the standard dataset (always the
     * same one) and creates a new painting for this artist, committing it to the
     * database. Both Painting and Artist will be cached in current DataContext.
     */
    protected Painting insertPaintingInContext(String paintingName) {
        Painting painting = (Painting) context.newObject("Painting");
        painting.setPaintingTitle(paintingName);
        painting.setToArtist(fetchArtist("artist2", false));

        context.commitChanges();

        return painting;
    }
View Full Code Here

        ArcProperty toArtist = (ArcProperty) d.getProperty("toArtist");

        SelectQuery artistQ = new SelectQuery(Artist.class, Expression
                .fromString("artistName = 'artist2'"));
        Artist anotherArtist = (Artist) context.performQuery(artistQ).get(0);
        Painting painting = context.newObject(Painting.class);
        painting.setPaintingTitle("PX");
        painting.setToArtist(anotherArtist);

        context.commitChanges();

        artistQ = new SelectQuery(Artist.class, Expression
                .fromString("artistName = 'artist1'"));
        Artist artist = (Artist) context.performQuery(artistQ).get(0);
        assertNotSame(artist, painting.getToArtist());

        ObjectDiff diff = context.getObjectStore().registerDiff(
                painting.getObjectId(),
                null);

        assertFalse(DataRowUtils.isToOneTargetModified(toArtist, painting, diff));

        painting.setToArtist(artist);
        assertTrue(DataRowUtils.isToOneTargetModified(toArtist, painting, diff));
    }
View Full Code Here

        createTestData("testIsToOneTargetModifiedWithNewTarget");

        // add NEW gallery to painting
        List paintings = context.performQuery(new SelectQuery(Painting.class));
        assertEquals(1, paintings.size());
        Painting p1 = (Painting) paintings.get(0);

        ClassDescriptor d = context.getEntityResolver().getClassDescriptor("Painting");
        ArcProperty toGallery = (ArcProperty) d.getProperty("toGallery");

        ObjectDiff diff = context.getObjectStore().registerDiff(p1.getObjectId(), null);
        assertFalse(DataRowUtils.isToOneTargetModified(toGallery, p1, diff));

        Gallery g1 = (Gallery) context.newObject("Gallery");
        g1.addToPaintingArray(p1);
        assertTrue(DataRowUtils.isToOneTargetModified(toGallery, p1, diff));
View Full Code Here

                        Painting.class,
                        "INSERT INTO PAINTING (PAINTING_ID, ARTIST_ID, PAINTING_TITLE) VALUES (1, 1, 'p1')"));

        context.performQuery(chain);

        Painting p = DataObjectUtils.objectForPK(context, Painting.class, 1);

        // resolve artist once before running non-refreshing query, to check that we do
        // not refresh the object

        Artist a = DataObjectUtils.objectForPK(context, Artist.class, 1);
        long v = a.getSnapshotVersion();
        int writeCalls = a.getPropertyWrittenDirectly();
        assertEquals("a1", a.getArtistName());

        context.performQuery(new SQLTemplate(
                Artist.class,
                "UPDATE ARTIST SET ARTIST_NAME = 'a2' WHERE ARTIST_ID = 1"));

        RelationshipQuery toOne = new RelationshipQuery(
                p.getObjectId(),
                Painting.TO_ARTIST_PROPERTY,
                false);

        List<Artist> related = context.performQuery(toOne);
        assertEquals(1, related.size());
View Full Code Here

                        Painting.class,
                        "INSERT INTO PAINTING (PAINTING_ID, ARTIST_ID, PAINTING_TITLE) VALUES (1, 1, 'p1')"));

        context.performQuery(chain);

        Painting p = DataObjectUtils.objectForPK(context, Painting.class, 1);

        // resolve artist once before running non-refreshing query, to check that we do
        // not refresh the object

        Artist a = DataObjectUtils.objectForPK(context, Artist.class, 1);
        long v = a.getSnapshotVersion();
        int writeCalls = a.getPropertyWrittenDirectly();
        assertEquals("a1", a.getArtistName());

        context.performQuery(new SQLTemplate(
                Artist.class,
                "UPDATE ARTIST SET ARTIST_NAME = 'a2' WHERE ARTIST_ID = 1"));

        RelationshipQuery toOne = new RelationshipQuery(
                p.getObjectId(),
                Painting.TO_ARTIST_PROPERTY,
                true);

        List<Artist> related = context.performQuery(toOne);
        assertEquals(1, related.size());
View Full Code Here

        context.commitChanges();
    }

    public void testCascadeToOne() {
        // Painting toPaintingInfo
        Painting painting = (Painting) context.newObject("Painting");
        painting.setPaintingTitle("A Title");

        PaintingInfo info = (PaintingInfo) context.newObject("PaintingInfo");
        painting.setToPaintingInfo(info);

        // Must commit before deleting.. this relationship is dependent,
        // and everything must be committed for certain things to work.
        context.commitChanges();

        context.deleteObject(painting);

        // info must also be deleted
        assertEquals(PersistenceState.DELETED, info.getPersistenceState());
        assertNull(info.getPainting());
        assertNull(painting.getToPaintingInfo());
        context.commitChanges();
    }
View Full Code Here

    public void testDenyToMany() {
        // Gallery paintingArray
        Gallery gallery = (Gallery) context.newObject("Gallery");
        gallery.setGalleryName("A Name");
        Painting painting = (Painting) context.newObject("Painting");
        painting.setPaintingTitle("A Title");
        gallery.addToPaintingArray(painting);
        context.commitChanges();

        try {
            context.deleteObject(gallery);
View Full Code Here

        ValidationDelegate delegate = new ValidationDelegate() {

            public void validateForSave(Object object, ValidationResult validationResult) {

                Artist a = (Artist) object;
                Painting p = a.getObjectContext().newObject(Painting.class);
                p.setPaintingTitle("XXX");
                p.setToArtist(a);
            }
        };

        DataContext context = createDataContext();
View Full Code Here

        assertNotNull(a3);
        assertTrue(a3.isPostAdded());

        assertSame(a3, listener2.getPublicCalledbackEntity());

        Painting p3 = context.newObject(Painting.class);
        assertNotNull(p3);
        assertFalse(p3.isPostAdded());
        assertSame(a3, listener2.getPublicCalledbackEntity());
    }
View Full Code Here

TOP

Related Classes of org.apache.art.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.