Hello all,
I’m currently in the process of evaluating BaseX for an embedded use case and I ran into an issue. I figured out that each Command is a transaction (though I think this should be made more prominent in the javadocs at http://docs.basex.org/javadoc/org/basex/core/Command.html) and I found the 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?
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
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/ba...).
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
Hi Buko,
Thanks for the details. It’s good to know you are using Java to connect to BaseX. As I assume that your requirement will be shared by others, you may be happy to hear that I have just extended the Execute class with an additional constructor [1]. Feel free to check out the latest snapshot [2].
Is XQuery the way to go? It seems like the Command API is limited and is perhaps not meant to support general use cases.
In fact we are using XQuery for nearly all tasks that cannot be represented via simple commands. For nearly all commands, equivalent built-in functions are available, which you find in our Module Library documentation [3]. To answer your next question, db:exists is what you need [4].
Hope this helps, Christian
[1] https://github.com/BaseXdb/basex/commit/1e1fbf19cfe84a7c8e6a4d5b0b75c973c7ab... [2] http://files.basex.org/releases/latest/ [3] http://docs.basex.org/wiki/Module_Library [4] http://docs.basex.org/wiki/Database_Module#db:exists
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
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
basex-talk@mailman.uni-konstanz.de