Package org.apache.cayenne.testdo.testmap

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


            queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

                public void execute() {
                    assertFalse(result.isEmpty());
                    Artist a1 = result.get(0);
                    List<?> toMany = (List<?>) a1.readPropertyDirectly("paintingArray");
                    assertNotNull(toMany);
                    assertFalse(((ValueHolder) toMany).isFault());
                }
            });
View Full Code Here


                assertNotNull(toOnePrefetch);
                assertTrue(
                        "Expected Artist, got: " + toOnePrefetch.getClass().getName(),
                        toOnePrefetch instanceof Artist);

                Artist a1 = (Artist) toOnePrefetch;
                assertEquals(PersistenceState.COMMITTED, a1.getPersistenceState());
            }
        });
    }
View Full Code Here

    public void testPrefetch9() throws Exception {
        createTwoArtistsAndTwoPaintingsDataSet();

        Expression artistExp = ExpressionFactory.matchExp("artistName", "artist3");
        SelectQuery artistQuery = new SelectQuery(Artist.class, artistExp);
        Artist artist1 = (Artist) context.performQuery(artistQuery).get(0);

        // find the painting not matching the artist (this is the case where such prefetch
        // at least makes sense)
        Expression exp = ExpressionFactory.noMatchExp("toArtist", artist1);

        SelectQuery q = new SelectQuery(Painting.class, exp);
        q.addPrefetch("toArtist");

        final List<Painting> results = context.performQuery(q);

        queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

            public void execute() {
                assertEquals(1, results.size());

                // see that artists are resolved...

                Painting px = results.get(0);
                Artist ax = (Artist) px.readProperty(Painting.TO_ARTIST_PROPERTY);
                assertEquals(PersistenceState.COMMITTED, ax.getPersistenceState());
            }
        });
    }
View Full Code Here

                assertNotNull(toOnePrefetch);
                assertTrue(
                        "Expected Artist, got: " + toOnePrefetch.getClass().getName(),
                        toOnePrefetch instanceof Artist);

                Artist a1 = (Artist) toOnePrefetch;
                assertEquals(PersistenceState.COMMITTED, a1.getPersistenceState());

                // and just in case - run one more time...
                context.performQuery(q);
            }
        });
View Full Code Here

                assertNotNull(toOnePrefetch);
                assertTrue(
                        "Expected Artist, got: " + toOnePrefetch.getClass().getName(),
                        toOnePrefetch instanceof Artist);

                Artist a1 = (Artist) toOnePrefetch;
                assertEquals(PersistenceState.COMMITTED, a1.getPersistenceState());

                // and just in case - run one more time...
                context.performQuery(q);
            }
        });
View Full Code Here

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

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

        Artist a = Cayenne.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());
        assertTrue(related.contains(a));
        assertEquals("a1", a.getArtistName());
        assertEquals(v, a.getSnapshotVersion());
        assertEquals(
                "Looks like relationship query caused snapshot refresh",
                writeCalls,
                a.getPropertyWrittenDirectly());
    }
View Full Code Here

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

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

        Artist a = Cayenne.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());
        assertTrue(related.contains(a));
        assertEquals("a2", a.getArtistName());
        assertTrue("Looks like relationship query didn't cause a snapshot refresh", v < a
                .getSnapshotVersion());
        assertTrue(
                "Looks like relationship query didn't cause a snapshot refresh",
                writeCalls < a.getPropertyWrittenDirectly());
    }
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);

        assertEquals(2, a1.getPaintingArray().size());
        assertEquals(0, a2.getPaintingArray().size());

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

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

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

        assertEquals(PersistenceState.HOLLOW, a1.getPersistenceState());
        assertEquals(PersistenceState.HOLLOW, a2.getPersistenceState());

        assertTrue(((ValueHolder) a1.readProperty(Artist.PAINTING_ARRAY_PROPERTY))
                .isFault());
        assertTrue(((ValueHolder) a2.readProperty(Artist.PAINTING_ARRAY_PROPERTY))
                .isFault());
    }
View Full Code Here

        List paints = context.performQuery(q);

        Painting p1 = (Painting) paints.get(0);
        Painting p2 = (Painting) paints.get(1);

        Artist a1 = p1.getToArtist();
        assertSame(a1, p2.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);

        assertEquals(2, a1.getPaintingArray().size());

        assertNotNull(context
                .getParentDataDomain()
                .getSharedSnapshotCache()
                .getCachedSnapshot(a1.getObjectId()));

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

        assertNull(context
                .getParentDataDomain()
                .getSharedSnapshotCache()
                .getCachedSnapshot(a1.getObjectId()));

        assertEquals(PersistenceState.HOLLOW, a1.getPersistenceState());

        assertTrue(((ValueHolder) a1.readProperty(Artist.PAINTING_ARRAY_PROPERTY))
                .isFault());
    }
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.