Search in sources :

Example 36 with TestEntity

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

the class LazyListTest method testUncached.

public void testUncached() {
    insert(1);
    LazyList<TestEntity> listLazy = dao.queryBuilder().build().listLazyUncached();
    assertFalse(listLazy.isEmpty());
    assertFalse(listLazy.isClosed());
    TestEntity entity1 = listLazy.get(0);
    TestEntity entity2 = listLazy.get(0);
    assertEquals(entity1.getId(), entity2.getId());
    if (identityScopeForDao == null) {
        assertNotSame(entity1, entity2);
    } else {
        assertSame(entity1, entity2);
    }
    assertFalse(listLazy.isClosed());
    try {
        listLazy.loadRemaining();
        fail("Not empty");
    } catch (DaoException expected) {
    // Expected, OK
    }
    listLazy.close();
    assertTrue(listLazy.isClosed());
}
Also used : TestEntity(org.greenrobot.greendao.daotest.TestEntity) DaoException(org.greenrobot.greendao.DaoException)

Example 37 with TestEntity

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

the class QueryBuilderOrderTest method testOrderDesc.

public void testOrderDesc() {
    ArrayList<TestEntity> inserted = insert(2);
    TestEntity entity = inserted.get(1);
    List<TestEntity> result = dao.queryBuilder().orderDesc(Properties.SimpleInteger).list();
    assertEquals(2, result.size());
    assertEquals(entity.getId(), result.get(0).getId());
    result = dao.queryBuilder().orderDesc(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 38 with TestEntity

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

the class QueryBuilderOrderTest method addEntity.

private TestEntity addEntity(List<TestEntity> list, String simpleString) {
    TestEntity entityAB = createEntity(42, simpleString);
    list.add(entityAB);
    return entityAB;
}
Also used : TestEntity(org.greenrobot.greendao.daotest.TestEntity)

Example 39 with TestEntity

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

the class QueryBuilderOrderTest method testOrderCustom.

public void testOrderCustom() {
    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().orderCustom(Properties.SimpleString, "ASC").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 40 with TestEntity

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

the class QueryBuilderOrderTest method testOrderUpperLowercase.

public void testOrderUpperLowercase() {
    List<TestEntity> list = new ArrayList<TestEntity>();
    TestEntity entityAA = addEntity(list, "aa");
    TestEntity entityAB = addEntity(list, "Ab");
    TestEntity entityAC = addEntity(list, "ac");
    TestEntity entityZA = addEntity(list, "ZA");
    TestEntity entityZB = addEntity(list, "zB");
    TestEntity entityZC = addEntity(list, "ZC");
    Collections.shuffle(list);
    dao.insertInTx(list);
    List<TestEntity> result = dao.queryBuilder().orderAsc(Properties.SimpleString).list();
    assertEquals(list.size(), result.size());
    assertEquals(entityAA.getId(), result.get(0).getId());
    assertEquals(entityAB.getId(), result.get(1).getId());
    assertEquals(entityAC.getId(), result.get(2).getId());
    assertEquals(entityZA.getId(), result.get(3).getId());
    assertEquals(entityZB.getId(), result.get(4).getId());
    assertEquals(entityZC.getId(), result.get(5).getId());
}
Also used : TestEntity(org.greenrobot.greendao.daotest.TestEntity) ArrayList(java.util.ArrayList)

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