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