Search in sources :

Example 6 with DaoException

use of org.greenrobot.greendao.DaoException in project greenDAO by greenrobot.

the class DaoConfig method reflectProperties.

private static Property[] reflectProperties(Class<? extends AbstractDao<?, ?>> daoClass) throws ClassNotFoundException, IllegalArgumentException, IllegalAccessException {
    Class<?> propertiesClass = Class.forName(daoClass.getName() + "$Properties");
    Field[] fields = propertiesClass.getDeclaredFields();
    ArrayList<Property> propertyList = new ArrayList<Property>();
    final int modifierMask = Modifier.STATIC | Modifier.PUBLIC;
    for (Field field : fields) {
        // There might be other fields introduced by some tools, just ignore them (see issue #28)
        if ((field.getModifiers() & modifierMask) == modifierMask) {
            Object fieldValue = field.get(null);
            if (fieldValue instanceof Property) {
                propertyList.add((Property) fieldValue);
            }
        }
    }
    Property[] properties = new Property[propertyList.size()];
    for (Property property : propertyList) {
        if (properties[property.ordinal] != null) {
            throw new DaoException("Duplicate property ordinals");
        }
        properties[property.ordinal] = property;
    }
    return properties;
}
Also used : Field(java.lang.reflect.Field) ArrayList(java.util.ArrayList) IdentityScopeObject(org.greenrobot.greendao.identityscope.IdentityScopeObject) DaoException(org.greenrobot.greendao.DaoException) Property(org.greenrobot.greendao.Property)

Example 7 with DaoException

use of org.greenrobot.greendao.DaoException 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)

Aggregations

DaoException (org.greenrobot.greendao.DaoException)7 ArrayList (java.util.ArrayList)2 Property (org.greenrobot.greendao.Property)2 TestEntity (org.greenrobot.greendao.daotest.TestEntity)2 Cursor (android.database.Cursor)1 Field (java.lang.reflect.Field)1 AnActiveEntity (org.greenrobot.greendao.daotest.AnActiveEntity)1 Database (org.greenrobot.greendao.database.Database)1 IdentityScopeObject (org.greenrobot.greendao.identityscope.IdentityScopeObject)1