TDB 0.8.1 works witht he latest Jena. I believe it ships with Jena
2.6.0. Could not find the announcement verifying this, but I am
pretty sure.
This
> Model model = ModelFactory.createDefaultModel();
creates an in-memory Jena model.
SDB introduced RDF models stored in relational databases like Oracle,
MySQL, a half dozen others. SDB however has slower performance
however than TDB.
> String directory = "MyDatabases/DB1" ;
> Model model = TDBFactory.createModel(directory) ;
>
> What happens when the above code snippet gets executed? Does it create a
> model
> and save it in the disk? Then I can add statements to this model? When the
> added
> statements will get saved to the disc?
Yes it should. In inqle we use 3 means to connect to TDB:
(1) Using the Jena API. This allows us to do things like
Model.listStatements(),
ResourceFactory.createStatement()
(2) using the Jenabean API.
http://code.google.com/p/jenabean/
Jenabean is an add-on to Jena, that permits storing and retrieving
Java objects from your Jena model (stored in this case in TDB). Very
slick capability of storing Java objects as RDF, which can be
retrieved or queried using SPARQL.
Inqle's class Persister handles the Jenabean operations:
Persister persister = Persister.getInstance();
//save an object to a model:
persister.persist(myObject, model);
//load an object from a model
SimpleSubjectSparqlSampler mySampler =
persister.reconstitute(SimpleSubjectSparqlSampler.class, mySamplerId,
modelContainingSamplers);
Please see class Persister for more on using the Jenabean API.
http://code.google.com/p/inqle/source/browse/trunk/org.inqle.data.rdf.jenabean/src/main/org/inqle/data/rdf/jenabean/Persister.java
The Persister class contains our methods for creating new TDB databases as well.
(3) using SPARQL queries. Here we use our Queryer class
private static final String SPARQL_SELECT_CLASSES_TABLE = "PREFIX
rdfs: <" + RDF.RDFS + "> \n" +
"SELECT DISTINCT " +
"?" + CLASS_URI_VAR + " ?Name ?Description { GRAPH ?anyGraph { \n " +
"?subject a ?" + CLASS_URI_VAR + " ." +
"OPTIONAL { ?" + CLASS_URI_VAR + " rdfs:label ?Name} . \n" +
"OPTIONAL { ?" + CLASS_URI_VAR + " rdfs:comment ?Description} . \n" +
"} } \n";
QueryCriteria queryCriteria = new QueryCriteria();
queryCriteria.addDatamodel(datamodelId);
queryCriteria.setQuery(SPARQL_SELECT_CLASSES_TABLE);
ResultSetRewindable results = Queryer.selectResultSet(queryCriteria);
Please see Queryer for more on how we work with queries
http://code.google.com/p/inqle/source/browse/trunk/org.inqle.data.rdf.jenabean/src/main/org/inqle/data/rdf/jena/Queryer.java
I hope this helps!
Dave