Search in sources :

Example 1 with DfPropertyAccessor

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

the class TnRelationPropertyTypeImpl method createPropertyAccessor.

protected DfPropertyAccessor createPropertyAccessor(final DfPropertyDesc propertyDesc, TnBeanMetaData myBeanMetaData) {
    final DBMeta dbmeta = myBeanMetaData.getDBMeta();
    assertDBMetaExists(dbmeta, myBeanMetaData);
    final String propertyName = propertyDesc.getPropertyName();
    final ForeignInfo foreignInfo = dbmeta.hasForeign(propertyName) ? dbmeta.findForeignInfo(propertyName) : null;
    return new DfPropertyAccessor() {

        public String getPropertyName() {
            return foreignInfo != null ? foreignInfo.getForeignPropertyName() : propertyName;
        }

        public Class<?> getPropertyType() {
            return foreignInfo != null ? foreignInfo.getPropertyAccessType() : propertyDesc.getPropertyType();
        }

        public Class<?> getGenericType() {
            return propertyDesc.getGenericType();
        }

        public Object getValue(Object target) {
            if (foreignInfo != null && target instanceof Entity) {
                // basically here
                return foreignInfo.read((Entity) target);
            } else {
                return propertyDesc.getValue(target);
            }
        }

        public void setValue(Object target, Object value) {
            if (foreignInfo != null && target instanceof Entity) {
                // basically here
                foreignInfo.write((Entity) target, value);
            } else {
                propertyDesc.setValue(target, value);
            }
        }

        public boolean isReadable() {
            return propertyDesc.isReadable();
        }

        public boolean isWritable() {
            return propertyDesc.isWritable();
        }
    };
}
Also used : DfPropertyAccessor(org.dbflute.helper.beans.DfPropertyAccessor) ForeignInfo(org.dbflute.dbmeta.info.ForeignInfo) Entity(org.dbflute.Entity) DBMeta(org.dbflute.dbmeta.DBMeta)

Aggregations

Entity (org.dbflute.Entity)1 DBMeta (org.dbflute.dbmeta.DBMeta)1 ForeignInfo (org.dbflute.dbmeta.info.ForeignInfo)1 DfPropertyAccessor (org.dbflute.helper.beans.DfPropertyAccessor)1