Hi Johannes,
· Is it expected behavior that multiple instances of a Java QueryModule (M1, in my scenario) may be created and used during an execution of a query scenario like the one described above – or in general?
Yes, this is currently expected behavior; the import mechanisms of XQuery and Java modules differ in various aspects. The customary way to proceed is to organize the Java calls in a single XQuery module. Both the Java class and the XQuery module can then optionally be bundled as JAR file (see [1]).
Hope this helps, Christian
[1] http://docs.basex.org/wiki/Repository#Combined
Or should there only ever be a single such instance, regardless of how many times the module is imported?
o Note: The functions used to initialize M1 are non-deterministic and declared as such. Not entirely sure if that makes a difference regarding how many times M1 would be created.
· I have the same questions for the case that the Java QueryModule M1 was packaged in a XAR (as described in http://docs.basex.org/wiki/Repository#EXPath_Packaging). Would such a packaging approach actually make any difference?
Apologies that I do not have a small, self-contained example project to demonstrate this. I hope that I explained the issue with sufficient detail and clarity. If not, just let me know.
Best regards,
Johannes
P.S.: If you have suggestions for a better approach of handling such a scenario, where a QueryModule must be initialized before it can be used, and there shall only be a single instance of this module within the execution of an XQuery, let me know.