added
MethodSeeker for findOne
This commit is contained in:
parent
7fcac63be5
commit
4d2f8b8cff
|
@ -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();
|
||||
|
|
52
src/main/java/com/loafle/overflow/proxy/db/MethodSeeker.java
Normal file
52
src/main/java/com/loafle/overflow/proxy/db/MethodSeeker.java
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user