public Method loadJavaMethod(Session session, TableName routineName) {
Routine routine = ais(session).getRoutine(routineName);
if (routine == null)
throw new NoSuchRoutineException(routineName);
if (routine.getCallingConvention() != Routine.CallingConvention.JAVA)
throw new SQLJInstanceException(routineName, "Routine was not SQL/J");
long currentVersion = routine.getVersion();
synchronized (javaMethods) {
VersionedItem<Method> entry = javaMethods.get(routineName);
if ((entry != null) && (entry.version == currentVersion))
return entry.item;
TableName jarName = null;
if (routine.getSQLJJar() != null)
jarName = routine.getSQLJJar().getName();
ClassLoader classLoader = loadSQLJJar(session, jarName);
Class<?> clazz;
try {
clazz = Class.forName(routine.getClassName(), true, classLoader);
}
catch (Exception ex) {
throw new SQLJInstanceException(routineName, ex);
}
String methodName = routine.getMethodName();
String methodArgs = null;
int idx = methodName.indexOf('(');
if (idx >= 0) {
methodArgs = methodName.substring(idx+1);
methodName = methodName.substring(0, idx);
}
Method javaMethod = null;
for (Method method : clazz.getMethods()) {
if (((method.getModifiers() & (Modifier.PUBLIC | Modifier.STATIC)) ==
(Modifier.PUBLIC | Modifier.STATIC)) &&
method.getName().equals(methodName) &&
((methodArgs == null) ||
(method.toString().indexOf(methodArgs) > 0))) {
javaMethod = method;
break;
}
}
if (javaMethod == null)
throw new SQLJInstanceException(routineName, "Method not found");
if (entry != null) {
entry.item = javaMethod;
}
else {
entry = new VersionedItem<>(currentVersion, javaMethod);