-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
invoke by reflection to avoid compile error of new APIs from JDBC4.1
- Loading branch information
Showing
4 changed files
with
66 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package lx.easydb; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
|
||
public final class ReflectHelper { | ||
public static final Class[] EMPTY_CLASSES = new Class[0]; | ||
public static final Object[] EMPTY_PARAMS = EMPTY_CLASSES; | ||
|
||
public static Object invokeSilent(Object obj, String methodName, | ||
Class[] parameterTypes, Object[] args) { | ||
try { | ||
return invoke(obj, methodName, parameterTypes, args); | ||
} catch (Exception e) { | ||
// ignore | ||
return null; | ||
} | ||
} | ||
|
||
public static Object invoke(Object obj, String methodName, | ||
Class[] parameterTypes, Object[] args) | ||
throws NoSuchMethodException, SecurityException, | ||
IllegalAccessException, IllegalArgumentException, InvocationTargetException { | ||
if (parameterTypes == null) | ||
parameterTypes = EMPTY_CLASSES; | ||
Method method = obj.getClass().getMethod(methodName, parameterTypes); | ||
if (args == null) | ||
args = EMPTY_PARAMS; | ||
return method.invoke(obj, args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters