diff --git a/src/main/java/com/loafle/overflow/proxy/db/DBProxy.java b/src/main/java/com/loafle/overflow/proxy/db/DBProxy.java index 6de5d29..0214881 100644 --- a/src/main/java/com/loafle/overflow/proxy/db/DBProxy.java +++ b/src/main/java/com/loafle/overflow/proxy/db/DBProxy.java @@ -136,7 +136,12 @@ public class DBProxy { 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()])); retObj = method.invoke(dao, valueList.toArray(new Object[valueList.size()])); }else { @@ -164,6 +169,8 @@ public class DBProxy { } } + + public void blockUntilShutdown() throws InterruptedException { if (server != null) { server.awaitTermination(); diff --git a/src/main/java/com/loafle/overflow/proxy/db/MethodSeeker.java b/src/main/java/com/loafle/overflow/proxy/db/MethodSeeker.java new file mode 100644 index 0000000..0552514 --- /dev/null +++ b/src/main/java/com/loafle/overflow/proxy/db/MethodSeeker.java @@ -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> 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; + } +}