Search in sources :

Example 61 with Painting

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

the class EJBQLQueryIT method testRelationshipWhereClause.

// SELECT COUNT(p) from Product p where p.vsCatalog.id = 1 and
// (
// p.displayName like '%rimadyl%'
// or p.manufacturer.name like '%rimadyl%'
// or p.description like '%rimadyl%'
// or p.longdescription like '%rimadyl%'
// or p.longdescription2 like '%rimadyl%'
// or p.manufacturerPartNumber like '%rimadyl%'
// or p.partNumber like '%rimadyl%'
// )
@Test
public void testRelationshipWhereClause() throws Exception {
    Artist a = context.newObject(Artist.class);
    a.setArtistName("a");
    Painting p = context.newObject(Painting.class);
    p.setPaintingTitle("p");
    p.setToArtist(a);
    context.commitChanges();
    EJBQLQuery query = new EJBQLQuery("select p from Painting p where p.toArtist=:a");
    query.setParameter("a", a);
    List<Painting> paintings = context.performQuery(query);
    assertEquals(1, paintings.size());
    assertSame(p, paintings.get(0));
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 62 with Painting

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

the class MappedQueryIT method testSQLTemplateUpdate.

@Test
public void testSQLTemplateUpdate() throws Exception {
    int updated = MappedExec.query("NonSelectingQuery").update(context)[0];
    assertEquals(1, updated);
    Painting painting = ObjectSelect.query(Painting.class).selectOne(context);
    assertEquals("No Painting Like This", painting.getPaintingTitle());
    assertEquals(12.5, painting.getEstimatedPrice().doubleValue(), 0);
}
Also used : Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 63 with Painting

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

the class OrderingTest method testCompare3.

@Test
public void testCompare3() {
    Painting p1 = new Painting();
    p1.setEstimatedPrice(new BigDecimal(1000.00));
    Painting p2 = new Painting();
    p2.setEstimatedPrice(new BigDecimal(2000.00));
    Painting p3 = new Painting();
    p3.setEstimatedPrice(new BigDecimal(2000.00));
    Ordering ordering = new Ordering("estimatedPrice", SortOrder.ASCENDING);
    assertTrue(ordering.compare(p1, p2) < 0);
    assertTrue(ordering.compare(p2, p1) > 0);
    assertTrue(ordering.compare(p2, p3) == 0);
}
Also used : BigDecimal(java.math.BigDecimal) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 64 with Painting

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

the class DataContextEJBQLQueryIT method testSelectFromWhereBetween.

@Test
public void testSelectFromWhereBetween() throws Exception {
    createFourArtistsTwoPaintings();
    String ejbql = "select P from Painting P WHERE p.estimatedPrice BETWEEN 2000 AND 3500";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    List<?> ps = context.performQuery(query);
    assertEquals(1, ps.size());
    Painting p = (Painting) ps.get(0);
    assertEquals("P1", p.getPaintingTitle());
    assertEquals(3000d, p.getEstimatedPrice().doubleValue(), 0.00001);
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 65 with Painting

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

the class DataContextEJBQLQueryIT method testSelectFromWhereAndEqual.

@Test
public void testSelectFromWhereAndEqual() throws Exception {
    createFourArtistsTwoPaintings();
    String ejbql = "select P from Painting P where P.paintingTitle = 'P1' " + "AND p.estimatedPrice = 3000";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    List<?> ps = context.performQuery(query);
    assertEquals(1, ps.size());
    Painting p = (Painting) ps.get(0);
    assertEquals("P1", p.getPaintingTitle());
    assertEquals(3000d, p.getEstimatedPrice().doubleValue(), 0.00001);
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) 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