Search in sources :

Example 46 with Painting

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

the class SQLSelectIT method test_Iterator.

@Test
public void test_Iterator() throws Exception {
    createPaintingsDataSet();
    try (ResultIterator<Painting> it = SQLSelect.query(Painting.class, "SELECT * FROM PAINTING").columnNameCaps(CapsStrategy.UPPER).iterator(context)) {
        int count = 0;
        for (Painting p : it) {
            count++;
        }
        assertEquals(20, count);
    }
}
Also used : Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 47 with Painting

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

the class SQLSelectIT method test_DataRows_ClassRoot_Parameters.

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

Example 48 with Painting

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

the class SQLTemplateIT method testSQLTemplateWithDisjointByIdPrefetch.

@Test
public void testSQLTemplateWithDisjointByIdPrefetch() throws Exception {
    tArtist.insert(1, "artist1");
    tArtist.insert(2, "artist2");
    tPainting.insert(1, 1, "p1", 10);
    tPainting.insert(2, 2, "p2", 20);
    String sql = "SELECT p.* FROM PAINTING p";
    SQLTemplate q1 = new SQLTemplate(Painting.class, sql);
    q1.addPrefetch(Painting.TO_ARTIST.disjointById());
    q1.setColumnNamesCapitalization(CapsStrategy.UPPER);
    @SuppressWarnings("unchecked") List<Painting> paintings = context.performQuery(q1);
    queryInterceptor.runWithQueriesBlocked(() -> {
        for (Painting painting : paintings) {
            assertEquals(PersistenceState.COMMITTED, painting.getToArtist().getPersistenceState());
        }
    });
}
Also used : Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 49 with Painting

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

the class SelectQueryIT method testMatchByRelatedObject.

@Test
public void testMatchByRelatedObject() {
    Artist a1 = context.newObject(Artist.class);
    a1.setArtistName("a1");
    Artist a2 = context.newObject(Artist.class);
    a2.setArtistName("a2");
    Painting p1 = context.newObject(Painting.class);
    p1.setPaintingTitle("p1");
    p1.setToArtist(a1);
    Painting p2 = context.newObject(Painting.class);
    p2.setPaintingTitle("p2");
    p2.setToArtist(a2);
    context.commitChanges();
    SelectQuery<Painting> query = new SelectQuery<>(Painting.class);
    query.setQualifier(ExpressionFactory.matchExp("toArtist", a1));
    assertSame(p1, query.selectOne(context));
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 50 with Painting

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

the class SelectQueryIT method testRouteQueryWithPrefetchesPrefetchExpressionPath.

/**
 * Test prefetching with qualifier on the root query being the path to the
 * prefetch.
 */
@Test
public void testRouteQueryWithPrefetchesPrefetchExpressionPath() {
    // find the painting not matching the artist (this is the case where
    // such prefetch
    // at least makes sense)
    Expression exp = ExpressionFactory.noMatchExp("toArtist", new Object());
    SelectQuery<Painting> q = new SelectQuery<>(Painting.class, exp);
    q.addPrefetch("toArtist");
    // test how prefetches are resolved in this case - this was a stumbling
    // block for
    // a while
    EntityResolver resolver = context.getEntityResolver();
    MockQueryRouter router = new MockQueryRouter();
    q.route(router, resolver, null);
    assertEquals(2, router.getQueryCount());
}
Also used : Expression(org.apache.cayenne.exp.Expression) EntityResolver(org.apache.cayenne.map.EntityResolver) 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