从 MarkLogic Xquery 模块调用 Java [英] Call Java from MarkLogic Xquery module

查看:25
本文介绍了从 MarkLogic Xquery 模块调用 Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个复杂的 Java 转换例程,我想从我的 XQuery 模块中调用它.我想直接调用它而不是使用服务或 http 端点来最小化开销.

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.

这适用于必须将大型几何形状从一个坐标系转换为另一个坐标系(RD 到 ETRS89)的例程.由于这些是更大的 XML 文档的一部分,可能包含数十个这样的形状,因此当我们实际处理文档时,我想在 MarkLogic 中执行此操作.

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.

MarkLogic 文档没有给我任何关于如何实现这种扩展的信息,只讨论了不合适的 xquery 和 javascript 扩展.

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.

在 XQuery 或 Javascript 中重写例程并不是一个真正的选择,因为它非常复杂且耗时.

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

推荐答案

不支持在进程内调用 java 的方法.有一些合理有效的方法可以调用您可能需要重新考虑的进程外服务.开销主要是延迟.如果您批量转换并保持 Java 服务器运行以避免启动成本,则可以最大限度地减少开销.

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.

可能存在不受支持和/未经测试的方法.此特定任务可能非常适合本机用户定义函数 - UDF"接口.这允许将本机代码作为查询的一部分(不是直接从 XQuery 中)调用,而是作为数据层中的 map-reduce 过程调用.这些函数可以用 C++ 'wrapper' 编写,它通过 JNI 调用 java —— 理论上(据我所知未经测试).

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).

还有 Java 到 JavaScript 的转换程序,它可能能够生成可在服务器中本地运行的 javascript.示例:GWT

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

我一直想尝试的一种方法是首先将 Java 转换为 Kotlin(相当简单,通过 IntelliJ 的 J2K 工具实现了大约 80% 的自动化).
然后可以将 Kotlin 编译为 Javascript.

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(通过 kotlin native)也可以生成本地可执行文件(但我不相信 UTF 接口所需的共享库.)

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

这篇关于从 MarkLogic Xquery 模块调用 Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆