Search in sources :

Example 21 with TestEntity

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());
}
Also used : TestEntity(org.greenrobot.greendao.daotest.TestEntity) Date(java.util.Date)

Example 22 with TestEntity

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());
}
Also used : TestEntity(org.greenrobot.greendao.daotest.TestEntity) WhereCondition(org.greenrobot.greendao.query.WhereCondition)

Example 23 with TestEntity

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());
}
Also used : TestEntity(org.greenrobot.greendao.daotest.TestEntity)

Example 24 with TestEntity

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()));
}
Also used : TestEntity(org.greenrobot.greendao.daotest.TestEntity)

Example 25 with TestEntity

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());
}
Also used : TestEntity(org.greenrobot.greendao.daotest.TestEntity)

Aggregations

TestEntity (org.greenrobot.greendao.daotest.TestEntity)72 ArrayList (java.util.ArrayList)16 RelationEntity (org.greenrobot.greendao.daotest.RelationEntity)4 List (java.util.List)3 DaoException (org.greenrobot.greendao.DaoException)2 TestSubscriber (rx.observers.TestSubscriber)2 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 Date (java.util.Date)1 Map (java.util.Map)1 NoSuchElementException (java.util.NoSuchElementException)1 WhereCondition (org.greenrobot.greendao.query.WhereCondition)1 Subscription (rx.Subscription)1