Search in sources :

Example 61 with Method

use of java.lang.reflect.Method in project killbill by killbill.

the class MultiTenantConfigBase method convertToListTimeSpan.

protected List<TimeSpan> convertToListTimeSpan(final String value, final String methodName) {
    final Method method = getConfigStaticMethodWithChecking(methodName);
    final Iterable<String> tokens = getTokens(method, value);
    return ImmutableList.copyOf(Iterables.transform(tokens, TIME_SPAN_CONVERTER));
}
Also used : Method(java.lang.reflect.Method)

Example 62 with Method

use of java.lang.reflect.Method in project killbill by killbill.

the class MultiTenantConfigBase method getConfigStaticMethod.

protected Method getConfigStaticMethod(final String methodName) {
    Method method = methodsCache.get(methodName);
    if (method == null) {
        synchronized (methodsCache) {
            method = methodsCache.get(methodName);
            if (method == null) {
                try {
                    method = getConfigClass().getMethod(methodName, InternalTenantContext.class);
                    methodsCache.put(methodName, method);
                } catch (final NoSuchMethodException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
    return method;
}
Also used : InternalTenantContext(org.killbill.billing.callcontext.InternalTenantContext) Method(java.lang.reflect.Method)

Example 63 with Method

use of java.lang.reflect.Method in project disconf by knightliao.

the class Setter method mapRow.

public ENTITY mapRow(ResultSet rs, int rowIndex) throws SQLException {
    if (setters == null) {
        ResultSetMetaData meta = rs.getMetaData();
        setters = getSetters(meta);
    }
    try {
        ENTITY entity = entityClass.newInstance();
        K key = isComplexKey ? keyClass.newInstance() : null;
        // FIXME
        if (key != null) {
            entity.setId(key);
        }
        for (Setter setter : setters) {
            String column = setter.columnName;
            Method setMethod = setter.method;
            Class<?> paramType = setter.setterParamType;
            if (setMethod.getName().equals("setId")) {
                paramType = keyClass;
            }
            Object value = MapperUtils.getValue4Type(rs, column, paramType);
            // FIXME
            if (orMapping.isKeyColumn(column) && key != null) {
                load2Entity(key, setMethod, value);
            } else {
                load2Entity(entity, setMethod, value);
            }
        }
        return entity;
    } catch (Exception e) {
        e.printStackTrace();
        throw new SQLException("error in loadEntity");
    }
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) SQLException(java.sql.SQLException) BaseObject(com.github.knightliao.apollo.db.bo.BaseObject) Method(java.lang.reflect.Method) SQLException(java.sql.SQLException)

Example 64 with Method

use of java.lang.reflect.Method in project disconf by knightliao.

the class Setter method getSetters.

/**
     * @param meta
     * @param genericMapper2
     *
     * @return 下午3:45:38 created by Darwin(Tianxin)
     *
     * @throws SQLException
     */
private List<Setter> getSetters(ResultSetMetaData meta) throws SQLException {
    int columnCount = meta.getColumnCount();
    List<Setter> setters = new ArrayList<Setter>(columnCount);
    for (int i = 1; i <= columnCount; i++) {
        String column = meta.getColumnName(i);
        Method setMethod = orMapping.getSetter(column);
        if (setMethod != null) {
            Setter setter = new Setter(setMethod, column, setMethod.getParameterTypes()[0]);
            setters.add(setter);
        }
    }
    return setters;
}
Also used : ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method)

Example 65 with Method

use of java.lang.reflect.Method 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;
}
Also used : Table(com.baidu.unbiz.common.genericdao.annotation.Table) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) BaseObject(com.github.knightliao.apollo.db.bo.BaseObject) Field(java.lang.reflect.Field)

Aggregations

Method (java.lang.reflect.Method)8797 Test (org.junit.Test)1772 InvocationTargetException (java.lang.reflect.InvocationTargetException)1084 ArrayList (java.util.ArrayList)665 Field (java.lang.reflect.Field)611 IOException (java.io.IOException)549 HashMap (java.util.HashMap)352 Map (java.util.Map)290 List (java.util.List)275 PropertyDescriptor (java.beans.PropertyDescriptor)253 Annotation (java.lang.annotation.Annotation)212 Type (java.lang.reflect.Type)202 HashSet (java.util.HashSet)199 File (java.io.File)173 IndexedPropertyDescriptor (java.beans.IndexedPropertyDescriptor)170 BeanInfo (java.beans.BeanInfo)166 ParameterizedType (java.lang.reflect.ParameterizedType)132 Constructor (java.lang.reflect.Constructor)131 SimpleBeanInfo (java.beans.SimpleBeanInfo)128 FakeFox01BeanInfo (org.apache.harmony.beans.tests.support.mock.FakeFox01BeanInfo)128