Search in sources :

Example 1 with BooleanTestEntity

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

the class NumericTypesIT method testBooleanBoolean.

@Test
public void testBooleanBoolean() throws Exception {
    // populate (testing insert as well)
    BooleanTestEntity trueObject = (BooleanTestEntity) context.newObject("BooleanTestEntity");
    trueObject.setBooleanColumn(Boolean.TRUE);
    BooleanTestEntity falseObject = (BooleanTestEntity) context.newObject("BooleanTestEntity");
    falseObject.setBooleanColumn(Boolean.FALSE);
    context.commitChanges();
    context.invalidateObjects(trueObject, falseObject);
    // fetch true...
    Expression trueQ = ExpressionFactory.matchExp("booleanColumn", Boolean.TRUE);
    List<?> trueResult = context1.performQuery(new SelectQuery<>(BooleanTestEntity.class, trueQ));
    assertEquals(1, trueResult.size());
    BooleanTestEntity trueRefetched = (BooleanTestEntity) trueResult.get(0);
    assertEquals(Boolean.TRUE, trueRefetched.getBooleanColumn());
    // CAY-320. Simplifying the use of booleans to allow identity comparison.
    assertNotSame(trueRefetched, trueObject);
    assertSame(Boolean.TRUE, trueRefetched.getBooleanColumn());
    // fetch false
    Expression falseQ = ExpressionFactory.matchExp("booleanColumn", Boolean.FALSE);
    List<?> falseResult = context1.performQuery(new SelectQuery<>(BooleanTestEntity.class, falseQ));
    assertEquals(1, falseResult.size());
    BooleanTestEntity falseRefetched = (BooleanTestEntity) falseResult.get(0);
    assertEquals(Boolean.FALSE, falseRefetched.getBooleanColumn());
    // CAY-320. Simplifying the use of booleans to allow identity comparison.
    assertNotSame(falseRefetched, falseObject);
    assertSame(Boolean.FALSE, falseRefetched.getBooleanColumn());
}
Also used : Expression(org.apache.cayenne.exp.Expression) BooleanTestEntity(org.apache.cayenne.testdo.numeric_types.BooleanTestEntity) Test(org.junit.Test)

Example 2 with BooleanTestEntity

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

the class DataContextEJBQLNumericalFunctionalIT method testUpdateNoQualifierBoolean.

@Test
public void testUpdateNoQualifierBoolean() throws Exception {
    BooleanTestEntity o1 = context.newObject(BooleanTestEntity.class);
    o1.setBooleanColumn(Boolean.TRUE);
    BooleanTestEntity o2 = context.newObject(BooleanTestEntity.class);
    o2.setBooleanColumn(Boolean.FALSE);
    BooleanTestEntity o3 = context.newObject(BooleanTestEntity.class);
    o3.setBooleanColumn(Boolean.FALSE);
    context.commitChanges();
    EJBQLQuery check = new EJBQLQuery("select count(p) from BooleanTestEntity p " + "WHERE p.booleanColumn = true");
    Object notUpdated = Cayenne.objectForQuery(context, check);
    assertEquals(new Long(1l), notUpdated);
    String ejbql = "UPDATE BooleanTestEntity AS p SET p.booleanColumn = true";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    QueryResponse result = context.performGenericQuery(query);
    int[] count = result.firstUpdateCount();
    assertNotNull(count);
    assertEquals(1, count.length);
    assertEquals(3, count[0]);
    notUpdated = Cayenne.objectForQuery(context, check);
    assertEquals(new Long(3l), notUpdated);
}
Also used : EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) BooleanTestEntity(org.apache.cayenne.testdo.numeric_types.BooleanTestEntity) QueryResponse(org.apache.cayenne.QueryResponse) Test(org.junit.Test)

Example 3 with BooleanTestEntity

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

the class BooleanExpressionTest method testCAY1185.

@Test
public void testCAY1185() {
    Expression expTrue = ExpressionFactory.exp("booleanColumn = true");
    Expression expFalse = ExpressionFactory.exp("booleanColumn = false");
    BooleanTestEntity entity = new BooleanTestEntity();
    entity.setBooleanColumn(true);
    assertTrue(expTrue.match(entity));
    assertFalse(expFalse.match(entity));
    entity.setBooleanColumn(false);
    assertFalse(expTrue.match(entity));
    assertTrue(expFalse.match(entity));
}
Also used : BooleanTestEntity(org.apache.cayenne.testdo.numeric_types.BooleanTestEntity) Test(org.junit.Test)

Aggregations

BooleanTestEntity (org.apache.cayenne.testdo.numeric_types.BooleanTestEntity)3 Test (org.junit.Test)3 QueryResponse (org.apache.cayenne.QueryResponse)1 Expression (org.apache.cayenne.exp.Expression)1 EJBQLQuery (org.apache.cayenne.query.EJBQLQuery)1