Search in sources :

Example 1 with DfPropertyDesc

use of org.dbflute.helper.beans.DfPropertyDesc in project dbflute-core by dbflute.

the class DfBeanDescImpl method setupWriteMethod.

protected void setupWriteMethod(Method writeMethod, String propertyName) {
    final Class<?> propertyType = writeMethod.getParameterTypes()[0];
    final DfPropertyDesc propDesc = getPropertyDescInternally(propertyName);
    if (propDesc != null) {
        if (!propDesc.getPropertyType().equals(propertyType)) {
            _invalidPropertyNames.add(propertyName);
        } else {
            propDesc.setWriteMethod(writeMethod);
        }
    } else {
        addPropertyDesc(createPropertyDesc(propertyName, propertyType, null, writeMethod, null));
    }
}
Also used : DfPropertyDesc(org.dbflute.helper.beans.DfPropertyDesc)

Example 2 with DfPropertyDesc

use of org.dbflute.helper.beans.DfPropertyDesc in project dbflute-core by dbflute.

the class DfBeanDescImpl method addFields.

protected void addFields(Class<?> clazz) {
    final Field[] fields = clazz.getDeclaredFields();
    for (Field field : fields) {
        final String fieldName = field.getName();
        if (_fieldMap.containsKey(fieldName)) {
            // target class's fields have priority
            continue;
        }
        if (isFieldPrivateAccessible()) {
            field.setAccessible(true);
        }
        _fieldMap.put(fieldName, field);
        if (DfReflectionUtil.isInstanceVariableField(field)) {
            if (hasPropertyDesc(fieldName)) {
                final DfPropertyDesc pd = getPropertyDesc(fieldName);
                pd.setField(field);
            } else if (DfReflectionUtil.isPublicField(field)) {
                final DfPropertyDesc pd = createPropertyDesc(fieldName, field.getType(), null, null, field);
                _propertyDescMap.put(fieldName, pd);
            }
        }
    }
}
Also used : Field(java.lang.reflect.Field) DfPropertyDesc(org.dbflute.helper.beans.DfPropertyDesc)

Example 3 with DfPropertyDesc

use of org.dbflute.helper.beans.DfPropertyDesc in project dbflute-core by dbflute.

the class DfBeanDescImpl method setupReadMethod.

protected void setupReadMethod(Method readMethod, String propertyName) {
    final Class<?> propertyType = readMethod.getReturnType();
    final DfPropertyDesc propDesc = getPropertyDescInternally(propertyName);
    if (propDesc != null) {
        if (!propDesc.getPropertyType().equals(propertyType)) {
            _invalidPropertyNames.add(propertyName);
        } else {
            propDesc.setReadMethod(readMethod);
        }
    } else {
        addPropertyDesc(createPropertyDesc(propertyName, propertyType, readMethod, null, null));
    }
}
Also used : DfPropertyDesc(org.dbflute.helper.beans.DfPropertyDesc)

Example 4 with DfPropertyDesc

use of org.dbflute.helper.beans.DfPropertyDesc in project dbflute-core by dbflute.

the class DfPropertyDescImplTest method test_getValue_illegalProperty.

public void test_getValue_illegalProperty() throws Exception {
    // ## Arrange ##
    DfBeanDesc beanDesc = DfBeanDescFactory.getBeanDesc(MockBean.class);
    DfPropertyDesc pd = beanDesc.getPropertyDesc("writeOnlyName");
    MockBean bean = new MockBean();
    bean.setWriteOnlyName("foo");
    // ## Act ##
    try {
        pd.getValue(bean);
        // ## Assert ##
        fail();
    } catch (DfBeanIllegalPropertyException e) {
        // OK
        log(e.getMessage());
    }
}
Also used : DfPropertyDesc(org.dbflute.helper.beans.DfPropertyDesc) DfBeanIllegalPropertyException(org.dbflute.helper.beans.exception.DfBeanIllegalPropertyException) DfBeanDesc(org.dbflute.helper.beans.DfBeanDesc)

Example 5 with DfPropertyDesc

use of org.dbflute.helper.beans.DfPropertyDesc in project dbflute-core by dbflute.

the class DfPropertyDescImplTest method test_setValue_illegalProperty.

public void test_setValue_illegalProperty() throws Exception {
    // ## Arrange ##
    DfBeanDesc beanDesc = DfBeanDescFactory.getBeanDesc(MockBean.class);
    DfPropertyDesc pd = beanDesc.getPropertyDesc("readOnlyName");
    MockBean bean = new MockBean();
    // ## Act ##
    try {
        pd.setValue(bean, "foo");
        // ## Assert ##
        fail();
    } catch (DfBeanIllegalPropertyException e) {
        // OK
        log(e.getMessage());
    }
}
Also used : DfPropertyDesc(org.dbflute.helper.beans.DfPropertyDesc) DfBeanIllegalPropertyException(org.dbflute.helper.beans.exception.DfBeanIllegalPropertyException) DfBeanDesc(org.dbflute.helper.beans.DfBeanDesc)

Aggregations

DfPropertyDesc (org.dbflute.helper.beans.DfPropertyDesc)22 DfBeanDesc (org.dbflute.helper.beans.DfBeanDesc)10 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 List (java.util.List)3 DfBeanIllegalPropertyException (org.dbflute.helper.beans.exception.DfBeanIllegalPropertyException)3 MapParameterBean (org.dbflute.twowaysql.pmbean.MapParameterBean)3 TnIdentifierGenerator (org.dbflute.s2dao.identity.TnIdentifierGenerator)2 TnPropertyType (org.dbflute.s2dao.metadata.TnPropertyType)2 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 Timestamp (java.sql.Timestamp)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Entity (org.dbflute.Entity)1 DBMeta (org.dbflute.dbmeta.DBMeta)1 DfBeanMethodNotFoundException (org.dbflute.helper.beans.exception.DfBeanMethodNotFoundException)1 TnBeanMetaData (org.dbflute.s2dao.metadata.TnBeanMetaData)1 TnModifiedPropertySupport (org.dbflute.s2dao.metadata.TnModifiedPropertySupport)1 TnRelationPropertyType (org.dbflute.s2dao.metadata.TnRelationPropertyType)1