Search in sources :

Example 41 with Painting

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

the class ProcedureCallIT method testSelectDataObject.

@Test
public void testSelectDataObject() throws Exception {
    if (!accessStackAdapter.supportsStoredProcedures()) {
        return;
    }
    if (!accessStackAdapter.canMakeObjectsOutOfProcedures()) {
        return;
    }
    // create an artist with painting in the database
    createArtist(1101.01);
    List<Artist> artists = runProcedureSelect(ProcedureCall.query(SELECT_STORED_PROCEDURE, Artist.class).param("aName", "An Artist")).firstList();
    // check the results
    assertNotNull("Null result from StoredProcedure.", artists);
    assertEquals(1, artists.size());
    Artist a = (Artist) artists.get(0);
    Painting p = a.getPaintingArray().get(0);
    // invalidate painting, it may have been updated in the proc
    context.invalidateObjects(p);
    assertEquals(1101.01, p.getEstimatedPrice().doubleValue(), 0.02);
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 42 with Painting

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

the class ProcedureCallIT method testUpdate.

@Test
public void testUpdate() throws Exception {
    if (!accessStackAdapter.supportsStoredProcedures()) {
        return;
    }
    // create an artist with painting in the database
    createArtist(1000.0);
    runProcedureSelect(ProcedureCall.query(UPDATE_STORED_PROCEDURE).param("paintingPrice", 3000));
    // check that price have doubled
    SelectQuery select = new SelectQuery<>(Artist.class);
    select.addPrefetch("paintingArray");
    List artists = context.performQuery(select);
    assertEquals(1, artists.size());
    Artist a = (Artist) artists.get(0);
    Painting p = a.getPaintingArray().get(0);
    assertEquals(2000, p.getEstimatedPrice().intValue());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) List(java.util.List) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 43 with Painting

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

the class SQLSelectIT method test_SelectOne.

@Test
public void test_SelectOne() throws Exception {
    createPaintingsDataSet();
    Painting a = SQLSelect.query(Painting.class, "SELECT * FROM PAINTING WHERE PAINTING_TITLE = #bind($a)").params("a", "painting3").columnNameCaps(CapsStrategy.UPPER).selectOne(context);
    assertEquals("painting3", a.getPaintingTitle());
}
Also used : Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 44 with Painting

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

the class SQLSelectIT method test_SelectFirst.

@Test
public void test_SelectFirst() throws Exception {
    createPaintingsDataSet();
    Painting p = SQLSelect.query(Painting.class, "SELECT * FROM PAINTING ORDER BY PAINTING_TITLE").columnNameCaps(CapsStrategy.UPPER).selectFirst(context);
    assertNotNull(p);
    assertEquals("painting1", p.getPaintingTitle());
}
Also used : Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 45 with Painting

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

the class SQLSelectIT method test_SelectFirstByContext.

@Test
public void test_SelectFirstByContext() throws Exception {
    createPaintingsDataSet();
    SQLSelect<Painting> q = SQLSelect.query(Painting.class, "SELECT * FROM PAINTING ORDER BY PAINTING_TITLE").columnNameCaps(CapsStrategy.UPPER);
    Painting p = context.selectFirst(q);
    assertNotNull(p);
    assertEquals("painting1", p.getPaintingTitle());
}
Also used : 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