Search in sources :

Example 81 with EJBQLQuery

use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.

the class DataContextEJBQLNumericalFunctionalIT method testSQRT.

@Test
public void testSQRT() {
    BigDecimalEntity o1 = context.newObject(BigDecimalEntity.class);
    o1.setBigDecimalField(new BigDecimal("9"));
    BigDecimalEntity o2 = context.newObject(BigDecimalEntity.class);
    o2.setBigDecimalField(new BigDecimal("16"));
    context.commitChanges();
    EJBQLQuery query = new EJBQLQuery("SELECT d FROM BigDecimalEntity d WHERE SQRT(d.bigDecimalField) > 3.1");
    List<?> objects = context.performQuery(query);
    assertEquals(1, objects.size());
    assertTrue(objects.contains(o2));
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) BigDecimalEntity(org.apache.cayenne.testdo.numeric_types.BigDecimalEntity) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 82 with EJBQLQuery

use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.

the class DataContextEJBQLNumericalFunctionalIT method testMOD.

@Test
public void testMOD() {
    BigIntegerEntity o1 = context.newObject(BigIntegerEntity.class);
    o1.setBigIntegerField(new BigInteger("9"));
    BigIntegerEntity o2 = context.newObject(BigIntegerEntity.class);
    o2.setBigIntegerField(new BigInteger("10"));
    context.commitChanges();
    EJBQLQuery query = new EJBQLQuery("SELECT d FROM BigIntegerEntity d WHERE MOD(d.bigIntegerField, 4) = 2");
    List<?> objects = context.performQuery(query);
    assertEquals(1, objects.size());
    assertTrue(objects.contains(o2));
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) BigInteger(java.math.BigInteger) BigIntegerEntity(org.apache.cayenne.testdo.numeric_types.BigIntegerEntity) Test(org.junit.Test)

Example 83 with EJBQLQuery

use of org.apache.cayenne.query.EJBQLQuery 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 84 with EJBQLQuery

use of org.apache.cayenne.query.EJBQLQuery 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)

Example 85 with EJBQLQuery

use of org.apache.cayenne.query.EJBQLQuery in project cayenne by apache.

the class DataContextEJBQLOrderByIT method testOrderByDesc.

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

Aggregations

EJBQLQuery (org.apache.cayenne.query.EJBQLQuery)160 Test (org.junit.Test)158 Artist (org.apache.cayenne.testdo.testmap.Artist)39 HashSet (java.util.HashSet)35 Painting (org.apache.cayenne.testdo.testmap.Painting)15 QueryResponse (org.apache.cayenne.QueryResponse)12 BigDecimal (java.math.BigDecimal)10 Persistent (org.apache.cayenne.Persistent)10 List (java.util.List)9 ArrayList (java.util.ArrayList)7 FlattenedTest1 (org.apache.cayenne.testdo.relationships_flattened.FlattenedTest1)6 CompoundPainting (org.apache.cayenne.testdo.testmap.CompoundPainting)5 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)5 HashMap (java.util.HashMap)4 Iterator (java.util.Iterator)4 ValueHolder (org.apache.cayenne.ValueHolder)4 CompoundPkTestEntity (org.apache.cayenne.testdo.compound.CompoundPkTestEntity)4 Gallery (org.apache.cayenne.testdo.testmap.Gallery)4 Calendar (java.util.Calendar)3 EJBQLCompiledExpression (org.apache.cayenne.ejbql.EJBQLCompiledExpression)3