Change basex home in the same execution enviroment
Tuesday, 27 October 2015 · 4 messages · last reply 28 Oct 2015
AM
Antonio Mele27 Oct 2015 12:00 #
Hello,
I am using basex version 8.3-SNAPSHOT in a java stand alone application. After i set the property org.basex.path with the path of my DB (ex. /mnt/test/db_1) I call a new Context and then CreateDB.
It creates the folder /mnt/test/db_1/data/db_1
After that (in the same execution enviroment) I change the property to another DB (ex. /mnt/test/db_2).
It creates the folder /mnt/test/db_1/data/db_2
I would like to create the db_2 in the path /mnt/test/db_2/data/db_2.
Follow the code I wrote, where inputFolder is a folder with inside some xml files
Thanks in advance.
System.setProperty("org.basex.path", "/mnt/test/db_1");
Context context = new Context(false);
new CreateDB("db_1", inputFolder).execute(context);
context.close();
System.setProperty("org.basex.path", "/mnt/test/db_2");
context = new Context(false);
new CreateDB("db_2", inputFolder).execute(context);
context.close();CG
Christian Grün28 Oct 2015 08:52 #
Hi Antonio
The BaseX home directory is static and will only be assigned once (see [1] for more information). You should have more success by assigning a directory to "org.basex.dbpath", but it's better to directly assign a new path to the context:
Context context = new Context(false);
context.soptions.set(StaticOptions.DBPATH, "/mnt/test/db_1");
...Hope this helps,
Christian
[1] https://github.com/BaseXdb/basex/blob/master/basex-core/src/main/java/org/basex/util/Prop.java#L99
Quoted text · Antonio Mele · 30 lines
On Tue, Oct 27, 2015 at 12:00 PM, Antonio Mele <amele at altereos.com> wrote: > Hello, > > I am using basex version 8.3-SNAPSHOT in a java stand alone application. > After i set the property org.basex.path with the path of my DB (ex. > /mnt/test/db_1) I call a new Context and then CreateDB. > It creates the folder /mnt/test/db_1/data/db_1 > After that (in the same execution enviroment) I change the property to > another DB (ex. /mnt/test/db_2). > It creates the folder /mnt/test/db_1/data/db_2 > > I would like to create the db_2 in the path /mnt/test/db_2/data/db_2. > > > Follow the code I wrote, where inputFolder is a folder with inside some xml > files > > > Thanks in advance. > > > System.setProperty("org.basex.path", "/mnt/test/db_1"); > Context context = new Context(false); > new CreateDB("db_1", inputFolder).execute(context); > context.close(); > > System.setProperty("org.basex.path", "/mnt/test/db_2"); > context = new Context(false); > new CreateDB("db_2", inputFolder).execute(context); > context.close();
AM
Antonio Mele28 Oct 2015 11:51 #
Yes thank you very much. It works. But I have to add it to every call even when I make a query, I saw that it doesn't create the folder data (usually it creates /mnt/test/db_1/data/db_1), so now my queries fail if I don't add context.soptions.set(StaticOptions.
DBPATH, "/mnt/test/db_1");
Thank you.
Antonio
2015-10-28 8:52 GMT+01:00 Christian Grün <christian.gruen at gmail.com>:Quoted text · Christian Grün · 50 lines
> Hi Antonio > > The BaseX home directory is static and will only be assigned once (see > [1] for more information). You should have more success by assigning a > directory to "org.basex.dbpath", but it's better to directly assign a > new path to the context: > > Context context = new Context(false); > context.soptions.set(StaticOptions.DBPATH, "/mnt/test/db_1"); > ... > > Hope this helps, > Christian > > [1] > https://github.com/BaseXdb/basex/blob/master/basex-core/src/main/java/org/basex/util/Prop.java#L99 > > > On Tue, Oct 27, 2015 at 12:00 PM, Antonio Mele <amele at altereos.com> wrote: > > Hello, > > > > I am using basex version 8.3-SNAPSHOT in a java stand alone application. > > After i set the property org.basex.path with the path of my DB (ex. > > /mnt/test/db_1) I call a new Context and then CreateDB. > > It creates the folder /mnt/test/db_1/data/db_1 > > After that (in the same execution enviroment) I change the property to > > another DB (ex. /mnt/test/db_2). > > It creates the folder /mnt/test/db_1/data/db_2 > > > > I would like to create the db_2 in the path /mnt/test/db_2/data/db_2. > > > > > > Follow the code I wrote, where inputFolder is a folder with inside some > xml > > files > > > > > > Thanks in advance. > > > > > > System.setProperty("org.basex.path", "/mnt/test/db_1"); > > Context context = new Context(false); > > new CreateDB("db_1", inputFolder).execute(context); > > context.close(); > > > > System.setProperty("org.basex.path", "/mnt/test/db_2"); > > context = new Context(false); > > new CreateDB("db_2", inputFolder).execute(context); > > context.close(); >
CG
Christian Grün28 Oct 2015 11:56 #
A little warning: The current rationale in BaseX is that there is only one Context instance and, thus, only one database directory. Moving away from that might give you more freedom, but it might also lead to unexpected behavior.
Quoted text · Antonio Mele · 63 lines
On Wed, Oct 28, 2015 at 11:51 AM, Antonio Mele <amele at altereos.com> wrote: > Yes thank you very much. It works. But I have to add it to every call even > when I make a query, I saw that it doesn't create the folder data (usually > it creates /mnt/test/db_1/data/db_1), so now my queries fail if I don't add > context.soptions.set(StaticOptions.DBPATH, "/mnt/test/db_1"); > > Thank you. > > Antonio > > 2015-10-28 8:52 GMT+01:00 Christian Grün <christian.gruen at gmail.com>: >> >> Hi Antonio >> >> The BaseX home directory is static and will only be assigned once (see >> [1] for more information). You should have more success by assigning a >> directory to "org.basex.dbpath", but it's better to directly assign a >> new path to the context: >> >> Context context = new Context(false); >> context.soptions.set(StaticOptions.DBPATH, "/mnt/test/db_1"); >> ... >> >> Hope this helps, >> Christian >> >> [1] >> https://github.com/BaseXdb/basex/blob/master/basex-core/src/main/java/org/basex/util/Prop.java#L99 >> >> >> On Tue, Oct 27, 2015 at 12:00 PM, Antonio Mele <amele at altereos.com> wrote: >> > Hello, >> > >> > I am using basex version 8.3-SNAPSHOT in a java stand alone application. >> > After i set the property org.basex.path with the path of my DB (ex. >> > /mnt/test/db_1) I call a new Context and then CreateDB. >> > It creates the folder /mnt/test/db_1/data/db_1 >> > After that (in the same execution enviroment) I change the property to >> > another DB (ex. /mnt/test/db_2). >> > It creates the folder /mnt/test/db_1/data/db_2 >> > >> > I would like to create the db_2 in the path /mnt/test/db_2/data/db_2. >> > >> > >> > Follow the code I wrote, where inputFolder is a folder with inside some >> > xml >> > files >> > >> > >> > Thanks in advance. >> > >> > >> > System.setProperty("org.basex.path", "/mnt/test/db_1"); >> > Context context = new Context(false); >> > new CreateDB("db_1", inputFolder).execute(context); >> > context.close(); >> > >> > System.setProperty("org.basex.path", "/mnt/test/db_2"); >> > context = new Context(false); >> > new CreateDB("db_2", inputFolder).execute(context); >> > context.close(); > >
Written for BaseX 8.3. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery