Search in sources :

Example 91 with Painting

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

the class DataContextEJBQLFunctionalExpressionsIT method testSIZE.

@Test
public void testSIZE() {
    Artist a1 = context.newObject(Artist.class);
    a1.setArtistName("a1");
    Artist a2 = context.newObject(Artist.class);
    a2.setArtistName("a2");
    Painting p12 = context.newObject(Painting.class);
    p12.setPaintingTitle("p12");
    a2.addToPaintingArray(p12);
    Painting p22 = context.newObject(Painting.class);
    p22.setPaintingTitle("p22");
    a2.addToPaintingArray(p22);
    context.commitChanges();
// this fails:
// EJBQLQuery query = new EJBQLQuery(
// "SELECT d FROM Artist d WHERE SIZE(d.paintingArray) = 2");
// List<?> objects = context.performQuery(query);
// assertEquals(1, objects.size());
// assertTrue(objects.contains(a2));
// 
// EJBQLQuery query2 = new EJBQLQuery(
// "SELECT d FROM Artist d WHERE SIZE(d.paintingArray) = 0");
// List<?> objects2 = context.performQuery(query2);
// assertEquals(1, objects2.size());
// assertTrue(objects2.contains(a1));
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 92 with Painting

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

the class CayenneDataObjectRelationshipsIT method testReadToOneRel3.

@Test
public void testReadToOneRel3() throws Exception {
    createArtistWithPaintingDataSet();
    Painting p1 = Cayenne.objectForPK(context, Painting.class, 6);
    Gallery g1 = p1.getToGallery();
    assertNull(g1);
}
Also used : Gallery(org.apache.cayenne.testdo.testmap.Gallery) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 93 with Painting

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

the class CayenneDataObjectRelationshipsIT method testReadToOneRel1.

@Test
public void testReadToOneRel1() throws Exception {
    createArtistWithPaintingDataSet();
    Painting p1 = Cayenne.objectForPK(context, Painting.class, 6);
    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) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 94 with Painting

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

the class CayenneDataObjectRelationshipsIT method testReciprocalRel1.

@Test
public void testReciprocalRel1() throws Exception {
    createArtistWithPaintingDataSet();
    Painting p1 = Cayenne.objectForPK(context, Painting.class, 6);
    Artist a1 = p1.getToArtist();
    assertNotNull(a1);
    assertEquals("aX", a1.getArtistName());
    List<Painting> paintings = a1.getPaintingArray();
    assertEquals(1, paintings.size());
    Painting p2 = paintings.get(0);
    assertSame(p1, p2);
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 95 with Painting

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

the class CayenneDataObjectRelationshipsIT method testReadToManyRel2.

@Test
public void testReadToManyRel2() throws Exception {
    // test empty relationship
    tArtist.insert(11, "aX");
    Artist a1 = Cayenne.objectForPK(context, Artist.class, 11);
    List<Painting> plist = a1.getPaintingArray();
    assertNotNull(plist);
    assertEquals(0, plist.size());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) 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