Fixed in SVN for the non-transactional case.
Be careful with closing an dopening - it has a potentially huge
performance impact because all caching is dropped. Calling TDB.sync(ds)
will ensure the on-disk version is up-to-date and retain caches.
Transactions are more robust. If used transactionally, there is no
problem. In fact, when used transactionally, then .close does not flush
the database connection out of the JVM, just make the current one
unusably, because there may be transaction work still to be done.
Andy
On 24/11/12 17:08, François-Paul Servant wrote:
Dear Jena users,
here is a test case that worked with TDB-0.8.10 but throws an exception with
jena 2.7.4. In short, you cannot anymore create a TDB dataset from a dir, close
it, and then create it again.
package ex;
import java.io.File;
import org.junit.Before;
import org.junit.Test;
import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.tdb.TDBFactory;
public class TDBProblem {
File tdbDir;ge
Dataset ds;
@Before
public void setUp() throws Exception {
tdbDir = new File("/Users/fps/Desktop/TDBTest");
}
@Test
public final void test1() {
openAndClose();
}
@Test
public final void test2() {
open();
}
@Test
public final void test3() {
openAndClose();
open();
}
void openAndClose() {
Dataset ds = TDBFactory.createDataset(tdbDir.getAbsolutePath());
Model m = ds.getDefaultModel();
m.add(m.createResource("http://foo.com/s"),
m.createProperty("http://foo.com/p"),
m.createResource("http://foo.com/o"));
m.commit();
ds.close();
}
void open() {
Dataset ds = TDBFactory.createDataset(tdbDir.getAbsolutePath());
// EXCEPTION HERE WITH JENA 2.7.4:
Model m = ds.getDefaultModel();
StmtIterator it = m.listStatements();
for(;it.hasNext();) {
System.out.println(it.next());
}
}
}
The exception you get (on ds.getDefaultModel()) is:
java.lang.NullPointerException
at
com.hp.hpl.jena.tdb.store.GraphTriplesTDB.createPrefixMapping(GraphTriplesTDB.java:92)
at
com.hp.hpl.jena.sparql.graph.GraphBase2.getPrefixMapping(GraphBase2.java:194)
at
com.hp.hpl.jena.rdf.model.impl.ModelCom.getPrefixMapping(ModelCom.java:908)
at
com.hp.hpl.jena.rdf.model.impl.ModelCom.withDefaultMappings(ModelCom.java:952)
at com.hp.hpl.jena.rdf.model.impl.ModelCom.<init>(ModelCom.java:66)
at com.hp.hpl.jena.rdf.model.impl.ModelCom.<init>(ModelCom.java:62)
at
com.hp.hpl.jena.rdf.model.ModelFactory.createModelForGraph(ModelFactory.java:166)
at
com.hp.hpl.jena.sparql.core.DatasetImpl.graph2model(DatasetImpl.java:266)
at
com.hp.hpl.jena.sparql.core.DatasetImpl.getDefaultModel(DatasetImpl.java:102)
at ex.TDBProblem.open(TDBProblem.java:48)
Best,
fps