Search in sources :

Example 16 with TestEntity

use of org.greenrobot.greendao.daotest.TestEntity in project greenDAO by greenrobot.

the class QueryBuilderOrderTest method testOrderAsc.

public void testOrderAsc() {
    ArrayList<TestEntity> inserted = insert(2);
    TestEntity entity = inserted.get(0);
    List<TestEntity> result = dao.queryBuilder().orderAsc(Properties.SimpleInteger).list();
    assertEquals(2, result.size());
    assertEquals(entity.getId(), result.get(0).getId());
    result = dao.queryBuilder().orderAsc(Properties.SimpleInteger, Properties.SimpleString).list();
    assertEquals(2, result.size());
    assertEquals(entity.getId(), result.get(0).getId());
}
Also used : TestEntity(org.greenrobot.greendao.daotest.TestEntity)

Example 17 with TestEntity

use of org.greenrobot.greendao.daotest.TestEntity in project greenDAO by greenrobot.

the class QueryBuilderOrderTest method testOrderCustom_stringOrderCollation.

public void testOrderCustom_stringOrderCollation() {
    List<TestEntity> list = new ArrayList<TestEntity>();
    TestEntity entityAA = addEntity(list, "Aa");
    TestEntity entityAB = addEntity(list, "ab");
    TestEntity entityAC = addEntity(list, "Ac");
    dao.insertInTx(list);
    List<TestEntity> result = dao.queryBuilder().stringOrderCollation(null).orderAsc(Properties.SimpleString).list();
    assertEquals(list.size(), result.size());
    assertEquals(entityAA.getId(), result.get(0).getId());
    assertEquals(entityAC.getId(), result.get(1).getId());
    assertEquals(entityAB.getId(), result.get(2).getId());
    result = dao.queryBuilder().stringOrderCollation("COLLATE BINARY").orderAsc(Properties.SimpleString).list();
    assertEquals(list.size(), result.size());
    assertEquals(entityAA.getId(), result.get(0).getId());
    assertEquals(entityAC.getId(), result.get(1).getId());
    assertEquals(entityAB.getId(), result.get(2).getId());
}
Also used : TestEntity(org.greenrobot.greendao.daotest.TestEntity) ArrayList(java.util.ArrayList)

Example 18 with TestEntity

use of org.greenrobot.greendao.daotest.TestEntity in project greenDAO by greenrobot.

the class QueryBuilderSimpleTest method testIsNullIsNotNull.

public void testIsNullIsNotNull() {
    ArrayList<TestEntity> inserted = insert(2);
    TestEntity testEntityNull = inserted.get(0);
    TestEntity testEntityNotNull = inserted.get(1);
    testEntityNull.setSimpleInteger(null);
    testEntityNotNull.setSimpleInteger(42);
    dao.update(testEntityNull);
    dao.update(testEntityNotNull);
    TestEntity testEntityNull2 = dao.queryBuilder().where(Properties.SimpleInteger.isNull()).uniqueOrThrow();
    assertEquals(testEntityNull.getId(), testEntityNull2.getId());
    TestEntity testEntityNotNull2 = dao.queryBuilder().where(Properties.SimpleInteger.isNotNull()).uniqueOrThrow();
    assertEquals(testEntityNotNull.getId(), testEntityNotNull2.getId());
}
Also used : TestEntity(org.greenrobot.greendao.daotest.TestEntity)

Example 19 with TestEntity

use of org.greenrobot.greendao.daotest.TestEntity in project greenDAO by greenrobot.

the class QueryBuilderSimpleTest method testDistinct.

public void testDistinct() {
    TestEntity entity = insert(3).get(1);
    Query<TestEntity> query = dao.queryBuilder().distinct().where(Properties.SimpleString.eq(entity.getSimpleString())).build();
    TestEntity entity2 = query.uniqueOrThrow();
    assertEquals(entity.getId(), entity2.getId());
// TODO improve test to check functionality
}
Also used : TestEntity(org.greenrobot.greendao.daotest.TestEntity)

Example 20 with TestEntity

use of org.greenrobot.greendao.daotest.TestEntity in project greenDAO by greenrobot.

the class QueryBuilderSimpleTest method testEqInteger.

public void testEqInteger() {
    ArrayList<TestEntity> inserted = insert(3);
    int value = getSimpleInteger(1);
    List<TestEntity> result = dao.queryBuilder().where(Properties.SimpleInteger.eq(value)).list();
    assertEquals(1, result.size());
    TestEntity resultEntity = result.get(0);
    assertEquals(value, (int) resultEntity.getSimpleInteger());
    assertEquals(inserted.get(1).getId(), resultEntity.getId());
}
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