Search in sources :

Example 31 with Persistent

use of org.apache.cayenne.Persistent in project cayenne by apache.

the class DataContextEJBQLIsNullIT method testIsNull.

@Test
public void testIsNull() throws Exception {
    createTwoPaintings();
    String ejbql1 = "SELECT p FROM Painting p WHERE p.estimatedPrice IS NULL";
    EJBQLQuery query1 = new EJBQLQuery(ejbql1);
    List<?> results = context.performQuery(query1);
    assertEquals(1, results.size());
    assertEquals(33001, Cayenne.intPKForObject((Persistent) results.get(0)));
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) Persistent(org.apache.cayenne.Persistent) Test(org.junit.Test)

Example 32 with Persistent

use of org.apache.cayenne.Persistent in project cayenne by apache.

the class DataContextEJBQLIsNullIT method testToOneIsNull.

@Test
public void testToOneIsNull() throws Exception {
    createTwoPaintingsAndOneArtist();
    String ejbql1 = "SELECT p FROM Painting p WHERE p.toArtist IS NULL";
    EJBQLQuery query1 = new EJBQLQuery(ejbql1);
    List<?> results = context.performQuery(query1);
    assertEquals(1, results.size());
    assertEquals(33001, Cayenne.intPKForObject((Persistent) results.get(0)));
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) Persistent(org.apache.cayenne.Persistent) Test(org.junit.Test)

Example 33 with Persistent

use of org.apache.cayenne.Persistent in project cayenne by apache.

the class DataContextEJBQLIsNullIT method testToOneIsNotNull.

@Test
public void testToOneIsNotNull() throws Exception {
    createTwoPaintingsAndOneArtist();
    String ejbql1 = "SELECT p FROM Painting p WHERE p.toArtist IS NOT NULL";
    EJBQLQuery query1 = new EJBQLQuery(ejbql1);
    List<?> results = context.performQuery(query1);
    assertEquals(1, results.size());
    assertEquals(33003, Cayenne.intPKForObject((Persistent) results.get(0)));
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) Persistent(org.apache.cayenne.Persistent) Test(org.junit.Test)

Example 34 with Persistent

use of org.apache.cayenne.Persistent in project cayenne by apache.

the class DataContextEJBQLOrderByIT method testOrderByAsc.

@Test
public void testOrderByAsc() throws Exception {
    createThreePaintings();
    String ejbql1 = "SELECT p FROM Painting p ORDER BY p.paintingTitle ASC";
    EJBQLQuery query1 = new EJBQLQuery(ejbql1);
    List<?> results1 = context.performQuery(query1);
    assertEquals(3, results1.size());
    assertEquals(33001, Cayenne.intPKForObject((Persistent) results1.get(0)));
    assertEquals(33002, Cayenne.intPKForObject((Persistent) results1.get(1)));
    assertEquals(33003, Cayenne.intPKForObject((Persistent) results1.get(2)));
    String ejbql2 = "SELECT p FROM Painting p ORDER BY p.estimatedPrice ASC";
    EJBQLQuery query2 = new EJBQLQuery(ejbql2);
    List<?> results2 = context.performQuery(query2);
    assertEquals(3, results2.size());
    assertEquals(33003, Cayenne.intPKForObject((Persistent) results2.get(0)));
    assertEquals(33002, Cayenne.intPKForObject((Persistent) results2.get(1)));
    assertEquals(33001, Cayenne.intPKForObject((Persistent) results2.get(2)));
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) Persistent(org.apache.cayenne.Persistent) Test(org.junit.Test)

Example 35 with Persistent

use of org.apache.cayenne.Persistent in project cayenne by apache.

the class DataContextEJBQLOrderByIT method testOrderByMultiple.

@Test
public void testOrderByMultiple() throws Exception {
    createFourPaintings();
    String ejbql1 = "SELECT p FROM Painting p ORDER BY p.paintingTitle DESC, p.estimatedPrice DESC";
    EJBQLQuery query1 = new EJBQLQuery(ejbql1);
    List<?> results1 = context.performQuery(query1);
    assertEquals(4, results1.size());
    assertEquals(33003, Cayenne.intPKForObject((Persistent) results1.get(0)));
    assertEquals(33004, Cayenne.intPKForObject((Persistent) results1.get(1)));
    assertEquals(33002, Cayenne.intPKForObject((Persistent) results1.get(2)));
    assertEquals(33001, Cayenne.intPKForObject((Persistent) results1.get(3)));
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) Persistent(org.apache.cayenne.Persistent) Test(org.junit.Test)

Aggregations

Persistent (org.apache.cayenne.Persistent)88 ObjectId (org.apache.cayenne.ObjectId)38 Test (org.junit.Test)32 ArrayList (java.util.ArrayList)17 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)17 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)17 DataObject (org.apache.cayenne.DataObject)13 Map (java.util.Map)12 ObjEntity (org.apache.cayenne.map.ObjEntity)10 EJBQLQuery (org.apache.cayenne.query.EJBQLQuery)10 AttributeProperty (org.apache.cayenne.reflect.AttributeProperty)10 DataRow (org.apache.cayenne.DataRow)8 PropertyVisitor (org.apache.cayenne.reflect.PropertyVisitor)8 ToManyProperty (org.apache.cayenne.reflect.ToManyProperty)8 ToOneProperty (org.apache.cayenne.reflect.ToOneProperty)8 Collection (java.util.Collection)7 HashMap (java.util.HashMap)7 ObjectContext (org.apache.cayenne.ObjectContext)6 DbEntity (org.apache.cayenne.map.DbEntity)6 List (java.util.List)5