| Purpose |
This tutorial aims to focus on the new DRB APIŽ
features.
Note: The presented samples are ordered by DRB APIŽ
version.
|
| Target audience |
Intermediate |
| Required knowledge |
Since this tutorial presents some of the newest
features of DRB APIŽ you should have a good
understanding of DRB APIŽ.
|
| What you will learn in this tutorial |
In this tutorial you will learn how to use new features of
DRB APIŽ.
|
Prerequisites
You may find usefull to configure your environnment by using an
alias, so that the command of this tutorial appears simpler.
The following definition is for Bash
shell:
alias drb='java -jar [DRB_INSTALLATION_HOME]/lib/java/drb-[M]-[m]-[t].jar'
Since DRB APIŽ version 2-3-rc-4
Java function call from XQuery script
Purpose:
Sometimes you may face two typical situations:
- XQuery language is not so suitable
for the
implemenation of your algorigthm
- You already have, or want to use Java language as
implementation for one of your algorithm
In both situation the new java call function of DRB APIŽ
will help you achiving your goal!
Indeed this new feature allow you to call
directly
the
java compiled code from your query.
How to:
In order to be able to call you java method from your query, you
have to follow the pattern:
- [Java]: Ensure your Java method have the static
modifier.
public static
xxx myJavaMethod(xxx) {...}
- [Command]: Ensure your Java class is accessible from
CLASSPATH.
drb -cp pathToMyJavaClass
-f myScript.xql
- [Query]: Declare a dedicated namespace for you Java
class. This namespace must start with the prefix:
"java:
" and continue with the path to the class
name.
declare namespace myNS = "java:path.to.my.java.Class";
- [Query]: For calling the java method, ensure to prefix its
name with the corresponding namespace.
myNS:myJavaMethod(xxx)
Some examples:
In this first example we will simply call a standard java
method already existing in the Double class:
script_java_double.xql
:
xquery version "1.0";
declare namespace doubleNS = "java:java.lang.Double";
fn:concat("Hello, here is the result of a java method call: ", doubleNS:parseDouble("53.5"))