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());
}
}
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++;
}
}
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());
}
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();
}
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());
}
Aggregations