提交 67eb291e authored 作者: sylvain-ilm's avatar sylvain-ilm

restored the more specific code for Trigger, as requested

上级 65f8e661
......@@ -5,6 +5,7 @@
*/
package org.h2.schema;
import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.SQLException;
......@@ -93,7 +94,15 @@ public class TriggerObject extends SchemaObjectBase {
String fullClassName = Constants.USER_PACKAGE + ".trigger." + getName();
compiler.setSource(fullClassName, triggerSource);
try {
return (Trigger) compiler.invoke(fullClassName);
if (SourceCompiler.isJavaxScriptSource(triggerSource)) {
return (Trigger) compiler.getCompiledScript(fullClassName).eval();
} else {
final Method m = compiler.getMethod(fullClassName);
if (m.getParameterTypes().length > 0) {
throw new IllegalStateException("No parameters are allowed for a trigger");
}
return (Trigger) m.invoke(null);
}
} catch (DbException e) {
throw e;
} catch (Exception e) {
......
......@@ -190,8 +190,13 @@ public class SourceCompiler {
return source.startsWith("#ruby");
}
// whether the passed source should be compiled using javax.script.ScriptEngineManager
private static boolean isJavaxScriptSource(String source) {
/**
* Whether the passed source can be compiled using {@link javax.script.ScriptEngineManager}.
*
* @param source the source to test.
* @return <code>true</code> if {@link #getCompiledScript(String)} can be called.
*/
public static boolean isJavaxScriptSource(String source) {
return isJavascriptSource(source) || isRubySource(source);
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论