提交 68f814b3 authored 作者: Thomas Mueller's avatar Thomas Mueller

Undo cache the last user defined function return value

上级 c16b5581
......@@ -279,7 +279,7 @@ public class FunctionAlias extends SchemaObjectBase {
* Each method must have a different number of parameters however.
* This helper class represents one such method.
*/
public class JavaMethod implements Comparable<JavaMethod> {
public static class JavaMethod implements Comparable<JavaMethod> {
private final int id;
private final Method method;
private final int dataType;
......@@ -287,11 +287,6 @@ public class FunctionAlias extends SchemaObjectBase {
private boolean varArgs;
private Class<?> varArgClass;
private int paramCount;
/**
* Cache the value of the last call if the function is deterministic.
*/
private Object[] previousParams;
private Value previousReturnValue;
JavaMethod(Method method, int id) {
this.method = method;
......@@ -403,11 +398,6 @@ public class FunctionAlias extends SchemaObjectBase {
params[p] = o;
}
}
if (deterministic) {
if (previousParams != null && Arrays.deepEquals(previousParams, params)) {
return previousReturnValue;
}
}
boolean old = session.getAutoCommit();
Value identity = session.getLastScopeIdentity();
boolean defaultConnection = session.getDatabase().getSettings().defaultConnection;
......@@ -419,6 +409,9 @@ public class FunctionAlias extends SchemaObjectBase {
Driver.setDefaultConnection(session.createConnection(columnList));
}
returnValue = method.invoke(null, params);
if (returnValue == null) {
return ValueNull.INSTANCE;
}
} catch (InvocationTargetException e) {
StatementBuilder buff = new StatementBuilder(method.getName());
buff.append('(');
......@@ -431,21 +424,11 @@ public class FunctionAlias extends SchemaObjectBase {
} catch (Exception e) {
throw DbException.convert(e);
}
Value ret;
if (returnValue == null) {
ret = ValueNull.INSTANCE;
} else {
if (Value.class.isAssignableFrom(method.getReturnType())) {
ret = (Value) returnValue;
} else {
ret = DataType.convertToValue(session, returnValue, dataType);
}
}
if (deterministic) {
previousParams = params;
previousReturnValue = ret;
if (Value.class.isAssignableFrom(method.getReturnType())) {
return (Value) returnValue;
}
return ret;
Value ret = DataType.convertToValue(session, returnValue, dataType);
return ret.convertTo(dataType);
} finally {
session.setLastScopeIdentity(identity);
session.setAutoCommit(old);
......
......@@ -80,7 +80,10 @@ public class TestFunctions extends TestBase implements AggregateFunction {
testNvl2();
testConcatWs();
testTruncate();
testCachingOfDeterministicFunctionAlias();
// TODO
// testCachingOfDeterministicFunctionAlias();
deleteDb("functions");
FileUtils.deleteRecursive(TEMP_DIR, true);
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论