1
votes

I have a complex conversion routine in Java that I would like to call from my XQuery module. I want to call it directly and not using a service or http endpoint to minimize overhead.

This is for a routine that has to convert large geometric shapes from one coordinate system to another (RD to ETRS89). As these are part of a much larger XML document, possibly containing dozens of such shapes, I'd like to do this in MarkLogic when we actually process the document.

The MarkLogic documentation doesn't give me any information how to implement such a extension, only talks about xquery and javascript extensions which are not suitable.

Rewriting the routine in XQuery or Javascript is not really an option as it would be pretty complex and time consuming.

2
What's the context here? Is it based on a user's request to a REST endpoint? Or is it part of an ingest process?rjrudin
Context: user has uploaded a large xml document that needs further processing. We validate it using schema and schematron. When the document is valid we process it further by extracting data including the GML which we want to store as cts:region so we can use geo search. But as it is in the wrong coordinate format (RD, a dutch proprietary format) we need to convert it to ETRS89 before storing it as ML cannot handle RD coordinates.Marcel de Kleine
Is there a Java middle tier between the user and MarkLogic? If so, one option would be to make two requests to ML. The first would do the validation and GML extraction, all of which would be returned back to the Java tier. The Java tier could then use a library to convert the GML into ETRS89. Then the Java tier would send everything back to ML, which would persist it. Alternatively, you could have the Java middle tier do all of the validation as well, as it can easily validate using a schema and Schematron as well.rjrudin

2 Answers

1
votes

There is no supported method for calling java in-process. There are reasonably effecient ways of calling a out-of-process service which you might want to reconsider. The overhead is largely latancy. If you batch up transformations and keep a java server running to avoid startup costs the overhead can be minimized.

There are possibly unsupported and/un-tested methods. This particular task might be well suited for the native 'user define function - UDF' interface. This allows native code to be invoked as part of a query ( not directly from XQuery) but rather as a map-reduce process in the data layer. These functions could be written in a C++ 'wrapper' that invokes java via JNI -- in theory (not tested to my knowledge).

Also there exists Java to JavaScript transformation programs, which might be able to produce javascript which is natively runnable in the server. Examples: GWT

One method I have been wanting to try myself is to first convert Java to Kotlin (fairly straight forward, about 80% automated via IntelliJ's J2K tool ).
Kotlin can then be compiled to Javascript.

Kotlin (via kotlin native) can also generate native executables (but I dont belive shared libraries which are needed for the UTF interfaces.)

0
votes

Based on your description it looks like you are working with something like ruimtelijke plannen or omgevingswet data. Depending on what you need to do with the data, you can work with RD in MarkLogic using Raw coordinate system.