How InstantDB Finds Functions
Whenever InstantDB comes across a function in a SQL expression,
it takes the function name, converts it to all lower case, and prepends
the package name "db.". For example, in the case of: SELECT UPPER(col1)
FROM mytable, InstantDB would look for a class with the name db.upper.
It then creates an instance of this class and invokes the following
- int checkParameters (int parameterTypes)
This is called when InstantDB has parsed the expressions being
supplied as the function's parameters. It allows the function
to determine the number and types of parameters it will receive
and, if necessary, to throw an exception if the parameters types
- public void setSpecialValue (int type, Object value)
Called when InstantDB wishes to pass database information, such
as configuration parameters, to a function.
- public Object getSpecialValue (int type)
Called when InstantDB needs additional information from a function,
such as how it would like its results to be formatted.
- public Object evaluate(Object parameters)
Called when InstantDB is actually evaluating a function. This
is always called last.
You should not rely on the first three methods above being invoked
in any particular order. The only thing guaranteed is the evaluate
will be the last method to be invoked.
Writing Your Own Functions
All user defined functions must be in the package "db" and must
implement the InstantDB interface db.SqlFunction.
It is then simply a matter of placing your compiled function anywhere
in your CLASSPATH or in the Java™ extensions directory (don't forget
to put it in a "db" subdirectory though).
Feel free to use any of the existing functions as templates for
your own. In addition to these, an example function is included
in the examples directory. This shows you how to use all of the
available InstantDB data types.
You can even add functions while InstantDB is still running, although
you will not necessarily be able to release new version of existing
functions without re-starting the Java Virtual Machine™.