Hey Christian,
Thanks for the help.
What I’m actually trying to do is new-up several Command objects and execute them in one go. Ideally I’d like to do something like:
List<Command> commands = new ArrayList<>();
commands.add(new Add(…));
commands.add(new Add(…));
new Execute(commands).run(context);
The problem is that the Execute command (http://docs.basex.org/javadoc/org/basex/core/cmd/Execute.html) takes a string. (Though internally, looking at the code, I see it has a list of Commands and parses the string into it @ https://github.com/BaseXdb/basex/blob/master/basex-core/src/main/java/org/basex/core/cmd/Execute.java).
Is there another way I might execute multiple Command objects in one go?
What I’m really trying to do is actually check for the existence of a few documents and if they don’t exist then write them out. My next question would of course be which command lets me check for the existence of a path in the database…
Is XQuery the way to go? It seems like the Command API is limited and is perhaps not meant to support general use cases.
From: Christian Grün
Sent: Friday, April 20, 2018 1:25 PM
To: buko
Cc: basex-talk@mailman.uni-konstanz.de
Subject: Re: [basex-talk] ExecuteCommand with a multiple Command objects?
Hi Buko,
> Execute command that lets multiple Commands be grouped together and executed
> as one… but the Execute command takes a string. What happens if I have a
> series of Command objects that I would like to execute together in a single
> transaction?
I think the first example in the documentation for EXECUTE should do
what you need [1].
> (though I think this should be made more prominent in the javadocs at
> http://docs.basex.org/javadoc/org/basex/core/Command.html)
As there are numerous ways to run commands in BaseX (on command line,
via scripts, via REST, etc), could you give me some more details on
how you proceeded?
Some more thoughts on this:
• We could generally run commands in a single transaction whenever
they are passed on as a single string (and separated by semicolons).
• Probably we shouldn’t this for scripts: Commands script can have a
large number of commands and are often used for batch operations,
which might run for a long time in the background.
Suggestions are welcome.
Christian
[1] http://docs.basex.org/wiki/Commands#EXECUTE