Hi Christian,

Thank you. If I understand you correctly, that answers my first question. 
It may also answer my second question, where I was referring to expath 
packaging and if that would make any difference - when compared to having a 
pure JAR with the Java classes (and required libraries). It sounds like expath 
packaging does not make a difference. Please correct me if I got this wrong.

You asked: Or should there only ever be a single such instance, regardless of 
how many times the module is imported? 
The answer is yes. That is because we call some specific functions first, to 
initialize the module, and we need the information conveyed by this 
initialization process throughout the whole execution of an xquery, regardless 
how many times the module is imported (by that xquery, or indirectly via 
modules that the xquery imports).

Before we made an attempt of modularizing all our custom xquery functions into 
a set of modules, the Java module worked fine, presumably because it was only 
imported once. Now the Java module is imported by the xquery and some xquery 
modules (that are imported by the xquery). And we end up with multiple 
instances of the Java module. I was wondering if any packaging approach would 
ensure that only a single instance of the Java module is created, regardless of 
how many times the module is imported. From what I heard so far, it looks like 
that is not the case. Please confirm, or correct me if I got it wrong.

If there is no guarantee that a Java module is instantiated multiple times if 
it is imported more than once, regardless of how the Java module is packaged, 
then we would simply go back to the original structure of our xquery (before 
the modularization attempt). I just need to understand what behavior to expect 
(from BaseX) when it processes imports of a Java module (provided as pure Java 
module, combined module, or using EXPath packaging). 

Best regards,
Johannes



-----Ursprüngliche Nachricht-----
Von: Christian Grün [mailto:christian.gr...@gmail.com] 
Gesendet: Mittwoch, 18. Dezember 2019 11:07
An: Johannes Echterhoff <echterh...@interactive-instruments.de>
Cc: BaseX <basex-talk@mailman.uni-konstanz.de>
Betreff: Re: [basex-talk] How many QueryModule instances can be created?

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

Reply via email to