Using ClientSession from java, I do this to check if the database is open:
try { replace(somewhere, new ArrayInput(bytes)); } catch (IOException e) { String msg = e.getMessage(); if (msg == null || !msg.contains(“No database opened”)) throw e; execute(new Check(databaseName)); replace(somewhere, new ArrayInput(bytes)); }
Is there a better way to detect if the database is open than testing the exception message text?
Kendall
Hi Kendall,
I would indeed recommend you to use the CHECK command before doing any other operations. This command does exactly what you seem to be looking for (checking if the databases is opened; if not, open it).
Does this help? Christian
On Wed, Jun 15, 2016 at 7:03 PM, Kendall Shaw kendall.shaw@workday.com wrote:
Using ClientSession from java, I do this to check if the database is open:
try {
replace(somewhere, new ArrayInput(bytes));
} catch (IOException e) { String msg = e.getMessage();
if (msg == null || !msg.contains(“No database opened”))
throw e;
execute(new Check(databaseName));
replace(somewhere, new ArrayInput(bytes));
}
Is there a better way to detect if the database is open than testing the exception message text?
Kendall
Hi,
I think of opening a database, in general, as something you wouldn’t want to do every time you do any operation. I would expect:
open the database do stuff do stuff do stuff do stuff do stuff close the database
not
open the database and do stuff open the database and do stuff open the database and do stuff open the database and do stuff close the database
Is using CHECK when the database is already open comparable in CPU cycles to testing a boolean variable that says open true or false? I understand that the time it takes for most commands to execute would make code logic usually insignificant.
Kendall
On 6/18/16, 4:54 AM, "Christian Grün" christian.gruen@gmail.com wrote:
Hi Kendall,
I would indeed recommend you to use the CHECK command before doing any other operations. This command does exactly what you seem to be looking for (checking if the databases is opened; if not, open it).
Does this help? Christian
On Wed, Jun 15, 2016 at 7:03 PM, Kendall Shaw kendall.shaw@workday.com wrote:
Using ClientSession from java, I do this to check if the database is open:
try {
replace(somewhere, new ArrayInput(bytes));
} catch (IOException e) { String msg = e.getMessage();
if (msg == null || !msg.contains(“No database opened”))
throw e;
execute(new Check(databaseName));
replace(somewhere, new ArrayInput(bytes));
}
Is there a better way to detect if the database is open than testing the exception message text?
Kendall
Hi Kendall,
Is using CHECK when the database is already open comparable in CPU cycles to testing a boolean variable that says open true or false? I understand that the time it takes for most commands to execute would make code logic usually insignificant.
Check will definitely be slower than a pure boolean check. On the other hand, I wouldn’t expect you to notice any delay, as the execution time should only be a few milliseconds, or even less.
What will be the processing time you require for this operation? There may be some chance to improve the execution time of this command (it just hasn’t been a bottleneck so far).
Cheers, Christian
On 6/18/16, 4:54 AM, "Christian Grün" christian.gruen@gmail.com wrote:
Hi Kendall,
I would indeed recommend you to use the CHECK command before doing any other operations. This command does exactly what you seem to be looking for (checking if the databases is opened; if not, open it).
Does this help? Christian
On Wed, Jun 15, 2016 at 7:03 PM, Kendall Shaw kendall.shaw@workday.com wrote:
Using ClientSession from java, I do this to check if the database is open:
try {
replace(somewhere, new ArrayInput(bytes));
} catch (IOException e) { String msg = e.getMessage();
if (msg == null || !msg.contains(“No database opened”))
throw e;
execute(new Check(databaseName));
replace(somewhere, new ArrayInput(bytes));
}
Is there a better way to detect if the database is open than testing the exception message text?
Kendall
Right now I am just adding or removing documents and executing queries. So, I imagine the time it takes to run CHECK is insignificant. But, if I am going to reuse code, then using the technique of always running CHECK before every operation seem like it might not be the best thing to do. Similarly assuming that my code elsewhere is correctly opening the database and setting a variable to say “isOpen” before it is needed also doesn’t seem like the best idea. But, I gather using CHECK all the time is the typical way to do this. So, I will do that. I thought of CHECK as create or open, it didn’t occur to me that it would optionally open.
Thanks, Kendall
On 6/19/16, 3:25 PM, "Christian Grün" christian.gruen@gmail.com wrote:
Hi Kendall,
Is using CHECK when the database is already open comparable in CPU cycles to testing a boolean variable that says open true or false? I understand that the time it takes for most commands to execute would make code logic usually insignificant.
Check will definitely be slower than a pure boolean check. On the other hand, I wouldn’t expect you to notice any delay, as the execution time should only be a few milliseconds, or even less.
What will be the processing time you require for this operation? There may be some chance to improve the execution time of this command (it just hasn’t been a bottleneck so far).
Cheers, Christian
On 6/18/16, 4:54 AM, "Christian Grün" christian.gruen@gmail.com wrote:
Hi Kendall,
I would indeed recommend you to use the CHECK command before doing any other operations. This command does exactly what you seem to be looking for (checking if the databases is opened; if not, open it).
Does this help? Christian
On Wed, Jun 15, 2016 at 7:03 PM, Kendall Shaw kendall.shaw@workday.com wrote:
Using ClientSession from java, I do this to check if the database is open:
try {
replace(somewhere, new ArrayInput(bytes));
} catch (IOException e) { String msg = e.getMessage();
if (msg == null || !msg.contains(“No database opened”))
throw e;
execute(new Check(databaseName));
replace(somewhere, new ArrayInput(bytes));
}
Is there a better way to detect if the database is open than testing the exception message text?
Kendall
basex-talk@mailman.uni-konstanz.de