use of org.greenrobot.greendao.daotest.TestEntity in project greenDAO by greenrobot.
the class QueryBuilderSimpleTest method testEqDate.
public void testEqDate() {
ArrayList<TestEntity> inserted = insert(3);
TestEntity testEntity = inserted.get(1);
Date date = new Date();
testEntity.setSimpleDate(date);
dao.update(testEntity);
Query<TestEntity> queryDate = dao.queryBuilder().where(Properties.SimpleDate.eq(date)).build();
TestEntity testEntity2 = queryDate.uniqueOrThrow();
assertEquals(testEntity.getId(), testEntity2.getId());
queryDate.setParameter(0, date);
testEntity2 = queryDate.uniqueOrThrow();
assertEquals(testEntity.getId(), testEntity2.getId());
testEntity2 = dao.queryBuilder().where(Properties.SimpleDate.eq(date.getTime())).uniqueOrThrow();
assertEquals(testEntity.getId(), testEntity2.getId());
}
use of org.greenrobot.greendao.daotest.TestEntity in project greenDAO by greenrobot.
the class QueryBuilderSimpleTest method testEqByteArray.
// TODO fix byte arrays? Android is doing String args everywhere
public void testEqByteArray() {
ArrayList<TestEntity> inserted = insert(3);
TestEntity testEntity = inserted.get(1);
byte[] byteArray = { 96, 77, 37, -21 };
testEntity.setSimpleByteArray(byteArray);
dao.update(testEntity);
// Unsupported: Query<TestEntity> query = dao.queryBuilder().where(Properties.SimpleByteArray.eq(byteArray)).build();
// Works, but probably voids any index on BLOBs (Note: there's no hex2blob function and X'?' is bad syntax):
// String conditionString = "HEX(" + Properties.SimpleByteArray.columnName + ")=?";
// WhereCondition condition = new WhereCondition.StringCondition(conditionString, SqlUtils.toHex(byteArray));
String conditionString = Properties.SimpleByteArray.columnName + '=' + SqlUtils.escapeBlobArgument(byteArray);
WhereCondition condition = new WhereCondition.StringCondition(conditionString);
Query<TestEntity> query = dao.queryBuilder().where(condition).build();
TestEntity testEntity2 = query.uniqueOrThrow();
assertEquals(testEntity.getId(), testEntity2.getId());
// Unsupported: query.setParameter(0, new byte[]{96, 77, 37, -21, 99});
// Unsupported: assertNull(query.unique());
}
use of org.greenrobot.greendao.daotest.TestEntity in project greenDAO by greenrobot.
the class QueryBuilderSimpleTest method testEqBoolean.
public void testEqBoolean() {
ArrayList<TestEntity> inserted = insert(3);
TestEntity testEntity = inserted.get(1);
testEntity.setSimpleBoolean(true);
dao.update(testEntity);
Query<TestEntity> queryBoolean = dao.queryBuilder().where(Properties.SimpleBoolean.eq(true)).build();
TestEntity testEntity2 = queryBoolean.uniqueOrThrow();
assertEquals(testEntity.getId(), testEntity2.getId());
queryBoolean.setParameter(0, true);
testEntity2 = queryBoolean.uniqueOrThrow();
assertEquals(testEntity.getId(), testEntity2.getId());
testEntity2 = dao.queryBuilder().where(Properties.SimpleBoolean.eq(Boolean.TRUE)).uniqueOrThrow();
assertEquals(testEntity.getId(), testEntity2.getId());
testEntity2 = dao.queryBuilder().where(Properties.SimpleBoolean.eq("TRUE")).uniqueOrThrow();
assertEquals(testEntity.getId(), testEntity2.getId());
testEntity2 = dao.queryBuilder().where(Properties.SimpleBoolean.eq("truE")).uniqueOrThrow();
assertEquals(testEntity.getId(), testEntity2.getId());
}
use of org.greenrobot.greendao.daotest.TestEntity in project greenDAO by greenrobot.
the class RxDaoTest method testDeleteByKeyInTx.
public void testDeleteByKeyInTx() {
TestEntity foo = insertEntity("foo");
TestEntity bar = insertEntity("bar");
assertDeleted(rxDao.deleteByKeyInTx(foo.getId(), bar.getId()));
}
use of org.greenrobot.greendao.daotest.TestEntity in project greenDAO by greenrobot.
the class RxDaoTest method testInsert.
public void testInsert() {
TestEntity foo = RxTestHelper.createEntity("foo");
TestSubscriber<TestEntity> testSubscriber = RxTestHelper.awaitTestSubscriber(rxDao.insert(foo));
assertEquals(1, testSubscriber.getValueCount());
TestEntity foo2 = testSubscriber.getOnNextEvents().get(0);
assertSame(foo, foo2);
List<TestEntity> all = dao.loadAll();
assertEquals(1, all.size());
assertEquals(foo.getSimpleStringNotNull(), all.get(0).getSimpleStringNotNull());
}
Aggregations