ExecuteCommand with a multiple Command objects?

Friday, 20 April 2018 · 4 messages
B
buko20 Apr 2018 00:56 #
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?
CG
Christian Grün20 Apr 2018 08:24 #
Hi Buko,
Quoted text · buko · 4 lines
> 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].
Quoted text · buko · 2 lines
> (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
B
buko20 Apr 2018 08:53 #
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.
Quoted text · Christian Grün · 26 lines
From: Christian Grün Sent: Friday, April 20, 2018 1:25 PM To: buko Cc: basex-talk at 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
CG
Christian Grün20 Apr 2018 10:28 #
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].
Quoted text · buko · 2 lines
> 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/1e1fbf19cfe84a7c8e6a4d5b0b75c973c7ab80f6 [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
Quoted text · buko · 71 lines
> From: Christian Grün > Sent: Friday, April 20, 2018 1:25 PM > To: buko > Cc: basex-talk at 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 > >

⚡Generated with XQuery