Search in sources :

Example 6 with CompoundPainting

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

the class DataContextFlattenedAttributesIT method testSelectCompound1.

@Test
public void testSelectCompound1() throws Exception {
    createTestDataSet();
    SelectQuery query = new SelectQuery(CompoundPainting.class);
    List<?> objects = context.performQuery(query);
    assertNotNull(objects);
    assertEquals(8, objects.size());
    assertTrue("CompoundPainting expected, got " + objects.get(0).getClass(), objects.get(0) instanceof CompoundPainting);
    for (Iterator<?> i = objects.iterator(); i.hasNext(); ) {
        CompoundPainting painting = (CompoundPainting) i.next();
        Number id = (Number) painting.getObjectId().getIdSnapshot().get("PAINTING_ID");
        assertEquals("CompoundPainting.getPaintingTitle(): " + painting.getPaintingTitle(), "painting" + id, painting.getPaintingTitle());
        if (painting.getToPaintingInfo() == null) {
            assertNull(painting.getTextReview());
        } else {
            assertEquals("CompoundPainting.getTextReview(): " + painting.getTextReview(), "painting review" + id, painting.getTextReview());
        }
        assertEquals("CompoundPainting.getArtistName(): " + painting.getArtistName(), painting.getToArtist().getArtistName(), painting.getArtistName());
        if (painting.getToGallery() == null) {
            assertNull(painting.getGalleryName());
        } else {
            assertEquals("CompoundPainting.getGalleryName(): " + painting.getGalleryName(), painting.getToGallery().getGalleryName(), painting.getGalleryName());
        }
    }
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) CompoundPainting(org.apache.cayenne.testdo.testmap.CompoundPainting) Test(org.junit.Test)

Example 7 with CompoundPainting

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

the class DataContextFlattenedAttributesIT method testSelectEJQBQL.

@Test
public void testSelectEJQBQL() throws Exception {
    createTestDataSet();
    EJBQLQuery query = new EJBQLQuery("SELECT a FROM CompoundPainting a WHERE a.artistName = 'artist2'");
    List<?> objects = context.performQuery(query);
    assertNotNull(objects);
    assertEquals(2, objects.size());
    assertTrue("CompoundPainting expected, got " + objects.get(0).getClass(), objects.get(0) instanceof CompoundPainting);
    Iterator<?> i = objects.iterator();
    while (i.hasNext()) {
        CompoundPainting painting = (CompoundPainting) i.next();
        assertEquals(PersistenceState.COMMITTED, painting.getPersistenceState());
    }
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) CompoundPainting(org.apache.cayenne.testdo.testmap.CompoundPainting) Test(org.junit.Test)

Example 8 with CompoundPainting

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

the class DataContextFlattenedAttributesIT method testSelectEJQBQLBetween.

@Test
public void testSelectEJQBQLBetween() throws Exception {
    createTestDataSet();
    EJBQLQuery query = new EJBQLQuery("SELECT a FROM CompoundPainting a " + "WHERE a.artistName BETWEEN 'artist1' AND 'artist4' " + "ORDER BY a.paintingTitle");
    List<?> objects = context.performQuery(query);
    assertNotNull(objects);
    assertEquals(8, objects.size());
    Iterator<?> i = objects.iterator();
    int index = 1;
    while (i.hasNext()) {
        CompoundPainting painting = (CompoundPainting) i.next();
        assertEquals("painting" + index, painting.getPaintingTitle());
        index++;
    }
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) CompoundPainting(org.apache.cayenne.testdo.testmap.CompoundPainting) Test(org.junit.Test)

Aggregations

CompoundPainting (org.apache.cayenne.testdo.testmap.CompoundPainting)8 Test (org.junit.Test)8 EJBQLQuery (org.apache.cayenne.query.EJBQLQuery)5 BigDecimal (java.math.BigDecimal)3 SelectQuery (org.apache.cayenne.query.SelectQuery)2 Artist (org.apache.cayenne.testdo.testmap.Artist)1