Search in sources :

Example 1 with AnActiveEntity

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

the class AnActiveEntityTest method testActiveDelete.

public void testActiveDelete() {
    AnActiveEntity entity = new AnActiveEntity(1l);
    dao.insert(entity);
    entity.delete();
    assertNull(dao.load(1l));
}
Also used : AnActiveEntity(org.greenrobot.greendao.daotest.AnActiveEntity)

Example 2 with AnActiveEntity

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

the class AnActiveEntityTest method testThrowWhenDetached.

public void testThrowWhenDetached() {
    AnActiveEntity entity = new AnActiveEntity();
    try {
        entity.delete();
        fail("Should fail for detached entity");
    } catch (DaoException e) {
    // OK, expected
    }
    try {
        entity.refresh();
        fail("Should fail for detached entity");
    } catch (DaoException e) {
    // OK, expected
    }
    try {
        entity.update();
        fail("Should fail for detached entity");
    } catch (DaoException e) {
    // OK, expected
    }
}
Also used : AnActiveEntity(org.greenrobot.greendao.daotest.AnActiveEntity) DaoException(org.greenrobot.greendao.DaoException)

Example 3 with AnActiveEntity

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

the class AnActiveEntityTest method testActiveUpdate.

public void testActiveUpdate() {
    AnActiveEntity entity = new AnActiveEntity(1l);
    long rowId = dao.insert(entity);
    entity.setText("NEW");
    entity.update();
    daoSession.clear();
    AnActiveEntity entity2 = dao.load(rowId);
    assertNotSame(entity, entity2);
    assertEquals("NEW", entity2.getText());
}
Also used : AnActiveEntity(org.greenrobot.greendao.daotest.AnActiveEntity)

Example 4 with AnActiveEntity

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

the class AnActiveEntityMultithreadingTest method doTestAlwaysAttached.

private void doTestAlwaysAttached(Thread thread) throws Exception {
    thread.start();
    Field daoSessionField = AnActiveEntity.class.getDeclaredField("daoSession");
    daoSessionField.setAccessible(true);
    int countEntity = 0;
    countDownAndAwaitLatch();
    try {
        assertTrue(latch.await(10, TimeUnit.SECONDS));
        for (int i = 0; ; i++) {
            AnActiveEntity entity = dao.load(1l);
            if (entity != null) {
                countEntity++;
                assertNotNull(daoSessionField.get(entity));
            }
            if (i == 1000000 && countEntity == 0) {
                fail("No entity available");
            }
            if (countEntity % 10000 == 0) {
                DaoLog.d("Checked entities " + countEntity + " in " + i + " iterations");
            }
            if (countEntity == ENTITIES_TO_CHECK) {
                break;
            }
        }
    } finally {
        running = false;
        thread.join();
    }
}
Also used : Field(java.lang.reflect.Field) AnActiveEntity(org.greenrobot.greendao.daotest.AnActiveEntity)

Example 5 with AnActiveEntity

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

the class AnActiveEntityTest method testActiveRefresh.

public void testActiveRefresh() {
    AnActiveEntity entity = new AnActiveEntity(1l);
    dao.insert(entity);
    AnActiveEntity entity2 = new AnActiveEntity(1l);
    entity2.setText("NEW");
    dao.update(entity2);
    entity.refresh();
    assertEquals("NEW", entity.getText());
}
Also used : AnActiveEntity(org.greenrobot.greendao.daotest.AnActiveEntity)

Aggregations

AnActiveEntity (org.greenrobot.greendao.daotest.AnActiveEntity)5 Field (java.lang.reflect.Field)1 DaoException (org.greenrobot.greendao.DaoException)1