Hi Mauro,
It is generally tricky to invoke XQuery functions outside the original context. Function items are difficult to isolate, as they may contain references to other parts of the containing code. This is also the reason why the Job Module (which allows asynchronous execution of code) requires XQuery code to be specified as a strings or a file reference [1].
Without promising anything, I may be able to give more suggestions if you provide me with a self-contained and minimized version of your use case.
Best, Christian
[1] https://docs.basex.org/main/Job_Functions
________________________________ Von: Mauro Mugnaini Gesendet: Dienstag, 17. Juni 2025 18:34 Bis: BaseX Betreff: [basex-talk] Execute an Query function from Java code
Hi all, I’m trying to invoke an XQuery function (instance of FItem) from a Java class that acts a callback listener for a Java client adapter.
I’m able to instantiate and register it in a query module by using the Java bindings, passing the reference to the XQuery code to invoke) but at the moment that the function is invoked a QueryContext instance is needed (or at least the current Context to create it if I understood correctly) of the running BaseX service (an HTTP server in my case). I tried to find a way to do that taking a look of the Jobs module and similar packages in the source code but without success.
In the “Java" examples it is shown how to do this for code invoked during a query execution in a class that is a subclass of the QueryModule and by using the ContextDependent annotation that do the job automatically. It is not my case since the code is not directly call during a query execution but asynchronously in a separate thread.
Finally my questions: It is something that is possibile to do? Is there some singleton I can access or other classes I can use to achieve that?
Thanks and regards.
Mauro