Graphs are named with URIs so by using the name "product_info" what you
have used is a relative URI and will not be the complete name

When given a relative URI Jena's default behaviour is to resolve it
against the current working directory.  So your graph is actually getting
named something like the following:

file:///your/working/dir/product_info

Depending on where your code runs the Base URI will change and so the
graph you are trying to access will change hence the apparent
disappearance of graphs.  You can use the dset.listNames() method to get
an iterator over the graph names in a store.

It is also worth noting that TDB does not store empty graphs (which is
what your code appears to do) so adding an empty named model has no effect
other than to add the graph name to the node table.  Therefore asking if
an empty graph is contained in TDB will always return false.

Btw you are several versions behind current stable release which is now
Jena/ARQ 2.11.2 and TDB 1.0.2 (Not that this is likely to make any
difference in this case)

Rob

On 18/06/2014 00:50, "Zachary M Jablons" <[email protected]> wrote:

>
>
>Hey all,
>
>I've been working with TDB for a bit now processing data into it, but I've
>run into an issue where after adding a named model, I find that the named
>model simply disappears, and is inaccessible. Here's some example code:
>
>        Model prodModel = null;
>        dset.begin(ReadWrite.WRITE);
>        Lock lck = dset.getLock();
>        try {
>               lck.enterCriticalSection(Lock.WRITE);
>            if (dset.containsNamedModel("product_info")) {
>                prodModel = dset.getNamedModel("product_info");
>                System.out.println("Using existing model");
>            } else {
>                System.out.println("Making new model");
>                dset.addNamedModel("product_info",
>ModelFactory.createDefaultModel());
>                prodModel = dset.getNamedModel("product_info");
>            }
>            dset.commit();
>        } finally {lck.leaveCriticalSection(); dset.end();}
>
>        TDB.sync(dset);
>        dset.begin(ReadWrite.READ);
>        Iterator<String> itr = dset.listNames();
>        while (itr.hasNext()) {
>               System.out.println(itr.next());
>        }
>        dset.end();
>In this case dset is a class attribute set by TDBFactory.createDataset
>("path/to/dataset/") at construction. Is it possible that this is causing
>an issue? If I run this multiple times, containsNamedModel returns false
>each time, even though manually inspecting nodes.dat shows it.
>I would expect it to print the named graph ("product_info") but instead
>nothing is printed. I might be using Jena's TDB interface incorrectly --
>it's hard to tell -- but I've been able to do this before with no issue.
>
>I'm using jena-tdb-0.10.1, jena-core-2.10.1, jena-arq-2.10.1.
>
>Thanks,
>- Zach Jablons




Reply via email to