Search in sources :

Example 96 with Painting

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

the class CayenneDataObjectRelationshipsIT method testComplexInsertUpdateOrdering.

@Test
public void testComplexInsertUpdateOrdering() {
    Artist artist = context.newObject(Artist.class);
    artist.setArtistName("a name");
    context.commitChanges();
    // Cause an update and an insert that need correct ordering
    Painting painting = context.newObject(Painting.class);
    painting.setPaintingTitle("a painting");
    artist.addToPaintingArray(painting);
    context.commitChanges();
    context.deleteObjects(artist);
    context.commitChanges();
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 97 with Painting

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

the class CayenneDataObjectRelationshipsIT method testReadToManyRel1.

@Test
public void testReadToManyRel1() throws Exception {
    createArtistWithPaintingDataSet();
    Artist a1 = Cayenne.objectForPK(context, Artist.class, 8);
    List<Painting> plist = a1.getPaintingArray();
    assertNotNull(plist);
    assertEquals(1, plist.size());
    assertEquals(PersistenceState.COMMITTED, plist.get(0).getPersistenceState());
    assertEquals("pW", plist.get(0).getPaintingTitle());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 98 with Painting

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

the class CayenneDataObjectRelationshipsIT method testReadToOneRel2.

@Test
public void testReadToOneRel2() throws Exception {
    // test chained calls to read relationships
    createArtistWithPaintingAndInfoDataSet();
    PaintingInfo pi1 = Cayenne.objectForPK(context, PaintingInfo.class, 6);
    Painting p1 = pi1.getPainting();
    p1.getPaintingTitle();
    Artist a1 = p1.getToArtist();
    assertNotNull(a1);
    assertEquals(PersistenceState.HOLLOW, a1.getPersistenceState());
    assertEquals("aX", a1.getArtistName());
    assertEquals(PersistenceState.COMMITTED, a1.getPersistenceState());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) PaintingInfo(org.apache.cayenne.testdo.testmap.PaintingInfo) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 99 with Painting

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

the class CayenneDataObjectSetToManyListIT method testRemoveOneOldAndAddOneNewPaintings.

@Test
public void testRemoveOneOldAndAddOneNewPaintings() throws Exception {
    createArtistWithPaintingDataSet();
    Artist artist = Cayenne.objectForPK(context, Artist.class, 8);
    List<Painting> newPaints = new ArrayList<Painting>();
    Painting paint6 = artist.getPaintingArray().get(0);
    Painting paint7 = artist.getPaintingArray().get(1);
    Painting paint8 = artist.getPaintingArray().get(2);
    Painting paintX = new Painting();
    paintX.setPaintingTitle("pantingX");
    Painting paintY = new Painting();
    paintY.setPaintingTitle("paintingY");
    newPaints.add(paint6);
    newPaints.add(paint7);
    newPaints.add(paintX);
    newPaints.add(paintY);
    List<? extends DataObject> returnList = artist.setToManyTarget(Artist.PAINTING_ARRAY.getName(), newPaints, true);
    assertEquals(returnList.size(), 1);
    assertEquals(returnList.get(0) == paint8, true);
    List<Painting> newPaints2 = artist.getPaintingArray();
    assertEquals(newPaints2.size(), 4);
    assertEquals(newPaints2.contains(paintX), true);
    assertEquals(newPaints2.contains(paintY), true);
    assertEquals(newPaints2.contains(paint6), true);
    assertEquals(newPaints2.contains(paint7), true);
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) ArrayList(java.util.ArrayList) ROPainting(org.apache.cayenne.testdo.testmap.ROPainting) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 100 with Painting

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

the class DataContextMaxIdQualifierIT method testIncrementalFaultList_Lower.

@Test
public void testIncrementalFaultList_Lower() throws Exception {
    insertData_OneBag_100Boxes();
    runtime.getDataDomain().setMaxIdQualifierSize(5);
    final SelectQuery query = new SelectQuery(Painting.class);
    query.setPageSize(10);
    int queriesCount = queryInterceptor.runWithQueryCounter(new UnitTestClosure() {

        public void execute() {
            final List<Painting> boxes = context.performQuery(query);
            for (Painting box : boxes) {
                box.getToArtist();
            }
        }
    });
    assertEquals(21, queriesCount);
    queriesCount = queryInterceptor.runWithQueryCounter(new UnitTestClosure() {

        public void execute() {
            final List<Painting> boxes = context.performQuery(query);
            List<Painting> tempList = new ArrayList<Painting>();
            tempList.addAll(boxes);
        }
    });
    assertEquals(21, queriesCount);
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) 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