Search in sources :

Example 71 with Painting

use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.

the class DataContextIteratedQueryIT method testPerformIteratedQuery_CommitWithinIterator.

@Test
public void testPerformIteratedQuery_CommitWithinIterator() throws Exception {
    createArtistsAndPaintingsDataSet();
    assertEquals(7, tPainting.getRowCount());
    try (ResultIterator<?> it = context.performIteratedQuery(SelectQuery.query(Artist.class))) {
        while (it.hasNextRow()) {
            DataRow row = (DataRow) it.nextRow();
            Artist artist = context.objectFromDataRow(Artist.class, row);
            Painting painting = context.newObject(Painting.class);
            painting.setPaintingTitle("P_" + artist.getArtistName());
            painting.setToArtist(artist);
            context.commitChanges();
        }
    }
    assertEquals(14, tPainting.getRowCount());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) DataRow(org.apache.cayenne.DataRow) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 72 with Painting

use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.

the class DataContextIteratedQueryIT method testPerformIteratedQuery_resolve.

@Test
public void testPerformIteratedQuery_resolve() throws Exception {
    createArtistsAndPaintingsDataSet();
    try (ResultIterator<?> it = context.performIteratedQuery(SelectQuery.query(Artist.class))) {
        while (it.hasNextRow()) {
            DataRow row = (DataRow) it.nextRow();
            // try instantiating an object and fetching its relationships
            Artist artist = context.objectFromDataRow(Artist.class, row);
            List<Painting> paintings = artist.getPaintingArray();
            assertNotNull(paintings);
            assertEquals("Expected one painting for artist: " + artist, 1, paintings.size());
        }
    }
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) DataRow(org.apache.cayenne.DataRow) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 73 with Painting

use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.

the class DataContextPerformQueryAPIIT method testNonSelectingQueryString.

@Test
public void testNonSelectingQueryString() throws Exception {
    int[] counts = context.performNonSelectingQuery("NonSelectingQuery");
    assertNotNull(counts);
    assertEquals(1, counts.length);
    assertEquals(1, counts[0]);
    Painting p = Cayenne.objectForPK(context, Painting.class, 512);
    assertEquals("No Painting Like This", p.getPaintingTitle());
}
Also used : Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 74 with Painting

use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.

the class DataContextPrefetchIT method testPrefetchToOneWithBackRelationship.

@Test
public void testPrefetchToOneWithBackRelationship() throws Exception {
    createArtistWithTwoPaintingsAndTwoInfosDataSet();
    SelectQuery<Painting> query = new SelectQuery<Painting>(Painting.class);
    query.andQualifier(Painting.PAINTING_TITLE.eq("p_artist2"));
    query.addPrefetch(Painting.TO_PAINTING_INFO.disjoint());
    query.addPrefetch(Painting.TO_PAINTING_INFO.dot(PaintingInfo.PAINTING).disjoint());
    final List<Painting> results = context.select(query);
    queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            assertEquals(1, results.size());
            Painting p0 = results.get(0);
            PaintingInfo pi0 = (PaintingInfo) p0.readPropertyDirectly(Painting.TO_PAINTING_INFO.getName());
            assertNotNull(pi0);
            assertNotNull(pi0.readPropertyDirectly(PaintingInfo.PAINTING.getName()));
        }
    });
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) PaintingInfo(org.apache.cayenne.testdo.testmap.PaintingInfo) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 75 with Painting

use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.

the class DataContextPrefetchIT method testPrefetch_ToOneWithQualifierOverlappingPrefetchPath.

@Test
public void testPrefetch_ToOneWithQualifierOverlappingPrefetchPath() throws Exception {
    createTwoArtistsAndTwoPaintingsDataSet();
    Expression exp = ExpressionFactory.matchExp("toArtist.artistName", "artist3");
    SelectQuery q = new SelectQuery(Painting.class, exp);
    q.addPrefetch(Painting.TO_ARTIST.disjoint());
    final List<Painting> results = context.performQuery(q);
    queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            assertEquals(1, results.size());
            Painting painting = results.get(0);
            // The parent must be fully fetched, not just HOLLOW (a fault)
            assertEquals(PersistenceState.COMMITTED, painting.getToArtist().getPersistenceState());
        }
    });
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) Expression(org.apache.cayenne.exp.Expression) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Aggregations

Painting (org.apache.cayenne.testdo.testmap.Painting)222 Test (org.junit.Test)218 Artist (org.apache.cayenne.testdo.testmap.Artist)144 SelectQuery (org.apache.cayenne.query.SelectQuery)75 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)35 List (java.util.List)30 Expression (org.apache.cayenne.exp.Expression)29 ArrayList (java.util.ArrayList)21 BigDecimal (java.math.BigDecimal)19 PaintingInfo (org.apache.cayenne.testdo.testmap.PaintingInfo)14 ObjectContext (org.apache.cayenne.ObjectContext)13 EJBQLQuery (org.apache.cayenne.query.EJBQLQuery)13 Gallery (org.apache.cayenne.testdo.testmap.Gallery)13 ValueHolder (org.apache.cayenne.ValueHolder)12 ROPainting (org.apache.cayenne.testdo.testmap.ROPainting)12 SQLTemplate (org.apache.cayenne.query.SQLTemplate)11 DataRow (org.apache.cayenne.DataRow)7 ProcedureQuery (org.apache.cayenne.query.ProcedureQuery)6 LifecycleCallbackRegistry (org.apache.cayenne.reflect.LifecycleCallbackRegistry)6 RefreshQuery (org.apache.cayenne.query.RefreshQuery)5