Search in sources :

Example 56 with TestEntity

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

the class QueryBuilderSimpleTest method testEqString.

public void testEqString() {
    ArrayList<TestEntity> inserted = insert(3);
    String value = getSimpleString(1);
    List<TestEntity> result = dao.queryBuilder().where(Properties.SimpleString.eq(value)).list();
    assertEquals(1, result.size());
    TestEntity resultEntity = result.get(0);
    assertEquals(value, resultEntity.getSimpleString());
    assertEquals(inserted.get(1).getId(), resultEntity.getId());
}
Also used : TestEntity(org.greenrobot.greendao.daotest.TestEntity)

Example 57 with TestEntity

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

the class QueryBuilderSimpleTest method testNotEqString.

public void testNotEqString() {
    ArrayList<TestEntity> inserted = insert(3);
    String value = getSimpleString(1);
    List<TestEntity> result = dao.queryBuilder().where(Properties.SimpleString.notEq(value)).list();
    assertEquals(2, result.size());
    TestEntity resultEntity1 = result.get(0);
    TestEntity resultEntity2 = result.get(1);
    long loId = Math.min(resultEntity1.getId(), resultEntity2.getId());
    long hiId = Math.max(resultEntity1.getId(), resultEntity2.getId());
    assertEquals((long) inserted.get(0).getId(), loId);
    assertEquals((long) inserted.get(2).getId(), hiId);
}
Also used : TestEntity(org.greenrobot.greendao.daotest.TestEntity)

Example 58 with TestEntity

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

the class QueryBuilderSimpleTest method testLike.

public void testLike() {
    TestEntity entity = insert(3).get(1);
    entity.setSimpleString("greenrobot");
    dao.update(entity);
    Query<TestEntity> query = dao.queryBuilder().where(Properties.SimpleString.like("%robot")).build();
    TestEntity entity2 = query.uniqueOrThrow();
    assertEquals(entity.getId(), entity2.getId());
    query.setParameter(0, "green%");
    entity2 = query.uniqueOrThrow();
    assertEquals(entity.getId(), entity2.getId());
    query.setParameter(0, "%enrob%");
    entity2 = query.uniqueOrThrow();
    assertEquals(entity.getId(), entity2.getId());
    query.setParameter(0, "%nothere%");
    entity2 = query.unique();
    assertNull(entity2);
}
Also used : TestEntity(org.greenrobot.greendao.daotest.TestEntity)

Example 59 with TestEntity

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

the class QueryForThreadTest method testGetForCurrentThread_ManyThreadsDontLeak.

public void testGetForCurrentThread_ManyThreadsDontLeak() throws Exception {
    if (VERSION.SDK_INT > VERSION_CODES.LOLLIPOP_MR1) {
        DaoLog.i("testGetForCurrentThread_ManyThreadsDontLeak does not work on API level " + VERSION.SDK_INT);
        return;
    }
    QueryBuilder<TestEntity> builder = dao.queryBuilder().where(Properties.SimpleInteger.eq("dummy"));
    final Query<TestEntity> query = builder.build();
    for (int i = 1; i <= LEAK_TEST_ITERATIONS; i++) {
        Thread thread = new Thread() {

            public void run() {
                query.forCurrentThread();
            }
        };
        thread.start();
        if (i % 10 == 0) {
            thread.join();
        }
    }
    Field queryDataField = Query.class.getDeclaredField("queryData");
    queryDataField.setAccessible(true);
    Object queryData = queryDataField.get(query);
    Class<?> dataSuperclass = queryData.getClass().getSuperclass();
    Field mapField = dataSuperclass.getDeclaredField("queriesForThreads");
    mapField.setAccessible(true);
    Method gcMethod = dataSuperclass.getDeclaredMethod("gc");
    gcMethod.setAccessible(true);
    Map map = (Map) mapField.get(queryData);
    for (int i = 0; map.size() > 1 && i < 1000; i++) {
        DaoLog.d("Queries left after " + i + ". GC: " + map.size());
        System.gc();
        gcMethod.invoke(queryData);
    }
    assertEquals(1, map.size());
}
Also used : TestEntity(org.greenrobot.greendao.daotest.TestEntity) Field(java.lang.reflect.Field) Method(java.lang.reflect.Method) Map(java.util.Map)

Example 60 with TestEntity

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

the class RxDaoTest method testSaveInTx.

public void testSaveInTx() {
    TestEntity foo = insertEntity("foo");
    TestEntity bar = insertEntity("bar");
    foo.setSimpleStringNotNull("foo2");
    assertUpdatedEntities(foo, bar, rxDao.saveInTx(foo, bar));
}
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