I unfocused on jean's tutorial at ApacheCon this morning for a bit to
add groovy eval fucntionality into Derby =)
She asked me to mail it to everyone here:
ij> select count(*), groovyEval('foo = ["woof", "meow"]; foo.join(" --
") ') from fortunes;
1 |2
--------------------------
13686 |woof -- meow
1 row selected
ij>
----------
package org.skife.derby.groovy;
import groovy.lang.Binding;
import groovy.lang.GroovyShell;
import org.codehaus.groovy.control.CompilationFailedException;
import java.io.IOException;
public class Groovy
{
public static String eval(String expression) throws IOException,
CompilationFailedException
{
Binding binding = new Binding();
GroovyShell shell = new GroovyShell(binding);
Object value = shell.evaluate(expression);
return String.valueOf(value);
}
}
--------
create function groovyEval(expression varchar(3000))
returns varchar(3000)
language java
parameter style java
no sql
external name 'org.skife.derby.groovy.Groovy.eval';
CALL SQLJ.install_jar ('sql/geval.jar', 'APP.GROOVYEVAL', 0);
CALL SQLJ.install_jar ('lib/groovy-1.0-beta-8-SNAPSHOT.jar', 'APP.GROOVY', 0);
CALL SQLJ.install_jar ('lib/asm-1.4.3.jar', 'APP.ASM', 0);
CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.database.classpath',
'APP.GROOVYEVAL:APP.GROOVY:APP.ASM');