mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
cache the reflect class and reflect method.
This commit is contained in:
@@ -14,19 +14,30 @@ public class ReflectionUtils {
|
||||
|
||||
private final static Log LOG = LogFactory.getLog(ReflectionUtils.class);
|
||||
|
||||
public static Class<?> getClassFromWebContainerOrCurrentClassLoader(String className) {
|
||||
public static Class<?> getClassFromWebContainer(String className) {
|
||||
Class<?> result = null;
|
||||
try {
|
||||
result = HttpServletRequest.class.getClassLoader().loadClass(className);
|
||||
} catch (ClassNotFoundException e) {
|
||||
if (LOG.isDebugEnabled()) LOG.debug("can'r find class in web container classLoader ", e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Class<?> getClassFromCurrentClassLoader(String className) {
|
||||
Class<?> result = null;
|
||||
try {
|
||||
result = Thread.currentThread().getContextClassLoader().loadClass(className);
|
||||
} catch (ClassNotFoundException e) {
|
||||
LOG.error("can'r find class in current thread context classLoader ", e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Class<?> getClassFromWebContainerOrCurrentClassLoader(String className) {
|
||||
Class<?> result = getClassFromWebContainer(className);
|
||||
if (result == null) {
|
||||
try {
|
||||
result = Thread.currentThread().getContextClassLoader().loadClass(className);
|
||||
} catch (ClassNotFoundException e) {
|
||||
LOG.error("can'r find class in current thread context classLoader ", e);
|
||||
}
|
||||
result = getClassFromCurrentClassLoader(className);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -51,7 +62,25 @@ public class ReflectionUtils {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Method getObjectMethod(Object obj, String methodName) {
|
||||
try {
|
||||
return obj.getClass().getMethod(methodName);
|
||||
} catch (Exception e) {
|
||||
LOG.warn("getObjectMethod fail:class=" + obj.getClass().getName() + " method=" + methodName, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Method getObjectMethod(Object obj, String methodName, Integer id) {
|
||||
try {
|
||||
return obj.getClass().getMethod(methodName, Integer.class);
|
||||
} catch (Exception e) {
|
||||
LOG.warn("getObjectMethod fail:class=" + obj.getClass().getName() + " method=" + methodName, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Object callObjectMethod(Object obj, String methodName, Integer id) {
|
||||
try {
|
||||
Method m = obj.getClass().getMethod(methodName, Integer.class);
|
||||
|
||||
Reference in New Issue
Block a user