Hi Zach,

A named model in TDB only "exists" as far as contains() and listNames() are concerned only if it has any triples in it. There is no separate graph management.

Named graphs are stored in the quads table and listNames() is, in effect, a projection of the named graph column (made distinct).

dset.addNamedModel("product_info", ModelFactory.createDefaultModel());

adds an empty graph.

In TDB, adding a graph is copying it in ... but it's empty. No triples added so it does not appear in listNames(). It is different in a memory dataset.

For TDB, you don't need to check existence, just do:

prodModel = dset.getNamedModel("product_info");

You will always get a model which you can update. The default memory dataset is the same here.

A few unrelated points:

Use a proper URI for the graph name else you will run into the problems if you ever try to write out a named graph format.

TDB.sync isn't necessary if you use transactions.

Lock lck isn't necessary if you use transactions unless you have multiple threads inside one transaction. Multiple transactions are already thread safe.

nodes.dat is not referenced counted - just because there is a node in it, does not mean it is still active in the database.

        Andy


On 18/06/14 00:50, Zachary M Jablons 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