jena-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andy Seaborne <andy.seabo...@epimorphics.com>
Subject Re: Problem replacing graph
Date Tue, 01 Feb 2011 21:20:58 GMT


On 01/02/11 14:47, Frank Budinsky wrote:
>
>
> Hi All,
>
> I'm having trouble doing a fairly straightforward operation in Jena, which
> probably just means I'm doing something wrong. I'm trying to add or replace
> a resource (as a graph) in my dataset. The code I wrote looks something
> like this:
>
>        protected Resource addOrReplaceResource(Dataset dataset, String
> resourceURI, InputStream instream)
>        {
>              Resource resource = dataset.containsNamedModel(resourceURI) ?
>                  dataset.getNamedModel(resourceURI).getResource
> (resourceURI) : null;
>              if (resource != null)
>                    dataset.asDatasetGraph().removeGraph(resource.asNode());
>              Model model = dataset.getNamedModel(resourceURI);
>              model.read(instream, null);
>              resource = model.getResource(resourceURI);
>              return resource;
>        }
>
> When a resourceURI is added for the first time, it works fine but when
> replacing a graph the call to removeGraph() seems to wipe out the entire
> dataset. The only thing left in the dataset after that is the single
> resource which gets added after the removeGraph call.

resources aren't added by getResource - in fact, it does not change the 
model and and RDF model does not have resources without being in a 
statement.

>
> Is there something obvious that I'm doing wrong here?
>
> Thanks,
> Frank.

removeGraph(String) removes the graph (all the statements).

Then it depends what's in the RDF/XML in instream.

What happens if you print the model, or print the dataset, just before 
the return?

	Andy

Mime
View raw message