> Hi Roman, > > You should get a "TDBTransactionException: Not in a transaction". It is > not possible to pass >
There is unfortunately no error message in my jetty log file. > > > On 13/02/17 15:55, [email protected] wrote: > > Hi, > > > > I tried update Jena from 3.1.0 to 3.2.0. And at a later point I tried to > > update to Jena 3.1.1. In both cases I had the problem, that the following > > code didn't work anymore. > > > > public Model pullNamedModelFromTDB(String pathToTDB, String modelURI) { > > // create a TDB-dataset > > Dataset dataset = TDBFactory.createDataset(pathToTDB); > > dataset.begin( ReadWrite.WRITE ); > > try { > > // get the named model from the dataset > > Model tdb = dataset.getNamedModel(modelURI); > > This does not copy it out of the dataset, it creates a view of the data > inside the dataset, in fact, a view Good to know. It works for me in the past. > > > // finish the "WRITE" transaction > > dataset.commit(); > > return tdb; > > } finally { > > // close the dataset > > dataset.end(); > > dataset.close(); > > No needed. close(), if it has any meaning, may close the dataset for > ever. It's all cached internally. > > > // write a message if the data was successfully find in the jena tdb > > System.out.println("The model " + modelURI + " was successfully loaded > > from directory: " + pathToTDB); > > } > > } > > > > Model defaultCompositionModel; > > > > defaultCompositionModel = > > connectionToTDB.pullNamedModelFromTDB(currDirectoryPath, > > defaultCompositionNGURI); > > System.out.println("close test = " + defaultCompositionModel.isClosed()); > > System.out.println("empty test = " + defaultCompositionModel.isEmpty()); > > > > The program stops immediatly when I try to access the data of the named > > model. > > With an exception, I hope. See first comment. > > > So is there a new/correct way to pull a Named Model from a Dataset to > > use it afterward? The Code above works fine with the old > > versions(3.1.0 & 3.0.0). I saw there was a change in > > "DatasetImpl.java"-code. A variable called "dftModel" was removed > > from the code. I also saw that there was a change on Feb 8, 2017, > > where an if-statement was added for the transformation from a graph > > in a model. > > The correct ways depends on what you want to do: > > A:: If you want to copy out the model, then create a memory model and > copy with model.add(tdb) to create an in-memory detached copy. > > See also the new RDF Connection: > http://jena.apache.org/documentation/rdfconnection/ > This provides whole graph operations - better than DataseAccessor. > It can operate in copy-out, copy-in mode, makign it liek a remote > connection and also for making it transaction safe. This way works for me. I want to copy a named graph from the jena tdb. Change some resources and want to save the "copied graph" into another dataset. the case with the memory model only works for me when I use the new Java class RDFConnection. So it works in Jena 3.2.0 but not in Jena 3.1.1. For the record, if somebody else is looking for a working way, this is my code snippet: public Model pullNamedModelFromTDB(String pathToTDB, String modelURI) { // create a TDB-dataset Dataset dataset = TDBFactory.createDataset(pathToTDB); try (RDFConnection conn = RDFConnectionFactory.connect(dataset)) { conn.begin(ReadWrite.WRITE); try { Model model = conn.fetch(modelURI); Model outputModel = ModelFactory.createDefaultModel().add(model); conn.commit(); return outputModel; } finally { // close the connection conn.end(); // write a message if the import was successfully System.out.println("The model " + modelURI + " was successfully loaded from directory: " + pathToTDB); } } } For your information the linking in the example section on the page "http://jena.apache.org/documentation/rdfconnection/" don't work correct. First it is not a correct linking and second the link leads me to an error page. Thanks for all, Roman
