On 23/09/13 18:39, Márcio Vinicius wrote:
Hello, I'm beginning to study and develop a small prototype of a future
application. I'm already using TDB and could store and retrieve triple.
However I have some questions:
- It would be possible to retrieve the information and put them in a model?
Yes.
Currently I do the following storage and data recovery:
public class DataBase {
public void store(Model model) {
Dataset dataset = TDBFactory.createDataset(Constants.DIRECTORY);
Model tdb = dataset.getDefaultModel();
tdb.add(model);
tdb.close();
dataset.close();
}
Thats' OK - another way to do it is to get the model from the dataset
andwriet directly into 'tdb'.
Trasnactions are better as you use them later - but if you are not using
them, consider havign the dataset created once and using TDB.sync(dataset).
public String query(String sparqlQueryString) {
Dataset dataset = TDBFactory.createDataset(Constants.DIRECTORY);
String msg = "";
try {
dataset.begin(ReadWrite.READ);
dataset.getNamedModel(Constants.NAME_APPLICATION);
Query query = QueryFactory.create(sparqlQueryString);
QueryExecution qexec = QueryExecutionFactory.create(query,
dataset);
ResultSet results = qexec.execSelect();
ResultSetFormatter.out(results);
} catch (Exception e) {
e.printStackTrace();
msg = "erro";
} finally {
dataset.end();
dataset.close();
No need to close, in fact repeated opening and closing is just a small
amount of overhead. The system caches the real connection to the DB.
Andy
}
return msg;
}
}
Sincerely.