Search in sources :

Example 1 with BigIntegerEntity

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

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

the class NumericTypesIT method testBigInteger.

@Test
public void testBigInteger() throws Exception {
    BigIntegerEntity test = context.newObject(BigIntegerEntity.class);
    BigInteger i = new BigInteger("1234567890");
    test.setBigIntegerField(i);
    context.commitChanges();
    SelectQuery<BigIntegerEntity> q = new SelectQuery<>(BigIntegerEntity.class);
    BigIntegerEntity testRead = (BigIntegerEntity) context.performQuery(q).get(0);
    assertNotNull(testRead.getBigIntegerField());
    assertEquals(i, testRead.getBigIntegerField());
    test.setBigIntegerField(null);
    context.commitChanges();
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) BigInteger(java.math.BigInteger) BigIntegerEntity(org.apache.cayenne.testdo.numeric_types.BigIntegerEntity) Test(org.junit.Test)

Example 3 with BigIntegerEntity

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

the class NumericTypesIT method testBigIntegerColumnSelect.

@Test
public void testBigIntegerColumnSelect() {
    BigIntegerEntity test = context.newObject(BigIntegerEntity.class);
    BigInteger i = new BigInteger("1234567890");
    test.setBigIntegerField(i);
    context.commitChanges();
    BigInteger readValue = ObjectSelect.query(BigIntegerEntity.class).column(BigIntegerEntity.BIG_INTEGER_FIELD).selectOne(context);
    assertEquals(i, readValue);
    Property<BigInteger> calculated = Property.create(ExpressionFactory.exp("bigIntegerField + 1"), BigInteger.class);
    BigInteger readValue2 = ObjectSelect.query(BigIntegerEntity.class).column(calculated).selectOne(context);
    assertEquals(i.add(BigInteger.ONE), readValue2);
}
Also used : BigInteger(java.math.BigInteger) BigIntegerEntity(org.apache.cayenne.testdo.numeric_types.BigIntegerEntity) Test(org.junit.Test)

Aggregations

BigInteger (java.math.BigInteger)3 BigIntegerEntity (org.apache.cayenne.testdo.numeric_types.BigIntegerEntity)3 Test (org.junit.Test)3 EJBQLQuery (org.apache.cayenne.query.EJBQLQuery)1 SelectQuery (org.apache.cayenne.query.SelectQuery)1