Re: Pull NamedModel from a Dataset didn't work since jena 3.1.1
Thanks, I've made that change. Keep in mind that if you see an error on a doc page, you can always use the "Improve this Page" link at the top of the page to send a patch. --- A. Soroka The University of Virginia Library > On Feb 14, 2017, at 11:21 AM, marschelin...@web.de wrote: > >> That link works fine for me and leads to appropriate documentation. Perhaps >> you can explain what you mean by "it is not a correct linking"? > > I don't mean the link "http://jena.apache.org/documentation/rdfconnection/";. > I speak from the link at the bottom of this site in the section "Examples". > The link is a plain text and no correct html link. The link at the bottom is > "https://github.com/apache/jena/tree/master/jena-rdfconnection/src/main/java/rdfconnection/examples";. > And this leads me to an error page. ;) > > I think the link for the example page must be > "https://github.com/apache/jena/tree/master/jena-rdfconnection/src/main/java/org/apache/jena/rdfconnection/examples";. > > Greetings, > > Roman > >>> On Feb 14, 2017, at 3:56 AM, marschelin...@web.de wrote: >>> >>> 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. >
Re: Pull NamedModel from a Dataset didn't work since jena 3.1.1
> That link works fine for me and leads to appropriate documentation. Perhaps > you can explain what you mean by "it is not a correct linking"? I don't mean the link "http://jena.apache.org/documentation/rdfconnection/";. I speak from the link at the bottom of this site in the section "Examples". The link is a plain text and no correct html link. The link at the bottom is "https://github.com/apache/jena/tree/master/jena-rdfconnection/src/main/java/rdfconnection/examples";. And this leads me to an error page. ;) I think the link for the example page must be "https://github.com/apache/jena/tree/master/jena-rdfconnection/src/main/java/org/apache/jena/rdfconnection/examples";. Greetings, Roman > > On Feb 14, 2017, at 3:56 AM, marschelin...@web.de wrote: > > > > 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.
Re: Pull NamedModel from a Dataset didn't work since jena 3.1.1
That link works fine for me and leads to appropriate documentation. Perhaps you can explain what you mean by "it is not a correct linking"? --- A. Soroka The University of Virginia Library > On Feb 14, 2017, at 3:56 AM, marschelin...@web.de wrote: > > 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.
Aw: Re: Pull NamedModel from a Dataset didn't work since jena 3.1.1
> 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, marschelin...@web.de 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
Re: Pull NamedModel from a Dataset didn't work since jena 3.1.1
Hi Roman, You should get a "TDBTransactionException: Not in a transaction". It is not possible to pass On 13/02/17 15:55, marschelin...@web.de 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 // 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. 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. B:: If you want to change the model and change the dataset, then get the model inside a transaction each time. It isn't a copy - it should not be expensive. Passing anything that is associated with the transaction out of the begin-commit is not safe. It used to lead to missing updates. It sort of worked for read-only operations although that could go wrong as well. "dftModel" - this is related - the code no longer holds on to default model across transactions. Feb 8 - after the release. It is actually making an error situation happen earlier and with a relevant error message. In TDB all graphs "exist" so the return is never null and so this is not relevant here. Andy Thanks in advance! Roman
Pull NamedModel from a Dataset didn't work since jena 3.1.1
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); // finish the "WRITE" transaction dataset.commit(); return tdb; } finally { // close the dataset dataset.end(); dataset.close(); // 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. 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. Thanks in advance! Roman