Search in sources :

Example 1 with BigDecimalEntity

use of org.apache.cayenne.testdo.numeric_types.BigDecimalEntity in project cayenne by apache.

the class NumericTypesIT method testBigDecimal.

@Test
public void testBigDecimal() throws Exception {
    BigDecimalEntity test = context.newObject(BigDecimalEntity.class);
    BigDecimal i = new BigDecimal("1234567890.44");
    test.setBigDecimalField(i);
    context.commitChanges();
    SelectQuery<BigDecimalEntity> q = new SelectQuery<>(BigDecimalEntity.class);
    BigDecimalEntity testRead = (BigDecimalEntity) context.performQuery(q).get(0);
    assertNotNull(testRead.getBigDecimalField());
    assertEquals(i, testRead.getBigDecimalField());
    test.setBigDecimalField(null);
    context.commitChanges();
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) BigDecimalEntity(org.apache.cayenne.testdo.numeric_types.BigDecimalEntity) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 2 with BigDecimalEntity

use of org.apache.cayenne.testdo.numeric_types.BigDecimalEntity 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 3 with BigDecimalEntity

use of org.apache.cayenne.testdo.numeric_types.BigDecimalEntity in project cayenne by apache.

the class DataContextEJBQLNumericalFunctionalIT method testABS.

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

Aggregations

BigDecimal (java.math.BigDecimal)3 BigDecimalEntity (org.apache.cayenne.testdo.numeric_types.BigDecimalEntity)3 Test (org.junit.Test)3 EJBQLQuery (org.apache.cayenne.query.EJBQLQuery)2 SelectQuery (org.apache.cayenne.query.SelectQuery)1