Search in sources :

Example 81 with Artist

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

the class ProcedureCallIT method testSelect.

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

Example 82 with Artist

use of org.apache.cayenne.testdo.testmap.Artist 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 83 with Artist

use of org.apache.cayenne.testdo.testmap.Artist 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 84 with Artist

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

the class SelectById_RunIT method testIntPk.

@Test
public void testIntPk() throws Exception {
    createTwoArtists();
    Artist a3 = SelectById.query(Artist.class, 3).selectOne(context);
    assertNotNull(a3);
    assertEquals("artist3", a3.getArtistName());
    Artist a2 = SelectById.query(Artist.class, 2).selectOne(context);
    assertNotNull(a2);
    assertEquals("artist2", a2.getArtistName());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Test(org.junit.Test)

Example 85 with Artist

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

the class SelectById_RunIT method testLocalCache.

@Test
public void testLocalCache() throws Exception {
    createTwoArtists();
    final Artist[] a3 = new Artist[1];
    assertEquals(1, interceptor.runWithQueryCounter(new UnitTestClosure() {

        @Override
        public void execute() {
            a3[0] = SelectById.query(Artist.class, 3).localCache("g1").selectOne(context);
            assertNotNull(a3[0]);
            assertEquals("artist3", a3[0].getArtistName());
        }
    }));
    interceptor.runWithQueriesBlocked(new UnitTestClosure() {

        @Override
        public void execute() {
            Artist a3cached = SelectById.query(Artist.class, 3).localCache("g1").selectOne(context);
            assertSame(a3[0], a3cached);
        }
    });
    context.performGenericQuery(new RefreshQuery("g1"));
    assertEquals(1, interceptor.runWithQueryCounter(new UnitTestClosure() {

        @Override
        public void execute() {
            SelectById.query(Artist.class, 3).localCache("g1").selectOne(context);
        }
    }));
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) Test(org.junit.Test)

Aggregations

Artist (org.apache.cayenne.testdo.testmap.Artist)490 Test (org.junit.Test)481 Painting (org.apache.cayenne.testdo.testmap.Painting)145 SelectQuery (org.apache.cayenne.query.SelectQuery)126 Expression (org.apache.cayenne.exp.Expression)67 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)47 EJBQLQuery (org.apache.cayenne.query.EJBQLQuery)39 List (java.util.List)36 ObjectContext (org.apache.cayenne.ObjectContext)30 SQLTemplate (org.apache.cayenne.query.SQLTemplate)26 ParallelTestContainer (org.apache.cayenne.test.parallel.ParallelTestContainer)26 DataRow (org.apache.cayenne.DataRow)21 ArrayList (java.util.ArrayList)20 ValueHolder (org.apache.cayenne.ValueHolder)18 ArtGroup (org.apache.cayenne.testdo.testmap.ArtGroup)16 LifecycleCallbackRegistry (org.apache.cayenne.reflect.LifecycleCallbackRegistry)15 ObjectId (org.apache.cayenne.ObjectId)14 ROPainting (org.apache.cayenne.testdo.testmap.ROPainting)13 Gallery (org.apache.cayenne.testdo.testmap.Gallery)12 ROArtist (org.apache.cayenne.testdo.testmap.ROArtist)12