Java – Jena TDB: nested transactions
I want to rewrite the code that currently uses transactions However, according to Jena's documentation( http://incubator.apache.org/jena/documentation/tdb/tdb_transactions.html ), nested transactions are not supported
For example, I want to query some data from the database and add an RDFS tag for each resource found Do I have to read and write the code strictly according to the following code, or is there a more effective way to implement this example?
Dataset dataset = ...; dataset.begin(ReadWrite.READ); ArrayList<Resource> res = new ArrayList<Resource>(); try{ QueryExecution qe = QueryExecutionFactory.create("SELECT ?x WHERE { ?x a <Whatever> . }",dataset); ResultSet rs = qe.execSelect(); try { while(rs.hasNext()) { QuerySolution s = rs.nextSolution(); RDFNode node = s.get("x"); if(node.isResource) res.add(node.asResource()); } }finally{ qe.close(); } }finally{ dataset.end(); } dataset.begin(ReadWrite.WRITE); try{ Property label = model.getProperty("http://www.w3.org/2000/01/rdf-schema#label"); for(Resource r : res) { r.addProperty(label,"text"); } dataset.commit(); }finally{ dataset.end(); }
I've been on Semantic Web Com posted this question, but I didn't receive any answer, so I hope someone can help me
Solution
Indeed, TDB does not support nested transactions, but you can perform any number of read operations in write transactions Therefore, start readwrite Write transactions and perform all processing You don't need nested transactions to do what you want
For more information on TDB transaction support, please check the official documentation here:
> http://incubator.apache.org/jena/documentation/tdb/tdb_transactions.html