MethodSeeker

   for findOne
This commit is contained in:
snoop 2017-06-23 19:34:29 +09:00
parent 7fcac63be5
commit 4d2f8b8cff
2 changed files with 60 additions and 1 deletions

View File

@ -136,7 +136,12 @@ public class DBProxy {
if(params.size() > 0) { if(params.size() > 0) {
method = dao.getClass().getMethod(methodName, Object.class); // method = dao.getClass().getMethod(methodName, Object.class);
method = MethodSeeker.getMethod(dao.getClass(), methodName);
if (method == null) {
throw new Exception("Not found method : " + methodName);
}
//method = dao.getClass().getMethod(methodName, paramTypes.toArray(new Class[paramTypes.size()])); //method = dao.getClass().getMethod(methodName, paramTypes.toArray(new Class[paramTypes.size()]));
retObj = method.invoke(dao, valueList.toArray(new Object[valueList.size()])); retObj = method.invoke(dao, valueList.toArray(new Object[valueList.size()]));
}else { }else {
@ -164,6 +169,8 @@ public class DBProxy {
} }
} }
public void blockUntilShutdown() throws InterruptedException { public void blockUntilShutdown() throws InterruptedException {
if (server != null) { if (server != null) {
server.awaitTermination(); server.awaitTermination();

View File

@ -0,0 +1,52 @@
package com.loafle.overflow.proxy.db;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
/**
* Created by root on 17. 6. 23.
*/
public class MethodSeeker {
private static List<Class<?>> typeList = null;
static {
MethodSeeker.typeList = new ArrayList<>();
//normal
MethodSeeker.typeList.add(Object.class);
//findOne
MethodSeeker.typeList.add(java.io.Serializable.class);
}
public static Method getMethod(Class cls, String methodName) {
Method method = null;
for(Class<?> type : MethodSeeker.typeList) {
method = MethodSeeker.getMethodType(cls,methodName, type);
if(method != null) {
return method;
}
}
return method;
}
private static Method getMethodType(Class jpa, String methodName, Class<?> type) {
if (jpa == null) {
return null;
}
Method m = null;
try {
m = jpa.getMethod(methodName, type);
} catch (NoSuchMethodException e) {
return MethodSeeker.getMethodType(jpa.getSuperclass(), methodName, type);
}
return m;
}
}