Package org.apache.cayenne.testdo.testmap

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


        // fetch P1 separately from cached query
        Painting p1 = Cayenne.objectForPK(context, Painting.class, 33001);

        Painting p2 = (Painting) paints.get(0);
        Artist a1 = p2.getToArtist();
        assertSame(a1, p1.getToArtist());

        assertNotNull(context
                .getParentDataDomain()
                .getSharedSnapshotCache()
View Full Code Here


        SelectQuery q = new SelectQuery(Artist.class);
        q.addOrdering("db:ARTIST_ID", SortOrder.ASCENDING);
        List artists = context.performQuery(q);

        Artist a1 = (Artist) artists.get(0);
        Artist a2 = (Artist) artists.get(1);
        Painting p1 = a1.getPaintingArray().get(0);
        Painting p2 = a1.getPaintingArray().get(0);

        assertNotNull(context
                .getParentDataDomain()
                .getSharedSnapshotCache()
                .getCachedSnapshot(a1.getObjectId()));
        assertNotNull(context
                .getParentDataDomain()
                .getSharedSnapshotCache()
                .getCachedSnapshot(a2.getObjectId()));
        assertNotNull(context
                .getParentDataDomain()
                .getSharedSnapshotCache()
                .getCachedSnapshot(p1.getObjectId()));
        assertNotNull(context
                .getParentDataDomain()
                .getSharedSnapshotCache()
                .getCachedSnapshot(p2.getObjectId()));

        RefreshQuery refresh = new RefreshQuery();
        context.performQuery(refresh);

        assertNull(context
                .getParentDataDomain()
                .getSharedSnapshotCache()
                .getCachedSnapshot(a1.getObjectId()));
        assertNull(context
                .getParentDataDomain()
                .getSharedSnapshotCache()
                .getCachedSnapshot(a2.getObjectId()));
        assertNull(context
                .getParentDataDomain()
                .getSharedSnapshotCache()
                .getCachedSnapshot(p1.getObjectId()));
        assertNull(context
                .getParentDataDomain()
                .getSharedSnapshotCache()
                .getCachedSnapshot(p2.getObjectId()));

        assertEquals(PersistenceState.HOLLOW, a1.getPersistenceState());
        assertEquals(PersistenceState.HOLLOW, a2.getPersistenceState());
        assertEquals(PersistenceState.HOLLOW, p1.getPersistenceState());
        assertEquals(PersistenceState.HOLLOW, p2.getPersistenceState());
    }
View Full Code Here

    }

    public void testUpdateNoQualifierToOne() throws Exception {
        createThreeArtistsTwoPaintings();

        Artist object = Cayenne.objectForPK(context, Artist.class, 33003);

        EJBQLQuery check = new EJBQLQuery("select count(p) from Painting p "
                + "WHERE p.toArtist <> :artist");
        check.setParameter("artist", object);
View Full Code Here

public class DataContextQueryChainTest extends CayenneCase {

    public void testSelectQuery() {
        DataContext context = createDataContext();
        Artist a1 = context.newObject(Artist.class);
        a1.setArtistName("X");
        context.commitChanges();

        QueryChain chain = new QueryChain();
        chain.addQuery(new SelectQuery(Artist.class));
        chain.addQuery(new SelectQuery(Artist.class));
View Full Code Here

        dbHelper.deleteAll("ARTIST_GROUP");
        dbHelper.deleteAll("ARTIST");
    }

    public void testRollbackNew() {
        Artist artist = (Artist) context.newObject("Artist");
        artist.setArtistName("a");

        Painting p1 = (Painting) context.newObject("Painting");
        p1.setPaintingTitle("p1");
        p1.setToArtist(artist);

        Painting p2 = (Painting) context.newObject("Painting");
        p2.setPaintingTitle("p2");
        p2.setToArtist(artist);

        Painting p3 = (Painting) context.newObject("Painting");
        p3.setPaintingTitle("p3");
        p3.setToArtist(artist);

        // before:
        assertEquals(artist, p1.getToArtist());
        assertEquals(3, artist.getPaintingArray().size());

        context.rollbackChanges();

        // after:
        assertEquals(PersistenceState.TRANSIENT, artist.getPersistenceState());
    }
View Full Code Here

        assertEquals(PersistenceState.TRANSIENT, artist.getPersistenceState());
    }

    public void testRollbackNewObject() {
        String artistName = "revertTestArtist";
        Artist artist = (Artist) context.newObject("Artist");
        artist.setArtistName(artistName);

        context.rollbackChanges();

        assertEquals(PersistenceState.TRANSIENT, artist.getPersistenceState());
        context.commitChanges();
        // The commit should have made no changes, so
        // perform a fetch to ensure that this artist hasn't been persisted to the db

        DataContext freshContext = (DataContext) serverRuntime.getContext();
View Full Code Here

    // modifying the collection the iterator was iterating over
    // (ConcurrentModificationException)
    public void testRollbackWithMultipleNewObjects() {
        String artistName = "rollbackTestArtist";
        String paintingTitle = "rollbackTestPainting";
        Artist artist = (Artist) context.newObject("Artist");
        artist.setArtistName(artistName);

        Painting painting = (Painting) context.newObject("Painting");
        painting.setPaintingTitle(paintingTitle);
        painting.setToArtist(artist);

        context.rollbackChanges();

        assertEquals(PersistenceState.TRANSIENT, artist.getPersistenceState());
        context.commitChanges();
       
        // The commit should have made no changes, so
        // perform a fetch to ensure that this artist hasn't been persisted to the db
View Full Code Here

    }

    public void testRollbackRelationshipModification() {
        String artistName = "relationshipModArtist";
        String paintingTitle = "relationshipTestPainting";
        Artist artist = (Artist) context.newObject("Artist");
        artist.setArtistName(artistName);
        Painting painting = (Painting) context.newObject("Painting");
        painting.setPaintingTitle(paintingTitle);
        painting.setToArtist(artist);
        context.commitChanges();

        painting.setToArtist(null);
        assertEquals(0, artist.getPaintingArray().size());
        context.rollbackChanges();

        assertTrue(((ValueHolder) artist.getPaintingArray()).isFault());
        assertEquals(1, artist.getPaintingArray().size());
        assertEquals(artist, painting.getToArtist());

        // Check that the reverse relationship was handled
        assertEquals(1, artist.getPaintingArray().size());
        context.commitChanges();

        DataContext freshContext = (DataContext) serverRuntime.getContext();
        assertNotSame(this.context, freshContext);
       
View Full Code Here

        assertEquals(artistName, queriedPainting.getToArtist().getArtistName());
    }

    public void testRollbackDeletedObject() {
        String artistName = "deleteTestArtist";
        Artist artist = (Artist) context.newObject("Artist");
        artist.setArtistName(artistName);
        context.commitChanges();
        // Save... cayenne doesn't yet handle deleting objects that are uncommitted
        context.deleteObject(artist);
        context.rollbackChanges();

        // Now check everything is as it should be
        assertEquals(PersistenceState.HOLLOW, artist.getPersistenceState());

        context.commitChanges();
        // The commit should have made no changes, so
        // perform a fetch to ensure that this artist hasn't been deleted from the db
View Full Code Here

        assertEquals(1, queryResults.size());
    }

    public void testRollbackModifiedObject() {
        String artistName = "initialTestArtist";
        Artist artist = (Artist) context.newObject("Artist");
        artist.setArtistName(artistName);
        context.commitChanges();

        artist.setArtistName("a new value");

        context.rollbackChanges();

        // Make sure the inmemory changes have been rolled back
        assertEquals(artistName, artist.getArtistName());

        // Commit what's in memory...
        context.commitChanges();

        // .. and ensure that the correct data is in the db
View Full Code Here

TOP

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

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.