use of com.github.knightliao.apollo.db.bo.BaseObject in project disconf by knightliao.
the class MappingItem method getMappingItems.
public static List<MappingItem> getMappingItems(Class<?> clazz) {
if (!ClassUtils.isBaiduClass(clazz)) {
return new ArrayList<MappingItem>(0);
}
// 如果不是BaseObject的子類,則一定是keyClass
boolean isKeyClass = !BaseObject.class.isAssignableFrom(clazz);
List<MappingItem> mappingItems = new ArrayList<MappingItem>(32);
Set<Field> fields = ClassUtils.getAllFiled(clazz);
Set<Method> methods = ClassUtils.getAllMethod(clazz);
Map<String, Method> methodMap = ClassUtils.filter2Map(methods);
Table table = isKeyClass ? null : clazz.getAnnotation(Table.class);
String keyColumn = isKeyClass ? null : table.keyColumn();
// 循环处理所有字段,过滤出该类加载为对象时需要调用的setter方法map
for (Field f : fields) {
// 静态字段则自动pass
if (Modifier.isStatic(f.getModifiers())) {
continue;
}
// 不做关联加载的工作
Class<?> fType = f.getType();
boolean isBaiduClass = ClassUtils.isBaiduClass(fType);
if (isBaiduClass || Collection.class.isAssignableFrom(fType) || fType.isArray()) {
continue;
}
// 字段名字
String name = f.getName().toLowerCase();
boolean isKey = name.equals("id");
if (isKey && isBaiduClass) {
continue;
}
// 其他字段获取field,getter,setter
Method set = methodMap.get("set" + name);
Method get = methodMap.get("get" + name);
if (get == null) {
get = methodMap.get("is" + name);
}
// FIXME
MappingItem item = new MappingItem(f, set, get, (table != null) ? table.columnStyle() : ColumnStyle.LOWER_CASE, (table != null) ? table.columnsModified() : false);
if (item.isIgnore()) {
continue;
}
item.dbColumn = isKey ? keyColumn : item.dbColumn;
mappingItems.add(item);
}
return mappingItems;
}
Aggregations