Search in sources :

Example 1 with Property

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

the class WhereCollector method checkProperty.

void checkProperty(Property property) {
    if (dao != null) {
        Property[] properties = dao.getProperties();
        boolean found = false;
        for (Property property2 : properties) {
            if (property == property2) {
                found = true;
                break;
            }
        }
        if (!found) {
            throw new DaoException("Property '" + property.name + "' is not part of " + dao);
        }
    }
}
Also used : DaoException(org.greenrobot.greendao.DaoException) Property(org.greenrobot.greendao.Property)

Example 2 with Property

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

the class AbstractDaoTestSinglePk method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    Property[] columns = daoAccess.getProperties();
    for (Property column : columns) {
        if (column.primaryKey) {
            if (pkColumn != null) {
                throw new RuntimeException("Test does not work with multiple PK columns");
            }
            pkColumn = column;
        }
    }
    if (pkColumn == null) {
        throw new RuntimeException("Test does not work without a PK column");
    }
}
Also used : Property(org.greenrobot.greendao.Property)

Example 3 with Property

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

the class QueryBuilder method orderAscOrDesc.

private void orderAscOrDesc(String ascOrDescWithLeadingSpace, Property... properties) {
    for (Property property : properties) {
        checkOrderBuilder();
        append(orderBuilder, property);
        if (String.class.equals(property.type) && stringOrderCollation != null) {
            orderBuilder.append(stringOrderCollation);
        }
        orderBuilder.append(ascOrDescWithLeadingSpace);
    }
}
Also used : Property(org.greenrobot.greendao.Property)

Example 4 with Property

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

the class QueryBuilder method join.

/**
     * Expands the query to another entity type by using a JOIN. The given sourceProperty is used to match the primary
     * key property of the given destinationEntity.
     */
public <J> Join<T, J> join(Property sourceProperty, Class<J> destinationEntityClass) {
    AbstractDao<J, ?> destinationDao = (AbstractDao<J, ?>) dao.getSession().getDao(destinationEntityClass);
    Property destinationProperty = destinationDao.getPkProperty();
    return addJoin(tablePrefix, sourceProperty, destinationDao, destinationProperty);
}
Also used : AbstractDao(org.greenrobot.greendao.AbstractDao) Property(org.greenrobot.greendao.Property)

Example 5 with Property

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

Aggregations

Property (org.greenrobot.greendao.Property)5 DaoException (org.greenrobot.greendao.DaoException)2 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 AbstractDao (org.greenrobot.greendao.AbstractDao)1 IdentityScopeObject (org.greenrobot.greendao.identityscope.IdentityScopeObject)1