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();
}
};
}
Aggregations