提交 09931cce authored 作者: sylvain-ilm's avatar sylvain-ilm

added support for Ruby

上级 e0137f4b
......@@ -735,7 +735,9 @@ The class must be available in the classpath of the database engine
The sourceCodeString must define a single method with no parameters that returns ""org.h2.api.Trigger"".
See CREATE ALIAS for requirements regarding the compilation.
Alternatively, it can be a javascript (see javax.script.ScriptEngineManager) that returns ""org.h2.api.Trigger"". In that case the source must begin with ""//javascript"".
Alternatively, javax.script.ScriptEngineManager can be used to create an instance of ""org.h2.api.Trigger"".
Currently javascript (included in every JRE) and ruby (with JRuby) are supported.
In that case the source must begin respectively with ""//javascript"" or ""#ruby"".
BEFORE triggers are called after data conversion is made, default values are set,
null and length constraint checks have been made;
......@@ -774,7 +776,8 @@ This command commits an open transaction in this connection.
","
CREATE TRIGGER TRIG_INS BEFORE INSERT ON TEST FOR EACH ROW CALL ""MyTrigger"";
CREATE TRIGGER TRIG_SRC BEFORE INSERT ON TEST AS $$org.h2.api.Trigger create() { return new MyTrigger(""constructorParam""); } $$;
CREATE TRIGGER TRIG_SCRIPT BEFORE INSERT ON TEST AS $$//javascript\nreturn new Packages.MyTrigger(""constructorParam""); $$;
CREATE TRIGGER TRIG_JS BEFORE INSERT ON TEST AS $$//javascript\nreturn new Packages.MyTrigger(""constructorParam""); $$;
CREATE TRIGGER TRIG_RUBY BEFORE INSERT ON TEST AS $$#ruby\nJava::MyPackage::MyTrigger.new(""constructorParam"") $$;
"
"Commands (DDL)","CREATE USER","
CREATE USER [ IF NOT EXISTS ] newUserName
......
......@@ -186,9 +186,13 @@ public class SourceCompiler {
return source.startsWith("//javascript");
}
private static boolean isRubySource(String source) {
return source.startsWith("#ruby");
}
// whether the passed source should be compiled using javax.script.ScriptEngineManager
private static boolean isJavaxScriptSource(String source) {
return isJavascriptSource(source);
return isJavascriptSource(source) || isRubySource(source);
}
public CompiledScript getCompiledScript(String packageAndClassName) throws ScriptException {
......@@ -198,6 +202,8 @@ public class SourceCompiler {
final String lang;
if (isJavascriptSource(source))
lang = "javascript";
else if (isRubySource(source))
lang = "ruby";
else
throw new IllegalStateException("Unkown language for " + source);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论