Search in sources :

Example 1 with Column

use of com.baidu.unbiz.common.genericdao.annotation.Column in project disconf by knightliao.

the class MappingItem method getColumnAnnotation.

/**
     * 获取某个字段的annotation,从继承链最下面获取
     *
     * @param f
     * @param set
     * @param get
     *
     * @return
     */
static Column getColumnAnnotation(Field f, Method set, Method get) {
    // 三个地方都有可能出现column
    Column column = f.getAnnotation(Column.class);
    // FIXME 如果不遵循java bean规范,get set 可能为 null,抛出NullPointerException
    Column gColumn = get.getAnnotation(Column.class);
    Column sColumn = set.getAnnotation(Column.class);
    // 预先获取出get与set所在的类
    Class<?> sClass = set.getDeclaringClass();
    Class<?> gClass = get.getDeclaringClass();
    // 如果get上定义了annotation,且get定义的地方是子类
    if (gColumn != null && !gClass.isAssignableFrom(sClass)) {
        return gColumn;
    }
    // 如果是set上定义的annotation,且set方法不在父类中定义
    if (sColumn != null && !sClass.isAssignableFrom(gClass)) {
        return sColumn;
    }
    return column;
}
Also used : Column(com.baidu.unbiz.common.genericdao.annotation.Column)

Aggregations

Column (com.baidu.unbiz.common.genericdao.annotation.Column)1