Hello, We are struggling with a situation where we have built a custom Java QueryModule (as described in http://docs.basex.org/wiki/Java_Bindings) - let's call it M1, and that module is imported by two other XQuery modules (let's call them M2 and M3). When executing an XQuery that imports M1 and the other XQuery modules M2 and M3 within the BaseX GUI, multiple different instances of M1 are created. That is an issue, because we initialise the module M1 with some information (a custom geometry index) before calling any other function of M1. This initialization shall only occur once, because it is quite time-consuming. Also, the information from this initialization procedure must be available whenever the (non-initialization) functions of M1 are called - whether in the XQuery or the other modules M2 and M3. The situation is as follows:
* testquery.xq imports the custom module M1
* testquery.xq also imports the XQuery modules M2 and M3, which are stored in other XQuery files; M2 and M3 both import M1
* the custom module is initialized in testquery.xq - not in M2 and M3
* non-initialization functions of M1 are called in testquery.xq, as well as by functions declared in M2 and M3 - but only after initialization functions of M1 have been called in testquery.xq We get exceptions when functions of M1 are called by functions declared in M2 and M3, apparently because multiple instances of M1 have been created by BaseX (tested with the BaseX GUI), and only one of them has been initialized (in testquery.xq). After this lengthy introduction of the issue at hand, here are my questions:
* 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? 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.