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());
}
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);
}
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));
}
Aggregations