This is an implementation of a trusted language execution engine that executes code in any JVM via an RPC mechanism
Any JVM based language
- Make and install it:
make clean && make && make install
From plj-java run maven exec:java
Then from the main dir run make installcheck
There are a number of examples in the tests which demonstrate how this works
From the PostgreSQL process when the function is called all of the arguments are encoded and sent to the JVM along with the java class name and method. For example the function defined as:
CREATE OR REPLACE FUNCTION pljvm_add(i int2, j int2) RETURNS int2 AS $$
org.postgresql.plj.test.Int.add
$$ LANGUAGE pljvm;
defines a function pljvm_add which takes two small ints as arguments and returns a small int. The java classname is org.postgresql.plj.test.Int and the method is add.
public Short add(Short a, Short b) { return (short)(a+b); }
On the JVM side there is a process running a netty pipeline which decodes the call requests; instantiates the class and calls the method in question and then encodes the call response back to the PostgreSQL process.
The library takes care of serializing and deserializing the arguments and the return values