Package org.apache.cayenne.testdo.testmap

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


   
    public void testNoRefreshValuesNew() {

        DataContext context = createDataContext();

        Artist a = context.newObject(Artist.class);
        a.setArtistName("X");

        context.commitChanges();

        context.performGenericQuery(new SQLTemplate(
                Artist.class,
                "UPDATE ARTIST SET ARTIST_NAME = 'Y'"));

        long id = Cayenne.longPKForObject(a);
        ObjectIdQuery query = new ObjectIdQuery(new ObjectId(
                "Artist",
                Artist.ARTIST_ID_PK_COLUMN,
                id), false, ObjectIdQuery.CACHE);

        Artist a1 = (Artist) Cayenne.objectForQuery(context, query);
        assertEquals("X", a1.getArtistName());
    }
View Full Code Here


        insert.setParameters(Collections.singletonMap("date", new Date()));

        DataContext context = createDataContext();
        context.performGenericQuery(insert);

        Artist a = Cayenne.objectForPK(context, Artist.class, 44l);
        assertNotNull(a.getDateOfBirth());
        assertEquals("X", a.getArtistName());

        context.performGenericQuery(new SQLTemplate(
                Artist.class,
                "UPDATE ARTIST SET DATE_OF_BIRTH = NULL"));

        ObjectIdQuery query = new ObjectIdQuery(new ObjectId(
                "Artist",
                Artist.ARTIST_ID_PK_COLUMN,
                44l), false, ObjectIdQuery.CACHE_REFRESH);

        Artist a1 = (Artist) Cayenne.objectForQuery(context, query);
        assertNull(a1.getDateOfBirth());
        assertEquals("X", a1.getArtistName());
    }
View Full Code Here

    public void testMultipleOrdering() throws Exception {

        Calendar c = Calendar.getInstance();

        DataContext context = createDataContext();
        Artist a1 = context.newObject(Artist.class);
        a1.setArtistName("2");
        a1.setDateOfBirth(c.getTime());

        c.add(Calendar.DAY_OF_MONTH, -1);
        Artist a2 = context.newObject(Artist.class);
        a2.setArtistName("3");
        a2.setDateOfBirth(c.getTime());

        c.add(Calendar.DAY_OF_MONTH, -1);
        Artist a3 = context.newObject(Artist.class);
        a3.setArtistName("3");
        a3.setDateOfBirth(c.getTime());

        context.commitChanges();

        SelectQuery query = new SelectQuery(Artist.class);
        query.addOrdering(Artist.ARTIST_NAME_PROPERTY, SortOrder.DESCENDING);
View Full Code Here

    public void testMultipleOrderingInSelectClauseCAY_1074() throws Exception {

        Calendar c = Calendar.getInstance();

        DataContext context = createDataContext();
        Artist a1 = context.newObject(Artist.class);
        a1.setArtistName("2");
        a1.setDateOfBirth(c.getTime());

        c.add(Calendar.DAY_OF_MONTH, -1);
        Artist a2 = context.newObject(Artist.class);
        a2.setArtistName("3");
        a2.setDateOfBirth(c.getTime());

        c.add(Calendar.DAY_OF_MONTH, -1);
        Artist a3 = context.newObject(Artist.class);
        a3.setArtistName("3");
        a3.setDateOfBirth(c.getTime());

        Painting p1 = context.newObject(Painting.class);
        p1.setEstimatedPrice(new BigDecimal(1));
        p1.setPaintingTitle("Y");
        a1.addToPaintingArray(p1);
View Full Code Here

public class NestedDataContextParentPeerEventsTest extends CayenneCase {

    public void testPeerObjectUpdatedSimpleProperty() throws Exception {
        DataContext context = createDataContext();

        Artist a = context.newObject(Artist.class);
        a.setArtistName("X");
        context.commitChanges();

        DataContext parentPeer = createDataContextWithSharedCache(false);
        Artist a1 = (Artist) parentPeer.localObject(a.getObjectId(), a);

        final ObjectContext peer2 = context.createChildContext();
        final Artist a2 = (Artist) peer2.localObject(a.getObjectId(), a);

        a1.setArtistName("Y");
        assertEquals("X", a2.getArtistName());
        parentPeer.commitChangesToParent();

        new ThreadedTestHelper() {

            @Override
            protected void assertResult() throws Exception {
                assertEquals("Y", a2.getArtistName());

                assertFalse("Peer data context became dirty on event processing", peer2
                        .hasChanges());
            }
        }.assertWithTimeout(2000);
View Full Code Here

    public void testPeerObjectUpdatedToOneRelationship() throws Exception {

        DataContext context = createDataContext();

        Artist a = context.newObject(Artist.class);
        Artist altA = context.newObject(Artist.class);

        Painting p = context.newObject(Painting.class);
        p.setToArtist(a);
        p.setPaintingTitle("PPP");
        a.setArtistName("X");
        altA.setArtistName("Y");
        context.commitChanges();

        DataContext parentPeer = createDataContextWithSharedCache(false);
        Painting p1 = (Painting) parentPeer.localObject(p.getObjectId(), p);
        Artist altA1 = (Artist) parentPeer.localObject(altA.getObjectId(), altA);

        final ObjectContext peer2 = context.createChildContext();
        final Painting p2 = (Painting) peer2.localObject(p.getObjectId(), p);
        final Artist altA2 = (Artist) peer2.localObject(altA.getObjectId(), altA);
        Artist a2 = (Artist) peer2.localObject(a.getObjectId(), a);

        p1.setToArtist(altA1);
        assertSame(a2, p2.getToArtist());
        assertNotSame(altA2, p2.getToArtist());
        parentPeer.commitChangesToParent();
View Full Code Here

    public void testPeerObjectUpdatedToManyRelationship() throws Exception {

        DataContext context = createDataContext();

        Artist a = context.newObject(Artist.class);
        a.setArtistName("X");

        Painting px = context.newObject(Painting.class);
        px.setToArtist(a);
        px.setPaintingTitle("PX");

        Painting py = context.newObject(Painting.class);
        py.setPaintingTitle("PY");

        context.commitChanges();

        DataContext parentPeer = createDataContextWithSharedCache(false);
        Painting py1 = (Painting) parentPeer.localObject(py.getObjectId(), py);
        Artist a1 = (Artist) parentPeer.localObject(a.getObjectId(), a);

        final ObjectContext peer2 = context.createChildContext();
        final Painting py2 = (Painting) peer2.localObject(py.getObjectId(), py);
        final Artist a2 = (Artist) peer2.localObject(a.getObjectId(), a);

        a1.addToPaintingArray(py1);
        assertEquals(1, a2.getPaintingArray().size());
        assertFalse(a2.getPaintingArray().contains(py2));
        parentPeer.commitChangesToParent();

        new ThreadedTestHelper() {

            @Override
            protected void assertResult() throws Exception {
                assertEquals(2, a2.getPaintingArray().size());
                assertTrue(a2.getPaintingArray().contains(py2));

                assertFalse("Peer data context became dirty on event processing", peer2
                        .hasChanges());
            }
        }.assertWithTimeout(2000);
View Full Code Here

    public void testPeerObjectUpdatedTempOID() {
        DataContext context = createDataContext();

        ObjectContext peer1 = context.createChildContext();
        Artist a1 = peer1.newObject(Artist.class);
        a1.setArtistName("Y");
        ObjectId a1TempId = a1.getObjectId();

        ObjectContext peer2 = context.createChildContext();
        Artist a2 = (Artist) peer2.localObject(a1TempId, a1);

        assertEquals(a1TempId, a2.getObjectId());

        peer1.commitChanges();
        assertFalse(a1.getObjectId().isTemporary());
        assertFalse(a2.getObjectId().isTemporary());
        assertEquals(a2.getObjectId(), a1.getObjectId());
    }
View Full Code Here

    }

    public void testPeerObjectUpdatedSimpleProperty() {
        DataContext context = createDataContext();

        Artist a = context.newObject(Artist.class);
        a.setArtistName("X");
        context.commitChanges();

        ObjectContext peer1 = context.createChildContext();
        Artist a1 = (Artist) peer1.localObject(a.getObjectId(), a);

        ObjectContext peer2 = context.createChildContext();
        Artist a2 = (Artist) peer2.localObject(a.getObjectId(), a);

        a1.setArtistName("Y");
        assertEquals("X", a2.getArtistName());
        peer1.commitChangesToParent();
        assertEquals("Y", a2.getArtistName());

        assertFalse("Peer data context became dirty on event processing", peer2
                .hasChanges());
    }
View Full Code Here

    public void testPeerObjectUpdatedToOneRelationship() {

        DataContext context = createDataContext();

        Artist a = context.newObject(Artist.class);
        Artist altA = context.newObject(Artist.class);

        Painting p = context.newObject(Painting.class);
        p.setToArtist(a);
        p.setPaintingTitle("PPP");
        a.setArtistName("X");
        altA.setArtistName("Y");
        context.commitChanges();

        ObjectContext peer1 = context.createChildContext();
        Painting p1 = (Painting) peer1.localObject(p.getObjectId(), p);
        Artist altA1 = (Artist) peer1.localObject(altA.getObjectId(), altA);

        ObjectContext peer2 = context.createChildContext();
        Painting p2 = (Painting) peer2.localObject(p.getObjectId(), p);
        Artist altA2 = (Artist) peer2.localObject(altA.getObjectId(), altA);
        Artist a2 = (Artist) peer2.localObject(a.getObjectId(), a);

        p1.setToArtist(altA1);
        assertSame(a2, p2.getToArtist());
        peer1.commitChangesToParent();
        assertEquals(altA2, p2.getToArtist());
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.