Search in sources :

Example 1 with CompoundPainting

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

the class DataContextFlattenedAttributesIT method testSelectCompound2.

// TODO: andrus 1/5/2007 - CAY-952: SelectQuery uses INNER JOIN for flattened
// attributes, while
// EJBQLQuery does an OUTER JOIN... which seems like a better idea...
// 14/01/2010 now it uses LEFT JOIN
@Test
public void testSelectCompound2() throws Exception {
    createTestDataSet();
    SelectQuery query = new SelectQuery(CompoundPainting.class, ExpressionFactory.matchExp("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);
    for (Iterator<?> i = objects.iterator(); i.hasNext(); ) {
        CompoundPainting painting = (CompoundPainting) i.next();
        assertEquals(PersistenceState.COMMITTED, painting.getPersistenceState());
        assertEquals("CompoundPainting.getArtistName(): " + painting.getArtistName(), "artist2", painting.getArtistName());
        assertEquals("CompoundPainting.getArtistName(): " + 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 2 with CompoundPainting

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

the class DataContextFlattenedAttributesIT method testSelectEJQBQLLike.

@Test
public void testSelectEJQBQLLike() throws Exception {
    createTestDataSet();
    EJBQLQuery query = new EJBQLQuery("SELECT a FROM CompoundPainting a WHERE a.artistName LIKE 'artist%' " + "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)

Example 3 with CompoundPainting

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

the class DataContextFlattenedAttributesIT method testDelete.

@Test
public void testDelete() throws Exception {
    // throw in a bit of random overlapping data, to make sure FK/PK correspondence is
    // not purely coincidental
    Artist a = context.newObject(Artist.class);
    a.setArtistName("AX");
    context.commitChanges();
    CompoundPainting o1 = context.newObject(CompoundPainting.class);
    o1.setArtistName("A1");
    o1.setEstimatedPrice(new BigDecimal(1.0d));
    o1.setGalleryName("G1");
    o1.setPaintingTitle("P1");
    o1.setTextReview("T1");
    context.commitChanges();
    context.deleteObjects(o1);
    context.commitChanges();
    Number artistCount = (Number) Cayenne.objectForQuery(context, new EJBQLQuery("select count(a) from Artist a"));
    assertEquals(1, artistCount.intValue());
    Number paintingCount = (Number) Cayenne.objectForQuery(context, new EJBQLQuery("select count(a) from Painting a"));
    assertEquals(0, paintingCount.intValue());
    Number galleryCount = (Number) Cayenne.objectForQuery(context, new EJBQLQuery("select count(a) from Gallery a"));
    assertEquals(0, galleryCount.intValue());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) CompoundPainting(org.apache.cayenne.testdo.testmap.CompoundPainting) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 4 with CompoundPainting

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

the class DataContextFlattenedAttributesIT method testUpdate.

@Test
public void testUpdate() {
    CompoundPainting o1 = context.newObject(CompoundPainting.class);
    o1.setArtistName("A1");
    o1.setEstimatedPrice(new BigDecimal(1d));
    o1.setGalleryName("G1");
    o1.setPaintingTitle("P1");
    o1.setTextReview("T1");
    context.commitChanges();
    o1.setArtistName("X1");
    o1.setEstimatedPrice(new BigDecimal(2d));
    o1.setGalleryName("X1");
    o1.setPaintingTitle("X1");
    o1.setTextReview("X1");
    context.commitChanges();
}
Also used : CompoundPainting(org.apache.cayenne.testdo.testmap.CompoundPainting) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 5 with CompoundPainting

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

the class DataContextFlattenedAttributesIT method testInsert.

@Test
public void testInsert() {
    CompoundPainting o1 = context.newObject(CompoundPainting.class);
    o1.setArtistName("A1");
    o1.setEstimatedPrice(new BigDecimal(1.0d));
    o1.setGalleryName("G1");
    o1.setPaintingTitle("P1");
    o1.setTextReview("T1");
    context.commitChanges();
    Number artistCount = (Number) Cayenne.objectForQuery(context, new EJBQLQuery("select count(a) from Artist a"));
    assertEquals(1, artistCount.intValue());
    Number paintingCount = (Number) Cayenne.objectForQuery(context, new EJBQLQuery("select count(a) from Painting a"));
    assertEquals(1, paintingCount.intValue());
    Number galleryCount = (Number) Cayenne.objectForQuery(context, new EJBQLQuery("select count(a) from Gallery a"));
    assertEquals(1, galleryCount.intValue());
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) CompoundPainting(org.apache.cayenne.testdo.testmap.CompoundPainting) BigDecimal(java.math.BigDecimal) 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